The C# language is evolving so fast that it does take effort to keep up with Anders Hejlsberg, C#’s designer at Microsoft
Talking about the next version of C# in this video, Anders describes implementing a runtime operation called “dynamic” that eliminates all type safety for a variable. This essentially means that until the code is run, [...]
Posts Tagged ‘C#’
C# 4.0 “dynamic” versus “var”
Posted in Technical, Theoretical, tagged .NET, C# on November 26, 2008 | Leave a Comment »
C# Schema Validator
Posted in Technical, tagged C#, XML, XSD on December 24, 2007 | Leave a Comment »
Can be wrapped into a reusable function for easy reuse
//The C# validator
//———————
System.Xml.XmlDocument objWorkingXML = new XmlDocument();
System.Xml.XmlValidatingReader objValidateXML;
System.Xml.Schema.XmlSchemaCollection objSchemasColl = new XmlSchemaCollection();
System.Xml.XmlTextReader xmlTxtReader = new System.Xml.XmlTextReader(@”..\..\rss.xsd”);
objSchemasColl.Add(“urn:simeon.com/xmlschemas/dosvis/dosvisgrouppayauthority/”, xmlTxtReader);
//This loads XML string in.. but you can also load files similarly
objValidateXML = new System.Xml.XmlValidatingReader(new XmlTextReader(@”..\..\rss.xml”));
//This is how you CATCH the errors (with a handler function)
//AddHandler objValidateXML.ValidationEventHandler, AddressOf [...]
.NET Security: Class for Symmetric Encryption
Posted in Technical, tagged .NET, C#, Security on December 24, 2007 | Leave a Comment »
Reusable class that seamlessly abstracts Symmetric Encryption
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace Simeon.Lobo.Security
{
public class SymmetricEncryption
{
public SymmetricEncryption()
{
this.Algorithm = SymmetricAlgorithm.Create();
for (int num1 = 0; num1 < this.Algorithm.LegalKeySizes.Length; num1++)
{
this.KeySize = this.Algorithm.LegalKeySizes[num1].MinSize;
if (this.Algorithm.ValidKeySize(this.KeySize))
{
break;
}
}
this.Algorithm.Mode = CipherMode.ECB;
}
public SymmetricEncryption(SymmetricAlgorithm Algorithm)
{
this.Algorithm = Algorithm;
for (int num1 [...]
C# .NET Optional logging with StackTrace
Posted in Technical, tagged .NET, C# on December 22, 2007 | 2 Comments »
In the event that simple application logging is required the below code could be used,
<!– application specific settings –>
<appSettings>
<!– Use a value of either “OVERWRITE” or “APPEND” –>
<add key=“loggingType“ value=“OVERWRITE“ />
</appSettings>
<!– Implementation –>
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Configuration;
using System.Diagnostics;
using System.Reflection;
public class Log
{
private string _loggingType = String.Empty;
private string _logFilePhyPath = String.Empty;
[...]
Stripping XML nodes imperatively
Posted in Technical, tagged .NET, C#, XML on December 22, 2007 | Leave a Comment »
Depending on the situation and in certain circumstances, XSL transformations may be unwieldy. The ability to parse and strip custom nodes from an XML fragment is very handy in the these situations. The below code can be modified and used for this purpose,
//Strip unwanted nodes
i = ProcessFile(Server.MapPath(“Extract.xml”), “AccessControl”, String.Empty, String.Empty);
//Strip unwanted attributes
xml = StripXmlAttribute(xml, “ThesaurusTerm”);
//Strip [...]