Feeds:
Posts
Comments

Posts Tagged ‘C#’

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, [...]

Read Full Post »

C# Schema Validator

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 [...]

Read Full Post »

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 [...]

Read Full Post »

C# .NET Optional logging with StackTrace

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;

        [...]

Read Full Post »

Stripping XML nodes imperatively

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 [...]

Read Full Post »