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


C# Type.GetMembers方法代码示例

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


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

示例1: Generate

        public static string Generate(Type type)
        {
            const string format = "{0}::{1}-{2}#{3}";

            if (type == null)
                throw new ArgumentNullException("type");

            var hashCode = type.GetHashCode();

            var attributes =
                type.GetMembers().SelectMany(x => x.GetCustomAttributes(true)).Concat(type.GetCustomAttributes(true));

            var nonPublicMembers = type.GetMembers(BindingFlags.NonPublic | BindingFlags.Instance);
            var statics = type.GetMembers(BindingFlags.Static | BindingFlags.Public);

            var items = type.GetMembers().Concat(attributes).Concat(nonPublicMembers).Concat(statics).ToArray();

            var typeCode = items.First().GetHashCode();
            typeCode = items.Skip(1).Aggregate(typeCode, (current, item) => current ^ item.GetHashCode());

            var asmDate = File.GetLastWriteTime(type.Assembly.Location);

            return String.Format(format, hashCode.ToString("X"), typeCode, items.Count(),
                asmDate.Ticks.ToString("X"));
        }
开发者ID:MatanShahar,项目名称:IntelliSun,代码行数:25,代码来源:SignatureStringProvider.cs

示例2: TypeDefinition

 public TypeDefinition(Type type)
     : this()
 {
     Namespace = type.Namespace;
     Name = type.Name;
     AddMembers(type.GetMembers(BindingFlags.Public | BindingFlags.Instance));
     AddMembers(type.GetMembers(BindingFlags.Public | BindingFlags.Static));
     AddMembers(type.GetMembers(BindingFlags.Public | BindingFlags.CreateInstance));
 }
开发者ID:stormleoxia,项目名称:lx,代码行数:9,代码来源:TypeDefinition.cs

