Querying Network Status in .NET programming

Work with My namespace

We can use My.Computer.Network.IsAvailable in Visual Basic.NET to determine whether the network is connected. The definition of this property is:

It leads to the approach in C#. Continue reading “Querying Network Status in .NET programming”

Play with Linq.Expression

Suddenly Visual Basic 6.0 ……

Yesterday once more.

When ConditionalExpression.ToString() is invoked...
When ConditionalExpression.ToString() is invoked…


Lambda function generated by Linq.Expression.

There’s virtually no way to debug into it…

So I had to use something like Debug.Print. Really had a hard time.

So I decided to implement XmlSerializer “again”

Reinventing the wheel T_T

ref = CXuesong/XSerializer/

Pull is welcomed T_T if you’d like to

Recently I’ve been considering the following problems:

When serializing using XmlSerializer to get more control on what the XML should look like,

  1. How to serialize members with type Nullable<T>, persisting it as XML attribute (rather than element)?
  2. How to serialize references, avoiding it persisted as multiple identical copies of one object?
  3. How to achieve the these two things above, without introducting public auxiliary properties?
    (e.g. for case 1, an auxiliary property can be introduced to do the conversions between Nullable<T> and string, the latter of which can be persisted as XML attribute.)

It seems that case 2 can be solved using DataContractSeriallizer. However, DataContractSeriallizer generates Id by itself, and represent Id and its references with z:Id andz:Ref. As I’ve mentioned in previously (在 XmlSerializer 与 DataContractSerializer 之间抉择), DataContractSeriallizer is rather rigid when you want to control the appearance of XML tree it generates.

Then, how to solve these problems?

Maybe, I’ll reinvent the wheel.

See Also

c# – Is there any way for my class to support serialisation as an XML attribute? – Stack Overflow

The exapmle provided in section “Serializing Derived Classes”(with XmlArrayItemAttribute) may be not the case


Another use of the XmlArrayItemAttribute is to allow the serialization of derived classes. For example, another class named Manager that derives from Employee can be added to the previous example. If you do not apply the XmlArrayItemAttribute, the code will fail at run time because the derived class type will not be recognized. To remedy this, apply the attribute twice, each time setting the Type property for each acceptable type (base and derived).

A serialized instance might resemble the following.

However, this is not the case.
I used the following test case:

which yields the result:

As you can see, xsi:type attribute didn’t appeared in the XML document containing the serialized Group instance. Instead, the element name of derived Manager class is employed.
If I modify the definition of Group class to

Then I get the following result

which coincides with the example output stated on MSDN.
p.s. I tested the code above in VS 2013.