示例#1
0
 private static object TryStrongTypeConversion(object obj)
 {
     if (!DDIHelper.IsSkippingStrongTypeConversion(obj))
     {
         Type type  = obj.GetType();
         Type type2 = null;
         if (DDIHelper.StrongTypeToStringList.Contains(type))
         {
             obj = obj.ToString();
         }
         else if (type == typeof(MultiValuedProperty <string>))
         {
             obj = ((MultiValuedProperty <string>)obj).ToArray();
         }
         else if (!DDIHelper.strongType2DataContractMapping.TryGetValue(type, out type2))
         {
             foreach (KeyValuePair <Type, Type> keyValuePair in DDIHelper.strongType2DataContractMapping)
             {
                 if (keyValuePair.Key.IsAssignableFrom(type))
                 {
                     type2 = keyValuePair.Value;
                     break;
                 }
             }
         }
         if (type2 == null && (type.IsEnum || typeof(Uri).IsAssignableFrom(type)))
         {
             obj = obj.ToString();
         }
         else if (type2 != null && type2 != null)
         {
             DDIHelper.Trace("Object: {0} of Type '{1}' is converted to '{2}'.", new object[]
             {
                 obj,
                 type,
                 type2
             });
             obj = Activator.CreateInstance(type2, new object[]
             {
                 obj
             });
         }
     }
     return(obj);
 }