December 2007 Entries

One of my coworker was trying to convert the existing Sql server reporting services ( what a big name !!!)

projects to Vs 2008 project type , looks like it is not supported in VS 2008. We have no choice other than to

go back to VS 2005.  I dont know why Mi$$crosoft does like that.

 

Is anybody aware of these two keywords OrElse and AndAlso in Vb.Net.

These keywords were introduced in .Net 2.0 . 

 

Dim myobj As Object

 

If Not IsNothing(myobj) AndAlso myobj.y = 200 Then

Console.WriteLine(

"Hello World")
End If

If the myObj is null or nothing then the If condition  shortcircuits and will not validate the condition myObj.y=200 .

I would advise everybody to use the  andAlso and orElse.  I wonder why it was not introduced  a long time back.

C# by default had this feature  by the use && and ||.  

 

 

 

Serialization is one of the concepts, that is always intriguing to developers.

One of my coworker, was trying to move the in process session state management into an out of proc session state service. We were getting some exceptions during the transition, of course when objects need to be persisted in a session, they have to serializable and more than that, if it is an aggregated object (object which may have multiple objects encapsulated in it) then a null check should be performed on each object in the serialization / deserialization method definitions.  

 

VB.NET

 

Public Overrides Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)
 
  If Not IsNothing(_empobject) Then 
        info.AddValue("_empobject", _empobject.Serialize(_empobject)) 
 End If 
 
End sub
 
 Private Sub New(ByVal Info As SerializationInfo, ByVal Context As StreamingContext)
 
      If Not String.IsNullOrEmpty(Info.GetString("_empobject")) Then 
   _empobject = New EmpObject().DeSerialize(Info.GetString("_empobject")) 
     End If 
 
 End Sub

C#

public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)

{    

    if ((_empobject != null)) {

        info.AddValue("_empobject", _empobject.Serialize(_empobject));

    }

   }

private New(SerializationInfo Info, StreamingContext Context)

{  

    if (!string.IsNullOrEmpty(Info.GetString("_empobject"))) {

        _empobject = EmpObject().DeSerialize(Info.GetString("_empobject"));

    }  

}

Finally, how do you serialize a generic list ( of any Type). I was thinking about that, and found this article which explains clearly  how to do it.

http://www.eggheadcafe.com/software/aspnet/30067316/how-can-i-add-generic-lis.aspx

If you wonder how to xml serialize a generic list, look at the below blog post

http://www.hanselman.com/blog/XmlSerializingAGenericListltgt.aspx

If you want a tool to convert a code from VB to C# , you could use the below link to do that

http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx