public static GType CreateFromJson(JsonData data) { GType ret = null; if (data.Keys.Contains("Class")) { ret = new GTypeClass(); } else if (data.Keys.Contains("Struct")) { ret = new GTypeStruct(); } else if (data.Keys.Contains("Enum")) { ret = new GTypeEnum(); } else if (data.Keys.Contains("BitField")) { ret = new GTypeBitField(); } else { GLog.LogError("Type must be declared as 'Class' or 'Struct' or 'Enum' or 'BitField'. \n" + data.ToJson()); return(null); } if (ret != null) { if (data.Keys.Contains("CompileTo")) { ret.CompileTo = (CompileTarget)Enum.Parse(typeof(CompileTarget), (string)data["CompileTo"]); } else { ret.CompileTo = CompileTarget.CSharp; } if (ret.ParseJson(data)) { return(ret); } } return(null); }
public static GType CreateFromDesc(TypeDesc desc) { GType ret = null; if (desc.Tt == TypeDesc.TT.Class) { ret = new GTypeClass(); } else if (desc.Tt == TypeDesc.TT.Struct) { ret = new GTypeStruct(); } else if (desc.Tt == TypeDesc.TT.Enum) { ret = new GTypeEnum(); } else if (desc.Tt == TypeDesc.TT.BitField) { ret = new GTypeBitField(); } else { GLog.LogError("Type must be declared as 'Class' or 'Struct' or 'Enum' or 'BitField'. \n" + desc.Tt); return(null); } ret.Name = desc.Name; ret.Namespace = desc.Namespace; ret.CompileTo = desc.CompileTo; ret.Gen_Head = desc.Gen_Head; ret.Gen_Serialize = desc.Gen_Serialize; ret.Gen_Deserialize = desc.Gen_Deserialize; if (ret.Parse(desc)) { return(ret); } return(null); }