Exemplo n.º 1
0
 private static object ConvertToEnum(object parsed, Type objtype)
 {
     if (Enum.IsDefined(objtype, (string)parsed))
     {
         return(Enum.Parse(objtype, (string)parsed));
     }
     Debug.LogWarning("The specified enum for " + objtype.Name + " does not exist. Existing Values are: " + Converter.ArrayToString(Enum.GetValues(objtype)));
     return(Enum.GetValues(objtype).GetValue(0));
 }
Exemplo n.º 2
0
 private static object ParsedToObject(object parsed, Type objtype)
 {
     if (parsed == null)
     {
         return(null);
     }
     if (Helper.IsPrimitive(objtype))
     {
         return(PrimitiveToObject(parsed, objtype));
     }
     if (parsed.GetType() == typeof(Dictionary <string, object>))
     {
         return(DictionaryToObject(parsed, objtype));
     }
     if (parsed.GetType() == typeof(List <object>))
     {
         if (objtype.IsArray)
         {
             return(ArrayToObject(parsed, objtype));
         }
         else
         {
             return(ListToObject(parsed, objtype));
         }
     }
     if (objtype.IsEnum && parsed.GetType() == typeof(string))
     {
         if (Enum.IsDefined(objtype, (string)parsed))
         {
             return(Enum.Parse(objtype, (string)parsed));
         }
         Debug.LogWarning("The specified enum for " + objtype.Name + " does not exist. Existing Values are: " + Converter.ArrayToString(Enum.GetValues(objtype)));
         return(Enum.GetValues(objtype).GetValue(0));
     }
     return(null);
 }