示例3: TypeReflector

 internal TypeReflector(Type type)
   : base(null){
   this.defaultMembers = null;
   ArrayList memberLookupTable = new ArrayList(512);
   int count = 0;
   SimpleHashtable staticMembers = new SimpleHashtable(256);
   foreach (MemberInfo member in type.GetMembers(BindingFlags.Public|BindingFlags.Static|BindingFlags.FlattenHierarchy)){
     String name = member.Name;
     Object ob = staticMembers[name];
     if (ob == null){
       staticMembers[name] = count++; //Avoid allocating an array until needed
       memberLookupTable.Add(member);
     }else{
       int index = (int)ob;
       ob = memberLookupTable[index];
       MemberInfo firstMember = ob as MemberInfo;
       if (firstMember != null){
         MemberInfoList mems = new MemberInfoList(); //Allocate a flexarray of MemberInfo, and turn it into a fixed array when GetMember is called for this name
         mems.Add(firstMember);
         mems.Add(member);
         memberLookupTable[index] = mems;
       }else
         ((MemberInfoList)ob).Add(member);
     }
   }
   this.staticMembers = staticMembers;
   SimpleHashtable instanceMembers = new SimpleHashtable(256);
   foreach (MemberInfo member in type.GetMembers(BindingFlags.Public|BindingFlags.Instance)){
     String name = member.Name;
     Object ob = instanceMembers[name];
     if (ob == null){
       instanceMembers[name] = count++; //Avoid allocating an array until needed
       memberLookupTable.Add(member);
     }else{
       int index = (int)ob;
       ob = memberLookupTable[index];
       MemberInfo firstMember = ob as MemberInfo;
       if (firstMember != null){
         MemberInfoList mems = new MemberInfoList();
         mems.Add(firstMember);
         mems.Add(member);
         memberLookupTable[index] = mems;
       }else
         ((MemberInfoList)ob).Add(member);
     }
   }
   this.instanceMembers = instanceMembers;
   this.memberLookupTable = memberLookupTable;
   this.memberInfos = new MemberInfo[count][];
   this.type = type;
   this.implementsIReflect = null;
   this.hashCode = (uint)type.GetHashCode();
   this.next = null;
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:54,代码来源:typereflector.cs

示例4: GenerateMethod

 public static void GenerateMethod(string methodName, Type type, Lua4NetSerializer serializer, Action<List<Type>> OnGetBody)
 {
     serializer.NewLine(methodName + "(");
     List<Type> args = new List<Type>();
     if (type.IsGenericType)
         args = type.GetGenericArguments().ToList();
     else
     {
         (type.GetMembers()[0] as MethodBase).GetParameters().ToList().ForEach(pi =>
         {
             args.Add(pi.ParameterType);
         }); ;
     }
     int nNextArgIndex = 0;
     while (nNextArgIndex < args.Count)
     {
         Type arg = args[nNextArgIndex];
         serializer.Apppend(GeneratorHelper.GetTypeName(arg) + " arg" + nNextArgIndex.ToString());
         ++nNextArgIndex;
         if (nNextArgIndex <= (args.Count - 1))
             serializer.Apppend(",");
     }
     serializer.Apppend(")");
     serializer.BeginBlock("{");
     OnGetBody(args);
     serializer.EndBlock("}");
 }
开发者ID:huiguochen,项目名称:Lua4Net,代码行数:27,代码来源:GeneratorHelper.cs

示例5: CreateModuleFromClass

        private static void CreateModuleFromClass(ScriptEngine engine, Type t, string ModuleName)
        {
            var Module = engine.CreateModule(ModuleName);
            foreach (MemberInfo m in t.GetMembers(BindingFlags.Public | BindingFlags.Static)){

                if (m.MemberType == MemberTypes.Method){
                    MethodInfo method = (MethodInfo)m;
                    Module.SetVariable(m.Name, (AllFunctions)delegate(object[] input){ return method.Invoke(null, input);});
                    continue;
                }

                if (m.MemberType == MemberTypes.Property){
                    MethodInfo method = ((PropertyInfo)m).GetGetMethod();
                    Module.SetVariable(m.Name, method.Invoke(null, null));
                    continue;
                }

                if (m.MemberType == MemberTypes.Field) {
                    FieldInfo field = (FieldInfo)m;
                    Module.SetVariable(field.Name, field.GetValue(null));
                }

                Console.WriteLine("Not supported: " + m.Name + " for module: " + ModuleName);
            }
        }
开发者ID:CloneDeath,项目名称:PokemonSmash,代码行数:25,代码来源:ResourceManager.cs

示例6: AddMembers

        /// <summary>
        /// Adds all members to the node's children, grabbing the parameters
        /// for methods.
        /// </summary>
        /// <param name="treeNode"></param>
        /// <param name="type"></param>
        public static void AddMembers(this TreeNode treeNode, Type type)
        {
            // Get all members except methods
            MemberInfo[] memberInfo = type.GetMembers();
            for (int j = 0; j < memberInfo.Length; j++)
            {
                if (memberInfo[j].ReflectedType.IsPublic && memberInfo[j].MemberType != MemberTypes.Method)
                {
                    TreeNode node = treeNode.Nodes.Add(memberInfo[j].Name);
                    node.Tag = memberInfo[j].MemberType;
                }
            }

            // Get all methods
            MethodInfo[] methodInfo = type.GetMethods();
            for (int j = 0; j < methodInfo.Length; j++)
            {
                TreeNode node = treeNode.Nodes.Add(methodInfo[j].Name);
                string parms = "";

                ParameterInfo[] parameterInfo = methodInfo[j].GetParameters();
                for (int f = 0; f < parameterInfo.Length; f++)
                {
                    parms += parameterInfo[f].ParameterType + " " + parameterInfo[f].Name + ", ";
                }

                // Knock off remaining ", "
                if (parms.Length > 2)
                {
                    parms = parms.Substring(0, parms.Length - 2);
                }

                node.Tag = parms;
            }
        }
开发者ID:nayanshah,项目名称:FastSharp,代码行数:41,代码来源:TreeExtensions.cs

示例7: Initialize

        private static void Initialize(ILocalTextRegistry registry, Type type, string languageID, string prefix)
        {
            var provider = registry ?? Dependency.Resolve<ILocalTextRegistry>();
            foreach (var member in type.GetMembers(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                var fi = member as FieldInfo;
                if (fi != null &&
                    fi.FieldType == typeof(LocalText))
                {
                    var value = fi.GetValue(null) as LocalText;
                    if (value != null)
                    {
                        var initialized = value as InitializedLocalText;
                        if (initialized != null)
                        {
                            provider.Add(languageID, initialized.Key, initialized.InitialText);
                        }
                        else
                        {
                            provider.Add(languageID, prefix + fi.Name, value.Key);
                            fi.SetValue(null, new InitializedLocalText(prefix + fi.Name, value.Key));
                        }
                    }
                }
            }

            foreach (var nested in type.GetNestedTypes(BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                var name = nested.Name;
                if (name.EndsWith("_"))
                    name = name.Substring(0, name.Length - 1);

                Initialize(registry, nested, languageID, prefix + name + ".");
            }
        }
开发者ID:volkanceylan,项目名称:Serenity,代码行数:35,代码来源:NestedLocalTextRegistration.cs

示例8: GetPublicFieldsAndProperties

 public static MemberInfo[] GetPublicFieldsAndProperties(Type type)
 {
     return type
         .GetMembers(BindingFlags.Instance | BindingFlags.Public)
         .Where(mi => mi.MemberType == MemberTypes.Property || mi.MemberType == MemberTypes.Field)
         .ToArray();
 }
开发者ID:ZixiangBoy,项目名称:FAS,代码行数:7,代码来源:ReflectionUtils.cs

示例9: GetDescriptions

        /// <summary>
        ///     Retrieve the descriptions on the enum type.
        ///     Then when you pass in the enum type (e.g. Enums.UserTitles), it will retrieve the descriptions for all the
        ///     individual enums
        /// </summary>
        /// <param name="enumType">The Enumeration Type</param>
        /// <returns>A string list representing all the friendly names</returns>
        public static List<string> GetDescriptions(Type enumType)
        {
            MemberInfo[] memInfo = enumType.GetMembers(BindingFlags.Public | BindingFlags.Static)
                .Where(m => m.MemberType == MemberTypes.Field)
                .ToArray();
            var result = new List<string>();
            if (memInfo != null && memInfo.Length > 0)
            {
                foreach (MemberInfo member in memInfo)
                {
                    object[] attrs = member.GetCustomAttributes(typeof (DescriptionAttribute), false);

                    if (attrs != null && attrs.Length > 0)
                    {
                        result.Add(((DescriptionAttribute) attrs[0]).Description);
                    }
                    else
                    {
                        result.Add(member.Name);
                    }
                }
            }

            return result;
        }
开发者ID:AbdoNile,项目名称:Foundation,代码行数:32,代码来源:EnumExtensions.cs

示例10: DiscoverValidValuePaths

		private static IEnumerable<String> DiscoverValidValuePaths(Type type, int depth)
		{
			var validMembers = type.GetMembers(BindingFlagsForSearch)
				.Where(member => (member.MemberType & MemberTypesToSearch) > 0);
			foreach (var member in validMembers)
			{
				yield return member.Name;
				var childType = ExtractMemberType(member);
				Type recurseOnType = childType;

				// For system collections declare only Count 
				if (typeof(System.Collections.ICollection).IsAssignableFrom(childType)
					&& childType.Namespace.StartsWith("System.Collections"))
				{
					yield return member.Name + ".Count";
					recurseOnType = childType.IsGenericType
						? childType.GetGenericArguments().First()
						: typeof(Object);
				}
				else if (childType.IsArray)
				{
					yield return member.Name + ".Length";
					recurseOnType = childType.GetElementType();
				}

				if (recurseOnType.IsClass && depth > 1 && recurseOnType != typeof(String))
				{ //recurse:
					var childItems = DiscoverValidValuePaths(recurseOnType, depth - 1);
					foreach (var item in childItems)
					{
						yield return member.Name + "." + item;
					}
				}
			}
		}
开发者ID:nortal,项目名称:Utilities.TextTemplating,代码行数:35,代码来源:ReflectionBasedValueExtractor.cs

示例11: EnumConfiguration

 public EnumConfiguration(Type enumType)
 {
     _signed = IsSignedEnum(enumType);
     _flags = IsFlagsEnum(enumType);
     _names = enumType.GetEnumNames();
     var members = enumType.GetMembers(BindingFlags.Static | BindingFlags.Public);
     Debug.Assert(members.Length == _names.Length);
     for (int i = 0; i < members.Length; i++)
     {
         var a = members[i].GetCustomAttributes<PersistedNameAttribute>().FirstOrDefault();
         if (a != null) _names[i] = a.Name;
     }
     var undertype = enumType.GetEnumUnderlyingType();
     var enumValues = enumType.GetEnumValues();
     IEnumerable<ulong> enumValuesUlongs;
     if (undertype == typeof(int)) enumValuesUlongs = enumValues.Cast<int>().Select(i => (ulong)i);
     else if (undertype == typeof(uint)) enumValuesUlongs = enumValues.Cast<uint>().Select(i => (ulong)i);
     else if (undertype == typeof(sbyte)) enumValuesUlongs = enumValues.Cast<sbyte>().Select(i => (ulong)i);
     else if (undertype == typeof(byte)) enumValuesUlongs = enumValues.Cast<byte>().Select(i => (ulong)i);
     else if (undertype == typeof(short)) enumValuesUlongs = enumValues.Cast<short>().Select(i => (ulong)i);
     else if (undertype == typeof(ushort)) enumValuesUlongs = enumValues.Cast<ushort>().Select(i => (ulong)i);
     else if (undertype == typeof(long)) enumValuesUlongs = enumValues.Cast<long>().Select(i => (ulong)i);
     else enumValuesUlongs = enumValues.Cast<ulong>();
     _values = enumValuesUlongs.ToArray();
 }
开发者ID:Xamarui,项目名称:BTDB,代码行数:25,代码来源:EnumFieldHandler.cs

示例12: ExistingNamespaceParams

	public ExistingNamespaceParams (Type t) 
	{
	    // Populate our tables.

	    MemberInfo[] mems = t.GetMembers ();

	    for (int i = 0; i < mems.Length; i++) {
		MemberInfo mi = mems[i];

		object[] attrs = mi.GetCustomAttributes (typeof (StructureParameterAttribute), 
							 false);

		if (attrs == null || attrs.Length == 0)
		    continue;

		sparams[mi.Name] = ((StructureParameterAttribute) attrs[0]).Kind;

		if (sparams[mi.Name] == StructureParameterKind.Structure) {
		    Type stype = null;

		    if (mi is PropertyInfo)
			stype = (mi as PropertyInfo).PropertyType;
		    else if (mi is FieldInfo)
			stype = (mi as FieldInfo).FieldType;

		    structtypes[mi.Name] = new UserType (stype);
		}
	    }
	}
开发者ID:emtees,项目名称:old-code,代码行数:29,代码来源:ExistingNamespaceParams.cs

示例13: CompileType

        static SerializableType CompileType(Type type)
        {
            // at this point, type is a composite type
            object[] typeAttributes = type.GetCustomAttributes(typeof(AmqpContractAttribute), true);
            if (typeAttributes.Length != 1)
            {
                throw new NotSupportedException(type.FullName);
            }

            AmqpContractAttribute contractAttribute = (AmqpContractAttribute)typeAttributes[0];
            string descriptorName = contractAttribute.Name;
            ulong? descriptorCode = contractAttribute.InternalCode;
            if (descriptorName == null && descriptorCode == null)
            {
                descriptorName = type.FullName;
            }

            int lastOrder = 0;
            SortedList<int, SerialiableMember> memberList = new SortedList<int, SerialiableMember>();
            MemberInfo[] memberInfos = type.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            foreach (MemberInfo memberInfo in memberInfos)
            {
                if (memberInfo.DeclaringType != type ||
                    (memberInfo.MemberType != MemberTypes.Field &&
                    memberInfo.MemberType != MemberTypes.Property))
                {
                    continue;
                }

                object[] memberAttributes = memberInfo.GetCustomAttributes(typeof(AmqpMemberAttribute), true);
                if (memberAttributes.Length != 1)
                {
                    continue;
                }

                AmqpMemberAttribute attribute = (AmqpMemberAttribute)memberAttributes[0];

                SerialiableMember member = new SerialiableMember();
                member.Name = attribute.Name ?? memberInfo.Name;
                member.Order = attribute.InternalOrder ?? lastOrder;
                member.Mandatory = attribute.Mandatory;
                member.Accessor = MemberAccessor.Create(memberInfo);

                // This will recursively resolve member types
                Type memberType = memberInfo.MemberType == MemberTypes.Field ? ((FieldInfo)memberInfo).FieldType : ((PropertyInfo)memberInfo).PropertyType;
                member.Type = GetType(memberType);

                memberList.Add(member.Order, member);
                lastOrder = member.Order >= lastOrder ? member.Order + 1 : lastOrder + 1;
            }

            SerialiableMember[] members = new SerialiableMember[memberList.Count];
            for (int i = 0; i < memberList.Count; ++i)
            {
                members[i] = memberList[i];
            }

            SerializableType serializableType = SerializableType.Create(type, descriptorName, descriptorCode, members);
            return serializableType;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:60,代码来源:AmqpContractSerializer.cs

示例14: MemberNames

        private static IEnumerable<string> MemberNames(Type type, bool getFacets)
        {
            if (type == null)
            {
                yield break;
            }

            var members = type.GetMembers();

            foreach (var member in members)
            {
                if (member.MemberType == MemberTypes.Field || member.MemberType == MemberTypes.Property)
                {
                    var propertyType = type.GetProperty(member.Name).PropertyType;

                    if (typeof(IFacet).IsAssignableFrom(propertyType))
                    {
                        if (getFacets)
                        {
                            yield return member.Name;
                        }
                    }
                    else
                    {
                        if (!getFacets)
                        {
                            yield return member.Name;
                        }
                    }
                }
            }
        }
开发者ID:boro2g,项目名称:sitecore-contact-utilities,代码行数:32,代码来源:FacetReflectionUtil.cs

示例15: GetList

        /// <summary>Получить список (значение; наименование)</summary>
        /// <param name="enumType">Тип перечисления</param>
        /// <returns>Список (значение; наименование)</returns>
        public static Dictionary<int, string> GetList(Type enumType)
        {
            int index = 0;
            Dictionary<int,string> list = new Dictionary<int, string>();

            while (true)
            {
                string numberStr = index.ToString();
                object valueDescription = Enum.Parse(enumType, index.ToString(), true);
                string valueStr = valueDescription.ToString();

                if (numberStr == valueStr)
                {
                    break;
                }

                MemberInfo inf = enumType.GetMembers()[10 + index];
                dbFieldAtt attribute = Attribute.GetCustomAttribute(inf, typeof(dbFieldAtt)) as dbFieldAtt;

                if (attribute != null)
                {
                    list.Add(index++, attribute.Description);
                }
            }

            return list;
        }
开发者ID:AramisIT,项目名称:Lamps,代码行数:30,代码来源:EnumWorker.cs


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