public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { string name = Enum.GetName(typeof(ProductStatus), (ProductStatus)value); if (string.IsNullOrEmpty(name)) { throw new NoNullAllowedException("Name of a value can't be null"); } JValue jv = new JValue(name.ToLower()); jv.WriteTo(writer); }
static int WriteTo(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); Newtonsoft.Json.Linq.JValue obj = (Newtonsoft.Json.Linq.JValue)ToLua.CheckObject(L, 1, typeof(Newtonsoft.Json.Linq.JValue)); Newtonsoft.Json.JsonWriter arg0 = (Newtonsoft.Json.JsonWriter)ToLua.CheckObject(L, 2, typeof(Newtonsoft.Json.JsonWriter)); Newtonsoft.Json.JsonConverter[] arg1 = ToLua.CheckParamsObject <Newtonsoft.Json.JsonConverter>(L, 3, count - 2); obj.WriteTo(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int WriteTo(IntPtr L) { try { ToLua.CheckArgsCount(L, 3); Newtonsoft.Json.Linq.JValue obj = (Newtonsoft.Json.Linq.JValue)ToLua.CheckObject <Newtonsoft.Json.Linq.JValue>(L, 1); Newtonsoft.Json.JsonWriter arg0 = (Newtonsoft.Json.JsonWriter)ToLua.CheckObject <Newtonsoft.Json.JsonWriter>(L, 2); Newtonsoft.Json.JsonConverter[] arg1 = ToLua.CheckObjectArray <Newtonsoft.Json.JsonConverter>(L, 3); obj.WriteTo(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private void ValidateInEnumAndNotDisallowed(JsonSchemaModel schema) { if (schema == null) return; JToken value = new JValue(_reader.Value); if (schema.Enum != null) { StringWriter sw = new StringWriter(CultureInfo.InvariantCulture); value.WriteTo(new JsonTextWriter(sw)); if (!schema.Enum.ContainsValue(value, new JTokenEqualityComparer())) RaiseError("Value {0} is not defined in enum.".FormatWith(CultureInfo.InvariantCulture, sw.ToString()), schema); } JsonSchemaType? currentNodeType = GetCurrentNodeSchemaType(); if (currentNodeType != null) { if (JsonSchemaGenerator.HasFlag(schema.Disallow, currentNodeType.Value)) RaiseError("Type {0} is disallowed.".FormatWith(CultureInfo.InvariantCulture, currentNodeType), schema); } }