Ejemplo n.º 1
0
 private string GetSerializedPrimitiveValue(object data)
 {
     if (data is bool)
     {
         return(true.Equals(data) ? "true" : "false");
     }
     if (data is string)
     {
         return($"\"{Extensions.GetEscapedString(data as string)}\"");
     }
     if (data is DateTime)
     {
         return($"\"{DateParser.Serialize((DateTime)data)}\"");
     }
     if (data.GetType().IsPrimitiveType())
     {
         return(data.ToString());
     }
     if (data.GetType().IsEnum)
     {
         if (base.SerializeEnumAsInteger)
         {
             return(Enum.GetNames(data.GetType()).ToList().IndexOf(data.ToString())
                    .ToString());
         }
         return($"\"{data}\"");
     }
     throw Assert.Guard();
 }
Ejemplo n.º 2
0
 private string GetValueString(object value)
 {
     if (value == null)
     {
         return(null);
     }
     if (value is string)
     {
         return($"\"{Extensions.GetEscapedString((string)value)}\"");
     }
     if (value is DateTime)
     {
         return($"\"{DateParser.Serialize((DateTime)value)}\"");
     }
     return(value.ToString());
 }