How to Generically Convert One Data Type to Another?

I once had this problem to read an Xml file and populate an object's properties with the value from the Xml. The problem was, the Xml was very simple, everything was string, the properties of the object itself had different data types. The object was a generic object, my application did not know what kind of object it was, the properties were inspected and assigned using Reflection.

This is a sample code to assign a string to an object's property with an unknown data type, it also able to assign an array property.

 using System.Reflection; 
using System.ComponentModel;

 private static void AssignProperty(Object obj, string PropertyName, object Value)
{
    PropertyInfo PI = obj.GetType().GetProperty(PropertyName);

    if (PI.PropertyType.IsArray == true)
    {
        if (!Value.GetType().IsArray)
            Value = new object[] { Value };
    }

    TypeConverter TC = TypeDescriptor.GetConverter(PI.PropertyType);

    if (TC.CanConvertFrom(Value.GetType()))
    {
        PI.SetValue(obj, TC.ConvertFrom(Value), null);
    }
}