public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type) { var visibility = config.InternalVisibility ? "Friend" : "Public"; if (config.UseNestedClasses) { sw.WriteLine(" {0} Partial Class {1}", visibility, config.MainClass); if (!type.IsRoot) { if (ShouldApplyNoRenamingAttribute(config)) sw.WriteLine(" " + NoRenameAttribute); if (ShouldApplyNoPruneAttribute(config)) sw.WriteLine(" " + NoPruneAttribute); sw.WriteLine(" {0} Class {1}", visibility, type.AssignedName); } } else { if (ShouldApplyNoRenamingAttribute(config)) sw.WriteLine(" " + NoRenameAttribute); if (ShouldApplyNoPruneAttribute(config)) sw.WriteLine(" " + NoPruneAttribute); sw.WriteLine(" {0} Class {1}", visibility, type.AssignedName); } var prefix = config.UseNestedClasses && !type.IsRoot ? " " : " "; WriteClassMembers(config, sw, type, prefix); if (config.UseNestedClasses && !type.IsRoot) sw.WriteLine(" End Class"); sw.WriteLine(" End Class"); sw.WriteLine(); }
public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config) { var arraysAsLists = !config.ExplicitDeserialization; switch (type.Type) { case JsonTypeEnum.Anything: return "object"; case JsonTypeEnum.Array: return arraysAsLists ? "IList<" + GetTypeName(type.InternalType, config) + ">" : GetTypeName(type.InternalType, config) + "[]"; case JsonTypeEnum.Dictionary: return "Dictionary<string, " + GetTypeName(type.InternalType, config) + ">"; case JsonTypeEnum.Boolean: return "bool"; case JsonTypeEnum.Float: return "double"; case JsonTypeEnum.Integer: return "int"; case JsonTypeEnum.Long: return "long"; case JsonTypeEnum.Date: return "DateTime"; case JsonTypeEnum.NonConstrained: return "object"; case JsonTypeEnum.NullableBoolean: return "bool?"; case JsonTypeEnum.NullableFloat: return "double?"; case JsonTypeEnum.NullableInteger: return "int?"; case JsonTypeEnum.NullableLong: return "long?"; case JsonTypeEnum.NullableDate: return "DateTime?"; case JsonTypeEnum.NullableSomething: return "object"; case JsonTypeEnum.Object: return type.AssignedName; case JsonTypeEnum.String: return "string"; default: throw new NotSupportedException("Unsupported json type"); } }
public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type) { var visibility = "public"; sw.WriteLine(); sw.WriteLine("package {0};",config.Namespace ); if (config.UseNestedClasses) { if (!type.IsRoot) { if (ShouldApplyNoRenamingAttribute(config)) sw.WriteLine(" " + NoRenameAttribute); if (ShouldApplyNoPruneAttribute(config)) sw.WriteLine(" " + NoPruneAttribute); sw.WriteLine(" {0} class {1}", visibility, type.AssignedName); sw.WriteLine(" {"); } } else { if (ShouldApplyNoRenamingAttribute(config)) sw.WriteLine(" " + NoRenameAttribute); if (ShouldApplyNoPruneAttribute(config)) sw.WriteLine(" " + NoPruneAttribute); sw.WriteLine(" {0} class {1}", visibility, type.AssignedName); sw.WriteLine(" {"); } var prefix = config.UseNestedClasses && !type.IsRoot ? " " : " "; var shouldSuppressWarning = config.InternalVisibility && !config.UseProperties && !config.ExplicitDeserialization; if (shouldSuppressWarning) { sw.WriteLine("#pragma warning disable 0649"); if (!config.UsePascalCase) sw.WriteLine(); } if (type.IsRoot && config.ExplicitDeserialization) WriteStringConstructorExplicitDeserialization(config, sw, type, prefix); if (config.ExplicitDeserialization) { if (config.UseProperties) WriteClassWithPropertiesExplicitDeserialization(sw, type, prefix); else WriteClassWithFieldsExplicitDeserialization(sw, type, prefix); } else { WriteClassMembers(config, sw, type, prefix); } if (shouldSuppressWarning) { sw.WriteLine(); sw.WriteLine("#pragma warning restore 0649"); sw.WriteLine(); } if (config.UseNestedClasses && !type.IsRoot) sw.WriteLine(" }"); if (!config.UseNestedClasses) sw.WriteLine(" }"); sw.WriteLine(); }
public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config) { var arraysAsLists = !config.ExplicitDeserialization; switch (type.Type) { case JsonTypeEnum.Anything: return "object"; case JsonTypeEnum.Array: return arraysAsLists ? "IList<" + GetTypeName(type.InternalType, config) + ">" : GetTypeName(type.InternalType, config) + "[]"; case JsonTypeEnum.Dictionary: return "Dictionary<string, " + GetTypeName(type.InternalType, config) + ">"; case JsonTypeEnum.Boolean: return "bit NOT NULL"; case JsonTypeEnum.Float: return "[decimal](9,2) NOT NULL"; case JsonTypeEnum.Integer: return "[int] NOT NULL"; case JsonTypeEnum.Long: return "[bigint] NOT NULL"; case JsonTypeEnum.Date: return "[datetime]"; case JsonTypeEnum.NonConstrained: return "object"; case JsonTypeEnum.NullableBoolean: return "bit NULL"; case JsonTypeEnum.NullableFloat: return "[decimal](9,2) NULL"; case JsonTypeEnum.NullableInteger: return "[int] NULL"; case JsonTypeEnum.NullableLong: return "[bigint] NULL"; case JsonTypeEnum.NullableDate: return "[datetime] NULL"; case JsonTypeEnum.NullableSomething: return "object NULL"; case JsonTypeEnum.Object: return type.AssignedName; case JsonTypeEnum.String: return "[varchar](50) NULL"; default: throw new System.NotSupportedException("Unsupported json type"); } }
public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config) { var arraysAsLists = config.ExplicitDeserialization; switch (type.Type) { case JsonTypeEnum.Anything: return "Object"; case JsonTypeEnum.Array: return arraysAsLists ? "IList(Of " + GetTypeName(type.InternalType, config) + ")" : GetTypeName(type.InternalType, config) + "()"; case JsonTypeEnum.Dictionary: return "Dictionary(Of String, " + GetTypeName(type.InternalType, config) + ")"; case JsonTypeEnum.Boolean: return "Boolean"; case JsonTypeEnum.Float: return "Double"; case JsonTypeEnum.Integer: return "Integer"; case JsonTypeEnum.Long: return "Long"; case JsonTypeEnum.Date: return "DateTime"; case JsonTypeEnum.NonConstrained: return "Object"; case JsonTypeEnum.NullableBoolean: return "Boolean?"; case JsonTypeEnum.NullableFloat: return "Double?"; case JsonTypeEnum.NullableInteger: return "Integer?"; case JsonTypeEnum.NullableLong: return "Long?"; case JsonTypeEnum.NullableDate: return "DateTime?"; case JsonTypeEnum.NullableSomething: return "Object"; case JsonTypeEnum.Object: return type.AssignedName; case JsonTypeEnum.String: return "String"; default: throw new System.NotSupportedException("Unsupported json type"); } }
public JSONObject() { type = JsonType.jobj; children = new Dictionary<string, JSONObject>(); array = null; svalue = null; dvalue = double.NaN; }
public JSONObject(double d) { type = JsonType.jnum; children = null; array = null; svalue = null; dvalue = d; }
public JSONObject(string s) { type = JsonType.jstr; dvalue = double.NaN; children = null; array = null; svalue = s; }
public JSONObject(bool b) { type = JsonType.jbool; children = null; array = null; bvalue = b; dvalue = double.NaN; }
public void Reset() { _type = JsonType.UnKnown; Text = string.Empty; Property = null; Value = null; }
private void WriteClassMembers(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type) { foreach (var field in type.Fields) { if (config.UseProperties) { string typeName = field.Type.InternalType == null ? field.Type.GetTypeName() : field.Type.InternalType.GetTypeName(); sw.WriteLine(" [{0}] {1},", field.MemberName, typeName); } } }
public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type) { sw.WriteLine("create table " + type.AssignedName + " ("); sw.WriteLine(" [Id] [int] IDENTITY(1,1) NOT NULL,"); WriteClassMembers(config, sw, type); sw.WriteLine("CONSTRAINT [PK_" + type.AssignedName + "] PRIMARY KEY CLUSTERED"); sw.WriteLine(" ("); sw.WriteLine(" [Id] asc"); sw.WriteLine(" )"); sw.WriteLine(")"); sw.WriteLine(); }
public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type) { var prefix = GetNamespace(config, type.IsRoot) != null ? " " : ""; var exported = !config.InternalVisibility || config.SecondaryNamespace != null; sw.WriteLine(prefix + (exported ? "export " : string.Empty) + "interface " + type.AssignedName + " {"); foreach (var field in type.Fields) { var shouldDefineNamespace = type.IsRoot && config.SecondaryNamespace != null && config.Namespace != null && (field.Type.Type == JsonTypeEnum.Object || (field.Type.InternalType != null && field.Type.InternalType.Type == JsonTypeEnum.Object)); if (config.ExamplesInDocumentation) { sw.WriteLine(); sw.WriteLine(prefix + " /**"); sw.WriteLine(prefix + " * Examples: " + field.GetExamplesText()); sw.WriteLine(prefix + " */"); } sw.WriteLine(prefix + " " + field.JsonMemberName + (IsNullable(field.Type.Type) ? "?" : "") + ": " + (shouldDefineNamespace ? config.SecondaryNamespace + "." : string.Empty) + GetTypeName(field.Type, config) + ";"); } sw.WriteLine(prefix + "}"); sw.WriteLine(); }
public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config) { switch (type.Type) { case JsonTypeEnum.Anything: return "any"; case JsonTypeEnum.String: return "string"; case JsonTypeEnum.Boolean: return "bool"; case JsonTypeEnum.Integer: case JsonTypeEnum.Long: case JsonTypeEnum.Float: return "number"; case JsonTypeEnum.Date: return "Date"; case JsonTypeEnum.NullableInteger: case JsonTypeEnum.NullableLong: case JsonTypeEnum.NullableFloat: return "number"; case JsonTypeEnum.NullableBoolean: return "bool"; case JsonTypeEnum.NullableDate: return "Date"; case JsonTypeEnum.Object: return type.AssignedName; case JsonTypeEnum.Array: return GetTypeName(type.InternalType, config) + "[]"; case JsonTypeEnum.Dictionary: return "{ [key: string]: " + GetTypeName(type.InternalType, config) + "; }"; case JsonTypeEnum.NullableSomething: return "any"; case JsonTypeEnum.NonConstrained: return "any"; default: throw new NotSupportedException("Unsupported type"); } }
private void WriteEnd(JsonType type) { switch (type) { case JsonType.Object: WriteEndObject(); break; case JsonType.Array: WriteEndArray(); break; case JsonType.Constructor: WriteEndConstructor(); break; default: throw new JsonWriterException("Unexpected type when writing end: " + type); } }
private JsonToken GetCloseTokenForType(JsonType type) { switch (type) { case JsonType.Object: return JsonToken.EndObject; case JsonType.Array: return JsonToken.EndArray; case JsonType.Constructor: return JsonToken.EndConstructor; default: throw new JsonWriterException("No close token for type: " + type); } }
private void CheckValues(object[] values, JsonType expectedType) { JsonPrimitive target; bool success; foreach (object value in values) { success = JsonPrimitive.TryCreate(value, out target); Assert.IsTrue(success); Assert.IsNotNull(target); Assert.AreEqual(expectedType, target.JsonType); } }
private void WriteClassMembers(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type, string prefix) { foreach (var field in type.Fields) { //if (config.UsePascalCase || config.ExamplesInDocumentation) sw.WriteLine(); //if (config.ExamplesInDocumentation) //{ // sw.WriteLine(prefix + "/// <summary>"); // sw.WriteLine(prefix + "/// Examples: " + field.GetExamplesText()); // sw.WriteLine(prefix + "/// </summary>"); //} //if (config.UsePascalCase || config.PropertyAttribute != "None") //{ // if (config.UsePascalCase && config.PropertyAttribute == "None") // sw.WriteLine(prefix + "@JsonProperty(\"{0}\")", field.JsonMemberName); // else // { // //if (config.PropertyAttribute == "DataMember") // // sw.WriteLine(prefix + "[" + config.PropertyAttribute + "(Name=\"{0}\")]", field.JsonMemberName); // if (config.PropertyAttribute == "JsonProperty") // sw.WriteLine(prefix + "@" + config.PropertyAttribute + "(\"{0}\")", field.JsonMemberName); // } //} if (config.UseProperties) { //sw.WriteLine(prefix + "@JsonProperty" + "(\"{0}\")", field.JsonMemberName); sw.WriteLine(prefix + "public function get{0}() {{ \r\t\t return $this->{1} \r\t}}", ChangeFirstChar(field.MemberName), field.MemberName); sw.WriteLine(prefix + "public function set{0}(${1}) {{ \r\t\t $this->{1} = ${1} \r\t}}", ChangeFirstChar(field.MemberName), field.MemberName); sw.WriteLine(prefix + "public ${1}; //{0}", field.Type.GetTypeName(), field.MemberName); sw.WriteLine(); } else { sw.WriteLine(prefix + "public ${1}; //{0}", field.Type.GetTypeName(), field.MemberName); } } }
public Response(JsonType fromJson) { this.json = fromJson; }
public JsonData(float number) { type = JsonType.Single; inst_single = number; }
public JsonObject() { _type = JsonType.UnKnown; }
public JsonData(bool boolean) { type = JsonType.Boolean; inst_boolean = boolean; }
/// <summary>create blank JSObject</summary> public DynamicJson() { xml = new XElement("root", CreateTypeAttr(JsonType.@object)); jsonType = JsonType.@object; }
private static XAttribute CreateTypeAttr(JsonType type) { return(new XAttribute("type", type.ToString())); }
internal XSet(HashSet <T> values) { this.values = values ?? throw new ArgumentNullException(nameof(values)); this.elementCode = System.Type.GetTypeCode(typeof(T)); this.elementType = XHelper.GetElementType(this.elementCode); }
public void SetJsonType(JsonType type) { }
void IJsonWrapper.SetSingle(float val) { type = JsonType.Single; inst_single = val; json = null; }
private void WriteStringConstructorExplicitDeserialization(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type, string prefix) { sw.WriteLine(); sw.WriteLine(prefix + "public {1}(string json)", config.InternalVisibility ? "internal" : "public", type.AssignedName); sw.WriteLine(prefix + " : this(JObject.Parse(json))"); sw.WriteLine(prefix + "{"); sw.WriteLine(prefix + "}"); sw.WriteLine(); }
public void AddJsonType(string key, JsonType type) { Items.Add(key, type); }
public JsonData(double number) { type = JsonType.Double; inst_double = number; }
public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type) { }
public JsonData(int number) { type = JsonType.Int; inst_int = number; }
public JsonValue(JsonType type, float value) { this.type = type; this.numberValue = value; }
public JsonData(long number) { type = JsonType.Long; inst_long = number; }
public bool ContainsField(string id, JsonType type) { JsonObject field = Fields[id]; return(field != null && field.JsonType == type); }
public JsonData(string str) { type = JsonType.String; inst_string = str; }
public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type) { //var visibility = config.InternalVisibility ? "" : "public"; //if (config.UseNestedClasses) //{ // if (!type.IsRoot) // { // if (config.PropertyAttribute == "DataMember") // { // sw.WriteLine(" [DataContract]"); // } // if (ShouldApplyNoRenamingAttribute(config)) sw.WriteLine(" " + NoRenameAttribute); // if (ShouldApplyNoPruneAttribute(config)) sw.WriteLine(" " + NoPruneAttribute); // sw.WriteLine(" {0} class {1}", visibility, type.AssignedName); // sw.WriteLine(" {"); // } //} //else //{ // if (config.PropertyAttribute == "DataMember") // { // sw.WriteLine(" [DataContract]"); // } // if (ShouldApplyNoRenamingAttribute(config)) sw.WriteLine(" " + NoRenameAttribute); // if (ShouldApplyNoPruneAttribute(config)) sw.WriteLine(" " + NoPruneAttribute); sw.WriteLine("class {0}", type.AssignedName); sw.WriteLine("{"); //} var prefix = config.UseNestedClasses && !type.IsRoot ? "" : " "; var shouldSuppressWarning = config.InternalVisibility && !config.UseProperties && !config.ExplicitDeserialization; if (shouldSuppressWarning) { sw.WriteLine("#pragma warning disable 0649"); if (!config.UsePascalCase) sw.WriteLine(); } //if (type.IsRoot && config.ExplicitDeserialization) WriteStringConstructorExplicitDeserialization(config, sw, type, prefix); //if (config.ExplicitDeserialization) //{ // if (config.UseProperties) WriteClassWithPropertiesExplicitDeserialization(sw, type, prefix); // else WriteClassWithFieldsExplicitDeserialization(sw, type, prefix); //} //else //{ WriteClassMembers(config, sw, type, prefix); //} if (shouldSuppressWarning) { sw.WriteLine(); sw.WriteLine("#pragma warning restore 0649"); sw.WriteLine(); } if (config.UseNestedClasses && !type.IsRoot) sw.WriteLine(" }"); if (!config.UseNestedClasses) sw.WriteLine("}"); sw.WriteLine(); }
void IJsonWrapper.SetBoolean(bool val) { type = JsonType.Boolean; inst_boolean = val; json = null; }
public bool ContainsField(string id, JsonType type) { JsonObject field = Fields[id]; return (field != null && field.JsonType == type); }
void IJsonWrapper.SetDouble(double val) { type = JsonType.Double; inst_double = val; json = null; }
private void Push(JsonType value) { _top++; if (_stack.Count <= _top) _stack.Add(value); else _stack[_top] = value; }
void IJsonWrapper.SetInt(int val) { type = JsonType.Int; inst_int = val; json = null; }
private void WriteClassWithPropertiesExplicitDeserialization(TextWriter sw, JsonType type, string prefix) { sw.WriteLine(prefix + "private JObject __jobject;"); sw.WriteLine(prefix + "public {0}(JObject obj)", type.AssignedName); sw.WriteLine(prefix + "{"); sw.WriteLine(prefix + " this.__jobject = obj;"); sw.WriteLine(prefix + "}"); sw.WriteLine(); foreach (var field in type.Fields) { string variable = null; if (field.Type.MustCache) { variable = "_" + char.ToLower(field.MemberName[0]) + field.MemberName.Substring(1); sw.WriteLine(prefix + "[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]"); sw.WriteLine(prefix + "private {0} {1};", field.Type.GetTypeName(), variable); } sw.WriteLine(prefix + "public {0} {1}", field.Type.GetTypeName(), field.MemberName); sw.WriteLine(prefix + "{"); sw.WriteLine(prefix + " get"); sw.WriteLine(prefix + " {"); if (field.Type.MustCache) { sw.WriteLine(prefix + " if ({0} == null)", variable); sw.WriteLine(prefix + " {0} = {1};", variable, field.GetGenerationCode("__jobject")); sw.WriteLine(prefix + " return {0};", variable); } else { sw.WriteLine(prefix + " return {0};", field.GetGenerationCode("__jobject")); } sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + "}"); sw.WriteLine(); } }
void IJsonWrapper.SetLong(long val) { type = JsonType.Long; inst_long = val; json = null; }
private void WriteClassWithFieldsExplicitDeserialization(TextWriter sw, JsonType type, string prefix) { sw.WriteLine(prefix + "public {0}(JObject obj)", type.AssignedName); sw.WriteLine(prefix + "{"); foreach (var field in type.Fields) { sw.WriteLine(prefix + " this.{0} = {1};", field.MemberName, field.GetGenerationCode("obj")); } sw.WriteLine(prefix + "}"); sw.WriteLine(); foreach (var field in type.Fields) { sw.WriteLine(prefix + "public readonly {0} {1};", field.Type.GetTypeName(), field.MemberName); } }
private static object FromJsonValue(JsonValue jsonValue, Type objectType) { if (jsonValue == null) { return(null); } object obj = null; JsonType jsonType = jsonValue.JsonType; Log.Verbose("In FromJsonValue. jsonValue: {0}, objecttype: {1}", jsonValue, objectType); switch (jsonType) { case JsonType.Array: { if (typeof(IList).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo())) { var list = (IList)System.Activator.CreateInstance(objectType); var jsonArray = (JsonArray)jsonValue; Log.Verbose("Json Array = {0}", jsonArray.ToString()); foreach (JsonValue jsonValueItem in jsonArray) { Log.Verbose("- jsonValueItem {0}", jsonValueItem); Type type = objectType.GenericTypeArguments[objectType.GenericTypeArguments.Length - 1]; if (jsonValueItem is JsonObject) { Log.Verbose("Found array, calling DeserializeDataContract."); list.Add(DeserializeDataContract(jsonValueItem, type)); } else { Log.Verbose("Found array, recursively calling myself (FromJsonValue)."); list.Add(FromJsonValue(jsonValueItem, type)); } } obj = list; } break; } case JsonType.String: case JsonType.Boolean: case JsonType.Number: { var jsonPrimitive = (JsonPrimitive)jsonValue; if (objectType.GetTypeInfo().IsGenericType&& objectType.GetGenericTypeDefinition() == typeof(Nullable <>)) { objectType = objectType.GetTypeInfo().GenericTypeArguments[0]; } //The following line is commented out for Mono Compatibility //if (!jsonPrimitive.TryReadAs(objectType, out obj)) if (!TryReadAs(jsonPrimitive, objectType, out obj)) { obj = null; } break; } case JsonType.Object: { if (typeof(IDictionary <string, string>).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo())) { var jsonObject = (JsonObject)jsonValue; var dictionary = new Dictionary <string, string>(); var keys = jsonObject.Keys; foreach (var key in keys) { Log.Verbose("Found object, recursively calling myself (FromJsonValue)."); var value = (string)FromJsonValue(jsonObject[key], typeof(string)); dictionary.Add(key, value); } obj = dictionary; } else { // Keeping old behaviour just in case, but I cannot see what good this would do. obj = jsonValue; } break; } } return(obj); }
public JsonValue(JsonType type, object value) { this.type = type; this.objectValue = value; }
public Json() { Type = JsonType.Object; data = new Dictionary <string, object>(); }
public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type) { throw new NotImplementedException(); }
public void SetString(string val) { type = JsonType.String; this.val = val; json = null; }
private Json(JsonType type) { primitiveValue = null; Type = type; data = new Dictionary <string, object>(); }
private void Push(JsonType value) { _stack.Add (value); _top++; }
private void WriteClassMembers(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type, string prefix) { foreach (var field in type.Fields) { if (config.UsePascalCase || config.ExamplesInDocumentation) sw.WriteLine(); if (config.ExamplesInDocumentation) { sw.WriteLine(prefix + "''' <summary>"); sw.WriteLine(prefix + "''' Examples: " + field.GetExamplesText()); sw.WriteLine(prefix + "''' </summary>"); } if (config.UsePascalCase) { sw.WriteLine(prefix + "<JsonProperty(\"{0}\")>", field.JsonMemberName); } if (config.UseProperties) { sw.WriteLine(prefix + "Public Property {1} As {0}", field.Type.GetTypeName(), field.MemberName); } else { sw.WriteLine(prefix + "Public {1} As {0}", field.Type.GetTypeName(), field.MemberName); } } }
internal XImmutableArray(T[] values) { this.values = values ?? throw new ArgumentNullException(nameof(values)); this.elementCode = System.Type.GetTypeCode(typeof(T)); this.elementType = XHelper.GetElementType(this.elementCode); }
public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config) { throw new NotImplementedException(); }
void IJsonWrapper.SetString(string val) { type = JsonType.String; inst_string = val; json = null; }
private DynamicJson(XElement element, JsonType type) { xml = element; jsonType = type; }
bool ProcessCharacter(char ch) { int next_class, next_state; if (ch >= 128) next_class = C_ETC; else { next_class = ascii_class [ch]; if (next_class <= UNIVERSAL_ERROR) return false; } if (escaped) { escaped = false; RemoveLastCharFromBuffer (); switch (ch) { case 'b': buffer.Append ('\b'); break; case 'f': buffer.Append ('\f'); break; case 'n': buffer.Append ('\n'); break; case 'r': buffer.Append ('\r'); break; case 't': buffer.Append ('\t'); break; case '"': case '\\': case '/': buffer.Append (ch); break; case 'u': buffer.Append ("\\u"); break; default: return false; } } else if (jsonType != JsonType.NONE || !(next_class == C_SPACE || next_class == C_WHITE)) buffer.Append (ch); next_state = state_transition_table [state, next_class]; if (next_state >= 0) { state = next_state; return true; } object result; /* An action to perform */ switch (next_state) { case UC: /* Unicode character */ DecodeUnicodeChar (); state = ST; break; case EX: /* Escaped character */ escaped = true; state = ES; break; case MX: /* integer detected by minus */ jsonType = JsonType.INTEGER; state = MI; break; case PX: /* integer detected by plus */ jsonType = JsonType.INTEGER; state = MI; break; case ZX: /* integer detected by zero */ jsonType = JsonType.INTEGER; state = ZE; break; case IX: /* integer detected by 1-9 */ jsonType = JsonType.INTEGER; state = IN; break; case DE: /* floating point number detected by exponent*/ jsonType = JsonType.FLOAT; state = E1; break; case DF: /* floating point number detected by fraction */ jsonType = JsonType.FLOAT; state = FX; break; case SB: /* string begin " or ' */ buffer.Length = 0; quoteChar = ch; jsonType = JsonType.STRING; state = ST; break; case KB: /* unquoted key name begin */ jsonType = JsonType.STRING; state = UK; break; case UE: /* unquoted key name end ':' */ RemoveLastCharFromBuffer (); if (ParseBuffer (out result)) StoreKey (result); jsonType = JsonType.NONE; PopMode (JsonMode.KEY); PushMode (JsonMode.OBJECT); state = VA; buffer.Length = 0; break; case NU: /* n */ jsonType = JsonType.NULL; state = N1; break; case FA: /* f */ jsonType = JsonType.FALSE; state = F1; break; case TR: /* t */ jsonType = JsonType.TRUE; state = T1; break; case EO: /* empty } */ result = PopObject (true); if (result != null) StoreValue (result); PopMode (JsonMode.KEY); state = OK; break; case OE: /* } */ RemoveLastCharFromBuffer (); if (ParseBuffer (out result)) StoreValue (result); result = PopObject (true); if (result != null) StoreValue (result); PopMode (JsonMode.OBJECT); jsonType = JsonType.NONE; state = OK; break; case AE: /* ] */ RemoveLastCharFromBuffer (); if (ParseBuffer (out result)) StoreValue (result); PopMode (JsonMode.ARRAY); result = PopObject (true); if (result != null) StoreValue (result); jsonType = JsonType.NONE; state = OK; break; case OS: /* { */ RemoveLastCharFromBuffer (); CreateObject (); PushMode (JsonMode.KEY); state = OB; break; case AB: /* [ */ RemoveLastCharFromBuffer (); CreateArray (); PushMode (JsonMode.ARRAY); state = AR; break; case SE: /* string end " or ' */ if (ch == quoteChar) { RemoveLastCharFromBuffer (); switch (PeekMode ()) { case JsonMode.KEY: if (ParseBuffer (out result)) StoreKey (result); jsonType = JsonType.NONE; state = CO; buffer.Length = 0; break; case JsonMode.ARRAY: case JsonMode.OBJECT: if (ParseBuffer (out result)) StoreValue (result); jsonType = JsonType.NONE; state = OK; break; case JsonMode.NONE: /* A stand-alone string */ jsonType = JsonType.STRING; state = IV; /* the rest of input is invalid */ if (ParseBuffer (out result)) PushObject (result); break; default: throw new ArgumentException ("Syntax error: string in unexpected place."); } } break; case CM: /* , */ RemoveLastCharFromBuffer (); // With MS.AJAX, a comma resets the recursion depth recursionDepth = 0; bool doStore = ParseBuffer (out result); switch (PeekMode ()) { case JsonMode.OBJECT: if (doStore) StoreValue (result); PopMode (JsonMode.OBJECT); PushMode (JsonMode.KEY); jsonType = JsonType.NONE; state = KE; break; case JsonMode.ARRAY: jsonType = JsonType.NONE; state = VA; if (doStore) StoreValue (result); break; default: throw new ArgumentException ("Syntax error: unexpected comma."); } break; case CA: /* : */ RemoveLastCharFromBuffer (); // With MS.AJAX a colon increases recursion depth if (++recursionDepth >= recursionLimit) throw new ArgumentException ("Recursion limit has been reached on parsing input."); PopMode (JsonMode.KEY); PushMode (JsonMode.OBJECT); state = VA; break; case IF: /* Infinity */ case NN: /* NaN */ jsonType = JsonType.FLOAT; switch (PeekMode ()) { case JsonMode.ARRAY: case JsonMode.OBJECT: if (ParseBuffer (out result)) StoreValue (result); jsonType = JsonType.NONE; state = OK; break; case JsonMode.NONE: /* A stand-alone NaN/Infinity */ jsonType = JsonType.FLOAT; state = IV; /* the rest of input is invalid */ if (ParseBuffer (out result)) PushObject (result); break; default: throw new ArgumentException ("Syntax error: misplaced NaN/Infinity."); } buffer.Length = 0; break; default: throw new ArgumentException (GetModeMessage (PeekMode ())); } return true; }
public void SetNatural(long val) { type = JsonType.Natural; this.val = val; json = null; }