private static object CreateObject(Type itemType)
{
try
{
if (itemType.FullName == "System.Uri")
{
????
}
return Activator.CreateInstance(itemType);
}
catch (Exception)
{
return itemType.GetConstructor(new Type[] { }).Invoke(new object[] { });
}
}
private static object CreateObject(Type itemType) { try { if (itemType.FullName == System.Uri) { ????
Share
Since a
Uriis immutable (much like string), it doesn’t make sense to create one without a value. When you know the Uri, use the regular constructor, for examplenew Uri(string)– or useTryCreate.Btw – you could also test:
if(itemType == typeof(Uri))