本文整理汇总了C#中JsonType类的典型用法代码示例。如果您正苦于以下问题:C# JsonType类的具体用法?C# JsonType怎么用?C# JsonType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonType类属于命名空间,在下文中一共展示了JsonType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteClass
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();
}
示例2: GetTypeName
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");
}
}
示例3: WriteClass
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();
}
示例4: GetTypeName
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");
}
}
示例5: GetTypeName
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");
}
}
示例6: JSONObject
public JSONObject(bool b)
{
type = JsonType.jbool;
children = null;
array = null;
bvalue = b;
dvalue = double.NaN;
}
示例7: Reset
public void Reset()
{
_type = JsonType.UnKnown;
Text = string.Empty;
Property = null;
Value = null;
}
示例8: WriteClassMembers
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);
}
}
}
示例9: WriteClass
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();
}
示例10: WriteClass
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();
}
示例11: GetTypeName
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");
}
}
示例12: JsonObject
public JsonObject()
{
_type = JsonType.UnKnown;
}
示例13: GetCloseTokenForType
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);
}
}
示例14: Push
private void Push(JsonType value)
{
_stack.Add (value);
_top++;
}
示例15: WriteClassMembers
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);
}
}
}