本文整理汇总了C#中MetadataType.IsAbstract方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataType.IsAbstract方法的具体用法?C# MetadataType.IsAbstract怎么用?C# MetadataType.IsAbstract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetadataType
的用法示例。
在下文中一共展示了MetadataType.IsAbstract方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddTypeExtension
private void AddTypeExtension(ref StringBuilderWrapper sbExt, MetadataType type, bool initCollections)
{
//Swift doesn't support extensions on same protocol used by Base and Sub types
if (type.IsAbstract())
return;
var typeName = Type(type.Name, type.GenericArgs);
var typeNameOnly = typeName.SplitOnFirst('<')[0];
sbExt.AppendLine();
sbExt.AppendLine("extension {0} : JsonSerializable".Fmt(typeNameOnly));
sbExt.AppendLine("{");
sbExt = sbExt.Indent();
sbExt.AppendLine("public static var typeName:String {{ return \"{0}\" }}".Fmt(typeName));
//func typeConfig()
var isGenericType = !type.GenericArgs.IsEmpty();
if (!isGenericType)
{
sbExt.AppendLine("public static var metadata = Metadata.create([");
sbExt = sbExt.Indent();
}
else
{
//Swift 2.0 doesn't allow stored static properties on generic types yet
sbExt.AppendLine("public static var metadata:Metadata {");
sbExt = sbExt.Indent();
sbExt.AppendLine("return Metadata.create([");
}
sbExt = sbExt.Indent();
foreach (var prop in GetPropertes(type))
{
var propType = FindType(prop.Type, prop.TypeNamespace, prop.GenericArgs);
if (propType.IsInterface()
|| IgnorePropertyTypeNames.Contains(prop.Type)
|| IgnorePropertyNames.Contains(prop.Name))
continue;
var fnName = "property";
if (prop.IsArray() || ArrayTypes.Contains(prop.Type))
{
fnName = initCollections
? "arrayProperty"
: "optionalArrayProperty";
}
else if (DictionaryTypes.Contains(prop.Type))
{
fnName = initCollections
? "objectProperty"
: "optionalObjectProperty";
}
else
{
if (propType != null && !propType.IsEnum.GetValueOrDefault())
{
fnName = "optionalObjectProperty";
}
else
{
fnName = "optionalProperty";
}
}
var propName = prop.Name.SafeToken().PropertyStyle();
var unescapedName = propName.UnescapeReserved();
sbExt.AppendLine("Type<{0}>.{1}(\"{2}\", get: {{ $0.{3} }}, set: {{ $0.{3} = $1 }}),".Fmt(
typeName, fnName, unescapedName, propName));
}
sbExt = sbExt.UnIndent();
sbExt.AppendLine("])");
sbExt = sbExt.UnIndent();
if (isGenericType)
{
sbExt.AppendLine("}");
}
sbExt = sbExt.UnIndent();
sbExt.AppendLine("}");
}
示例2: AddTypeExtension
private void AddTypeExtension(ref StringBuilderWrapper sbExt, MetadataType type, bool initCollections)
{
//Swift doesn't support extensions on same protocol used by Base and Sub types
if (type.IsAbstract())
return;
var typeName = Type(type.Name, type.GenericArgs);
var typeNameOnly = typeName.SplitOnFirst('<')[0];
sbExt.AppendLine();
sbExt.AppendLine("extension {0} : JsonSerializable".Fmt(typeNameOnly));
sbExt.AppendLine("{");
sbExt = sbExt.Indent();
sbExt.AppendLine("public static var typeName:String {{ return \"{0}\" }}".Fmt(typeName));
//func typeConfig()
sbExt.AppendLine("public static func reflect() -> Type<{0}> {{".Fmt(typeName));
sbExt = sbExt.Indent();
sbExt.AppendLine(
"return TypeConfig.config() ?? TypeConfig.configure(Type<{0}>(".Fmt(typeName));
sbExt = sbExt.Indent();
sbExt.AppendLine("properties: [".Fmt(typeName));
sbExt = sbExt.Indent();
foreach (var prop in GetPropertes(type))
{
var propType = FindType(prop.Type, prop.TypeNamespace, prop.GenericArgs);
if (propType.IsInterface()
|| IgnorePropertyTypeNames.Contains(prop.Type)
|| IgnorePropertyNames.Contains(prop.Name))
continue;
var fnName = "property";
if (prop.IsArray() || ArrayTypes.Contains(prop.Type))
{
fnName = initCollections
? "arrayProperty"
: "optionalArrayProperty";
}
else if (DictionaryTypes.Contains(prop.Type))
{
fnName = initCollections
? "objectProperty"
: "optionalObjectProperty";
}
else
{
if (propType != null && !propType.IsEnum.GetValueOrDefault())
{
fnName = "optionalObjectProperty";
}
else
{
fnName = "optionalProperty";
}
}
sbExt.AppendLine("Type<{0}>.{1}(\"{2}\", get: {{ $0.{2} }}, set: {{ $0.{2} = $1 }}),".Fmt(
typeName, fnName, prop.Name.SafeToken().PropertyStyle()));
}
sbExt = sbExt.UnIndent();
sbExt.AppendLine("]))");
sbExt = sbExt.UnIndent();
sbExt = sbExt.UnIndent();
sbExt.AppendLine("}");
//toJson()
sbExt.AppendLine("public func toJson() -> String {");
sbExt = sbExt.Indent();
sbExt.AppendLine("return {0}.reflect().toJson(self)".Fmt(typeName));
sbExt = sbExt.UnIndent();
sbExt.AppendLine("}");
//fromJson()
sbExt.AppendLine("public static func fromJson(json:String) -> {0}? {{".Fmt(typeName));
sbExt = sbExt.Indent();
sbExt.AppendLine("return {0}.reflect().fromJson({0}(), json: json)".Fmt(typeName));
sbExt = sbExt.UnIndent();
sbExt.AppendLine("}");
//fromObject()
sbExt.AppendLine("public static func fromObject(any:AnyObject) -> {0}? {{".Fmt(typeName));
sbExt = sbExt.Indent();
sbExt.AppendLine("return {0}.reflect().fromObject({0}(), any:any)".Fmt(typeName));
sbExt = sbExt.UnIndent();
sbExt.AppendLine("}");
//toString()
sbExt.AppendLine("public func toString() -> String {");
sbExt = sbExt.Indent();
sbExt.AppendLine("return {0}.reflect().toString(self)".Fmt(typeName));
sbExt = sbExt.UnIndent();
sbExt.AppendLine("}");
//fromString()
//.........这里部分代码省略.........