Monday, February 15, 2010

General migration issues - .NET 1.1 to .NET 3.5 [Part - 1]

1. New method "GetObjectData" is added to DataSet class: Since we were using this name for our custom Dataset, we had to overload this method.
Check This out.

2. Warning as Error: 'System.Xml.Xsl.XslTransform' is obsolete: 'This class has been deprecated. Please use System.Xml.Xsl.XslCompiledTransform instead.

XSLTransform calss is depricated and better performing XslCompiledTransform is inroduced.
Check this out for Migrating From the XslTransform Class.

3. Warning as Error: 'System.Xml.Schema.XmlSchemaCollection' is obsolete: 'Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation.

XmlSchemaCollection calss is depricated and better performing XmlSchemaSet is inroduced.

To traverse through XmlSchemaSet we should use XmlSchemaSet.Schemas() method.
foreach (XmlSchema schema in schemaSetObject.Schemas())
{
      xmlSchemaObject = schema;
      .....
      ....
}
4. Warning as Error: 'System.Configuration.ConfigurationSettings.GetConfig(string)' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration! System.Configuration.ConfigurationManager.GetSection'
Visit this link if you need more info on how to use GetSection Method. 

5. Warning as Error: 'System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(System.Runtime.Remoting.Channels.IChannel)' is obsolete: 'Use System.Runtime.Remoting.ChannelServices.RegisterChannel(IChannel chnl, bool ensureSecurity) instead.'

More info here.

Friday, February 12, 2010

StringBuilder.Append vs string.Join

This is most common situation we encounter, joining an array (list) of string into a delimiter seperarted string (most commonly comma seperated). We use string builder to append the array items and make it as one string using a foreach loop.


string[] stringArray = new string[] { "This", "is", "single", "string" };
_______________________________________
Stringbuilder way

StringBuilder sbObject = new StringBuilder();


foreach (string strItem in stringArray)
        sbObject.Append(strItem + " ");
string finalString = sbObject.ToString();


//remove the last character
finalString = finalString.Substring(0, finalString.Length);

output for this code is
"This is single string"
________________________________________
Instead of the above code we can use string.Join(), a built in method which is much efficient and reduces coding effort significantly.

string finalString = string.Join(" ", stringArray);
--
happy coding