public virtual object ConvertTo(CLS_Content env, object src, CLType targetType)
{
Type targettype = (Type)targetType;
if (this._type == targettype) return src;
//type.get
if (_type.IsEnum)
{
if ((Type)targetType == typeof(int))
return System.Convert.ToInt32(src);
else if ((Type)targetType == typeof(uint))
return System.Convert.ToUInt32(src);
else if ((Type)targetType == typeof(short))
return System.Convert.ToInt16(src);
else if ((Type)targetType == typeof(ushort))
return System.Convert.ToUInt16(src);
else
{
return System.Convert.ToInt32(src);
}
}
else if (targettype != null && targettype.IsEnum)
{
return Enum.ToObject(targettype, src);
}
var ms = _type.GetMethods();
foreach (var m in ms)
{
if ((m.Name == "op_Implicit" || m.Name == "op_Explicit") && m.ReturnType == targettype)
{
return m.Invoke(null, new object[] { src });
}
}
if (targettype != null)
{
if (targettype.IsAssignableFrom(_type))
return src;
if (src != null && targettype.IsInstanceOfType(src))
return src;
}
else
{
return src;
}
return null;
}