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


C# Type.GetGenericArgumentsEx方法代码示例

本文整理汇总了C#中Type.GetGenericArgumentsEx方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetGenericArgumentsEx方法的具体用法?C# Type.GetGenericArgumentsEx怎么用?C# Type.GetGenericArgumentsEx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Type的用法示例。


在下文中一共展示了Type.GetGenericArgumentsEx方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddType

        void AddType(Type type)
        {
            if (type == null || type == typeof(object) || type.IsGenericParameter || _usedTypes.Contains(type))
                return;

            _usedTypes.Add(type);

            if (type.IsGenericTypeEx())
                foreach (var arg in type.GetGenericArgumentsEx())
                    AddType(arg);

            if (type.IsGenericTypeEx() && type.GetGenericTypeDefinition() != type)
                AddType(type.GetGenericTypeDefinition());

            AddType(type.BaseTypeEx());

            foreach (var i in type.GetInterfacesEx())
                AddType(i);
        }
开发者ID:ili,项目名称:linq2db,代码行数:19,代码来源:ExpressionTestGenerator.cs

示例2: GetTypeName

        string GetTypeName(Type type)
        {
            if (type == null || type == typeof(object))
                return null;

            if (type.IsGenericParameter)
                return type.ToString();

            string name;

            if (_typeNames.TryGetValue(type, out name))
                return name;

            if (IsAnonymous(type))
            {
                _typeNames[type] = null;
                return null;
            }

            if (type.IsGenericTypeEx())
            {
                var args = type.GetGenericArgumentsEx();

                name = "";

                if (type.Namespace != "System")
                    name = type.Namespace + ".";

                name += type.Name;

                var idx = name.LastIndexOf("`");

                if (idx > 0)
                    name = name.Substring(0, idx);

                if (type.GetGenericTypeDefinition() == typeof(Nullable<>))
                {
                    name = "{0}?".Args(GetTypeName(args[0]));
                }
                else
                {
                    name = string.Format("{0}<{1}>",
                        name,
                        args.Select(GetTypeName).Aggregate("", (s,t) => s + "," + t, p => p.TrimStart(',')));
                }

                _typeNames[type] = name;

                return name;
            }

            if (type.Namespace == "System")
                return type.Name;

            return EncryptName(type, type.ToString(), "T");
        }
开发者ID:ili,项目名称:linq2db,代码行数:56,代码来源:ExpressionTestGenerator.cs

示例3: BuildType


//.........这里部分代码省略.........
                    ps.Length == 0 ? "" : ps.Aggregate((s,t) => s + ", " + t));
            }).ToList();

            if (ctors.Count == 1 && ctors[0].IndexOf("()") >= 0)
                ctors.Clear();

            var members = type.GetFieldsEx().Intersect(_usedMembers.OfType<FieldInfo>()).Select(f =>
            {
            #if SILVERLIGHT || NETFX_CORE
                var attrs = f.GetCustomAttributes(false).ToList();
            #else
                var attrs = f.GetCustomAttributesData();
            #endif
                return @"{0}
            public {1} {2};".Args(
                    attrs.Count > 0 ? attrs.Select(a => "\r\n\t\t" + a.ToString()).Aggregate((a1,a2) => a1 + a2) : "",
                    GetTypeName(f.FieldType),
                    EncryptName(isUserName, f.Name, "P"));
            })
            .Concat(
                type.GetPropertiesEx().Intersect(_usedMembers.OfType<PropertyInfo>()).Select(p =>
                {
            #if SILVERLIGHT || NETFX_CORE
                    var attrs = p.GetCustomAttributes(false).ToList();
            #else
                    var attrs = p.GetCustomAttributesData();
            #endif
                    return string.Format(@"{0}
            {3}{1} {2} {{ get; set; }}",
                        attrs.Count > 0 ? attrs.Select(a => "\r\n\t\t" + a.ToString()).Aggregate((a1,a2) => a1 + a2) : "",
                        GetTypeName(p.PropertyType),
                        EncryptName(isUserName, p.Name, "P"),
                        type.IsInterfaceEx() ? "" : "public ");
                }))
            .Concat(
                type.GetMethodsEx().Intersect(_usedMembers.OfType<MethodInfo>()).Select(m =>
                {
            #if SILVERLIGHT || NETFX_CORE
                    var attrs = m.GetCustomAttributes(false).ToList();
            #else
                    var attrs = m.GetCustomAttributesData();
            #endif
                    var ps    = m.GetParameters().Select(p => GetTypeName(p.ParameterType) + " " + EncryptName(p.Name, "p")).ToArray();
                    return string.Format(@"{0}
            {5}{4}{1} {2}({3})
            {{
            throw new NotImplementedException();
            }}",
                        attrs.Count > 0 ? attrs.Select(a => "\r\n\t\t" + a.ToString()).Aggregate((a1,a2) => a1 + a2) : "",
                        GetTypeName(m.ReturnType),
                        EncryptName(isUserName, m.Name, "M"),
                        ps.Length == 0 ? "" : ps.Aggregate((s,t) => s + ", " + t),
                        m.IsStatic   ? "static "   :
                        m.IsVirtual  ? "virtual "  :
                        m.IsAbstract ? "abstract " :
                                       "",
                        type.IsInterfaceEx() ? "" : "public ");
                }))
            .ToArray();

            {
            #if SILVERLIGHT || NETFX_CORE
                var attrs = type.GetCustomAttributesEx(false).ToList();
            #else
                var attrs = type.GetCustomAttributesData();
            #endif

                _typeBuilder.AppendFormat(
                    type.IsGenericTypeEx() ?
            @"
            namespace {0}
            {{{8}
            {6}{7}{1} {2}<{3}>{5}
            {{{4}{9}
            }}
            }}
            "
            :
            @"
            namespace {0}
            {{{8}
            {6}{7}{1} {2}{5}
            {{{4}{9}
            }}
            }}
            ",
                    EncryptName(isUserName, type.Namespace, "T"),
                    type.IsInterfaceEx() ? "interface" : type.IsClassEx() ? "class" : "struct",
                    name,
                    type.IsGenericTypeEx() ? GetTypeNames(type.GetGenericArgumentsEx(), ",") : null,
                    ctors.Count == 0 ? "" : ctors.Aggregate((s,t) => s + "\r\n" + t),
                    baseClasses.Length == 0 ? "" : " : " + GetTypeNames(baseClasses),
                    type.IsPublicEx() ? "public " : "",
                    type.IsAbstractEx() && !type.IsInterfaceEx() ? "abstract " : "",
                    attrs.Count > 0 ? attrs.Select(a => "\r\n\t" + a.ToString()).Aggregate((a1,a2) => a1 + a2) : "",
                    members.Length > 0 ?
                        (ctors.Count != 0 ? "\r\n" : "") + members.Aggregate((f1,f2) => f1 + "\r\n" + f2) :
                        "");
            }
        }
开发者ID:ili,项目名称:linq2db,代码行数:101,代码来源:ExpressionTestGenerator.cs


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