예제 #1
0
 private static string SerializePropertyValue(object propertyValue)
 {
     if (propertyValue == null)
     {
         return("NULL");
     }
     else if (propertyValue is string)
     {
         return("[String] " + propertyValue.ToString().Trim());
     }
     else if (propertyValue.GetType().IsPrimitive)
     {
         return("[" + propertyValue.GetType().Name + "] " + propertyValue.ToString());
     }
     else
     {
         try
         {
             Type   type = propertyValue.GetType();
             string name = type.FullName;
             if (type.FullName.Contains("<>f__AnonymousType"))
             {
                 name = "AnonymousType";
             }
             return("[" + name + "] " + SerializationUtility.JsonSerialize2(propertyValue));
         }
         catch (Exception ex)
         {
             return("Serialize exception for type '" + propertyValue.GetType().AssemblyQualifiedName + "' : " + ex.Message);
         }
     }
 }
예제 #2
0
 public static string JsonSerializeCommon(object obj)
 {
     if (obj.GetType().Name.StartsWith("<>f__AnonymousType"))
     {
         return(SerializationUtility.JsonSerialize2(obj));
     }
     return(SerializationUtility.JsonSerialize(obj));
 }