当前位置: 首页>>代码示例>>C#>>正文


C# MetadataType.IsAbstract方法代码示例

本文整理汇总了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("}");
        }
开发者ID:jin29neci,项目名称:ServiceStack,代码行数:85,代码来源:SwiftGenerator.cs

示例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()
//.........这里部分代码省略.........
开发者ID:dittodhole,项目名称:dotnet-ServiceStack,代码行数:101,代码来源:SwiftGenerator.cs


注:本文中的MetadataType.IsAbstract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。