September 2004 - Posts

XML Serialization basics

Here are a couple of basic (annoying) points about XML serialization. Consider two simple classes:

public class Container
{
    private string m_s;
    private int m_i;
    private Child m_c = null;
    public string S
    {
        get 
        {
            return this.m_s;
        }
        set
        {
            this.m_s = value;
        }
    }
    public int I
    {
        get 
        {
            return this.m_i;
        }
        set
        {
            this.m_i = value;
        }
    }
    public Child C
    {
        get 
        {
            return this.m_c;
        }
    }
    public Container(int i, string s, int ci, string cs)
    {
        this.m_i = i;
        this.m_s = s;
        this.m_c = new Child(ci, cs);
    }
}
public class Child
{
    private string m_cs;
    private int m_ci;
    public string CS
    {
        get 
        {
            return this.m_cs;
        }
        set
        {
            this.m_cs = value;
        }
    }
    public int CI
    {
        get 
        {
            return this.m_ci;
        }
        set
        {
            this.m_ci = value;
        }
    }
    public Child(int i, string s)
    {
        this.m_ci = i;
        this.m_cs = s;
    }
}

Can we serialize them? No, not yet. First of all we have to add public default constructor for each class being serialized:

    public Container(){}
    public
Child(){}

OK, I can live with that. Let's try again:

class Test
{
    public static void Main()
    {
        Container d =
new Container(3, "abc", 4, "123");
        StringWriter sw =
new StringWriter();
        XmlSerializer xs =
new XmlSerializer(d.GetType());

        xs.Serialize(sw, d);
        Console.Write(sw.ToString());
    }
}


Well, it is serialized now, but is not something missing? Where the child class has gone? Now, we have to keep in mind that XMLSerializer taking in account only public WRITABLE property. Property without getter will be skipped, even if it is of reference type and getter is totally unnecessary.

Final touch will give us desirable result:

public class Container
{
    ...
    public Child C
    {
        get 
        {
            return this.m_c;
        }
        set
        {
        }
    }
    ...
}

Compilation for .NET Framework 1.1 in Visual Studio 2005

Like many other developers today, I am using part of the time Visual Studio 2003 and part of the time Visual Studio 2005 (Whidbey, beta 1). VS2005 is so much user-friendly, more productive, fast and advanced that using VS2003 becomes frustrating experience.

Still we have a lot of clients and projects in various stages of development, which use VS2003 and Framework 1.1. It is impossible (in current version of VS2005) to build solution compatible with FW1.1. I think, this limit will prevent a lot of organizations (especially medium and large) to enter VS2005 beta process and will delay adaptation of new tools (FW 1.1, VS2005, Team System). It is definitely make my life harder :) . The funny thing is that this functionality is pretty easy to add. It can be done through special task in msbuild.

Suggestion was post at Product Feedback Center. If you think it is important enough, please vote. You can make a difference.

What do you think? I would like to see your feedbacks.

Happy Rosh Hashanah!

It is Rosh Hashanah (Jewish New Year) tomorrow.

I wish PEACE, joy and prosperity to you and your families. It does not meter where you are, what is your religion or gender, I wish you all the best, my friends! 

NET on the beach.

In unlikely case that some of you, guys, did not receive this invitation yet and will be in Israel at 13.9, you are more then welcome. It is Microsoft annual developers' event. It is coming with cool presentations and demos, swimming pool and beer. Pick your swimming suit and come, it will be fun. 

http://www.microsoft.com/israel/events/msdn/invitation.asp

Connection Strings Examples

Connections is a comprehensive collection of ADO and ADO.NET connection strings samples, including examples of usage and links for additional info. It could be very handy. Thanks to Carl Prothman.

Free Linux

From yesterdays meating with Eric Rudder:

“...Linux is free as a free poppy. You have years to walk with a dog...”