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


C# Type.FindMembers方法代码示例

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


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

示例1: FindMember

 private static MemberInfo FindMember(Type t, string name, MemberTypes types)
 {
     return t
         .FindMembers(types, BindingFlags.Instance | BindingFlags.Public, Type.FilterNameIgnoreCase, name)
         .OrderByDescending(x => x.Name == name)
         .ThenByDescending(x => x.MemberType == MemberTypes.Property)
         .FirstOrDefault();
 }
开发者ID:MetaMicrocode,项目名称:Veil,代码行数:8,代码来源:HandlebarsExpressionParser.cs

示例2: IsNativelyScrolled

 public static bool IsNativelyScrolled(Type widgettype)
 {
     MemberInfo[] infos = widgettype.FindMembers(
         MemberTypes.Event,
         BindingFlags.Instance | BindingFlags.Public,
         SignalFilter,
         "set_scroll_adjustment");
     return infos.Length > 0;
 }
开发者ID:langpavel,项目名称:LPS-old,代码行数:9,代码来源:ScrolledExpression.cs

示例3: GetMember

        /// <summary>
        /// Gets the member representing the id if one exists.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        protected MemberInfo GetMember(Type type)
        {
            var foundMembers = type.FindMembers(_memberTypes, _bindingFlags, IsMatch, null);

            if (foundMembers.Length == 0)
                return null;
            if (foundMembers.Length == 1)
                return foundMembers[0];

            //Todo: use custom exception
            throw new Exception("Too many members found matching the criteria.");
        }
开发者ID:jango2015,项目名称:MongoDB_Client_.Net,代码行数:17,代码来源:MemberFinderBase.cs

示例4: ConvertSignal

        // Everything below came from the Gtk# source:
        public static Type ConvertSignal(Type widgetType, string gladeName)
        {
            //Console.WriteLine("ConvertSignal: " + widgetType.ToString() + " " + gladeName);
            System.Reflection.MemberFilter signalFilter = new System.Reflection.MemberFilter (SignalFilter);
            System.Reflection.MemberInfo[] evnts = widgetType.
                                        FindMembers (System.Reflection.MemberTypes.Event,
                                             System.Reflection.BindingFlags.Instance
                                             | System.Reflection.BindingFlags.Static
                                             | System.Reflection.BindingFlags.Public
                                             | System.Reflection.BindingFlags.NonPublic,
                                             signalFilter, gladeName);

            return (evnts[0] as EventInfo).EventHandlerType;
        }
开发者ID:codebutler,项目名称:glade-sharp-code-generator,代码行数:15,代码来源:Util.cs

示例5: GetClrExtensions

        public static MemberInfo[] GetClrExtensions(Type type, string memberName)
        {
            if (!HasClrExtensions()) return NoExtensions;

            MemberInfo[] members = null;
            if (!_clrExtensionsMembers.TryGetValue(type, out members))
            {
                if (!IsAttributeDefined(type, Types.ClrExtensionAttribute))
                {
                    _clrExtensionsMembers.Add(type, NoExtensions);
                }
                else
                {
                    members = type.FindMembers(MemberTypes.Method, BindingFlags.Public | BindingFlags.Static, ClrExtensionFilter, memberName);
                    _clrExtensionsMembers.Add(type, members);
                }
            }
            return members ?? NoExtensions;
        }
开发者ID:radiy,项目名称:boo,代码行数:19,代码来源:MetadataUtil.cs

示例6: TypeInfo

        public TypeInfo(System.String tyName)
        {
            m_type = TypeInfo.GetType(tyName);

            if (m_type != null) {
              if (m_type.IsInterface) {
                m_members = m_type.GetMethods();
              } else {
                m_members =
                  m_type.FindMembers(
                         System.Reflection.MemberTypes.All,
                         System.Reflection.BindingFlags.DeclaredOnly |
                         System.Reflection.BindingFlags.Instance |
                         System.Reflection.BindingFlags.Public |
                         System.Reflection.BindingFlags.Static,
                         new System.Reflection.MemberFilter(myFilter),
                         null);
              }
            }
        }
开发者ID:robinp,项目名称:hugs98-plus-Sep2006,代码行数:20,代码来源:TypeInfo.cs

示例7: CreateFromType

        public static Options CreateFromType(Type type)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            //if (!Attribute.IsDefined(type, typeof(OptionsAttribute)))
            //	throw new ArgumentException("The type '" + type + "' is not marked as options");

            MemberInfo[] members = type.FindMembers(MemberTypes.Field | MemberTypes.Property,
                                                    BindingFlags.Public | BindingFlags.Instance,
                                                    FilterMember, null);

            var groups = new Dictionary<string, OptionGroup>();
            var requiredGroups = new List<string>();

            Attribute[] groupsAttrs = Attribute.GetCustomAttributes(type, typeof(OptionGroupAttribute));
            foreach (OptionGroupAttribute groupAttr in groupsAttrs) {
                OptionGroup group;
                if (!groups.TryGetValue(groupAttr.Name, out @group)) {
                    @group = new OptionGroup {IsRequired = groupAttr.IsRequired};
                    groups[groupAttr.Name] = @group;
                    if (groupAttr.IsRequired)
                        requiredGroups.Add(groupAttr.Name);
                }
            }

            var options = new Options();

            foreach (MemberInfo member in members) {
                Option option = CreateOptionFromMember(member, groups);
                if (option != null)
                    options.AddOption(option);
            }

            foreach(var entry in groups) {
                var group = entry.Value;
                options.AddOptionGroup(group);
            }

            return options;
        }
开发者ID:deveel,项目名称:deveel-cli,代码行数:41,代码来源:ReflectedOptions.cs

示例8: GetMethodGroup

        /// <summary>
        /// Gets a singleton method group from the provided type.
        /// 
        /// The provided method group will be unique based upon the methods defined, not based upon the type/name
        /// combination.  In other words calling GetMethodGroup on a base type and a derived type that introduces
        /// no new methods under a given name will result in the same method group for both types.
        /// </summary>
        public static MethodGroup GetMethodGroup(Type type, string name, BindingFlags bindingFlags, MemberFilter filter) {
            ContractUtils.RequiresNotNull(type, "type");
            ContractUtils.RequiresNotNull(name, "name");

            MemberInfo[] mems = type.FindMembers(MemberTypes.Method,
                bindingFlags,
                filter ?? delegate(MemberInfo mem, object filterCritera) {
                    return mem.Name == name;
                },
                null);

            MethodGroup res = null;
            if (mems.Length != 0) {
                MethodInfo[] methods = ArrayUtils.ConvertAll<MemberInfo, MethodInfo>(
                    mems,
                    delegate(MemberInfo x) { return (MethodInfo)x; }
                );
                res = GetMethodGroup(name, methods);
            }
            return res;
        }
开发者ID:apboyle,项目名称:ironruby,代码行数:28,代码来源:ReflectionCache.cs

示例9: FindProperty

        private static PropertyInfo FindProperty(Type type, string propertyName, Expression[] arguments, BindingFlags flags) {
            MemberInfo[] members = type.FindMembers(MemberTypes.Property, flags, Type.FilterNameIgnoreCase, propertyName);
            if (members == null || members.Length == 0)
                return null;

            PropertyInfo pi;
            var propertyInfos = members.Map(t => (PropertyInfo)t);
            int count = FindBestProperty(propertyInfos, arguments, out pi);

            if (count == 0)
                return null;
            if (count > 1)
                throw Error.PropertyWithMoreThanOneMatch(propertyName, type);
            return pi;
        }
开发者ID:sbc100,项目名称:mono,代码行数:15,代码来源:IndexExpression.cs

示例10: computeTransactionAttribute

        private ITransactionAttribute computeTransactionAttribute(MethodInfo method, Type targetType)
        {
            MethodInfo specificMethod;
            if (targetType == null)
            {
                specificMethod = method;
            }
            else
            {
                ParameterInfo[] parameters = method.GetParameters();

                ComposedCriteria searchCriteria = new ComposedCriteria();
                searchCriteria.Add(new MethodNameMatchCriteria(method.Name));
                searchCriteria.Add(new MethodParametersCountCriteria(parameters.Length));
#if NET_2_0
                searchCriteria.Add(new MethodGenericArgumentsCountCriteria(
                    method.GetGenericArguments().Length));
#endif
                searchCriteria.Add(new MethodParametersCriteria(ReflectionUtils.GetParameterTypes(parameters)));

                MemberInfo[] matchingMethods = targetType.FindMembers(
                    MemberTypes.Method,
                    BindingFlags.Instance | BindingFlags.Public,
                    new MemberFilter(new CriteriaMemberFilter().FilterMemberByCriteria),
                    searchCriteria);

                if (matchingMethods != null && matchingMethods.Length == 1)
                {
                    specificMethod = matchingMethods[0] as MethodInfo;
                }
                else
                {
                    specificMethod = method;
                }
            }

            ITransactionAttribute transactionAttribute = getTransactionAttribute(specificMethod);
            if (null != transactionAttribute)
            {
                return transactionAttribute;
            }
            else if (specificMethod != method)
            {
                transactionAttribute = getTransactionAttribute(method);
            }
            return null;
        }
开发者ID:fuadm,项目名称:spring-net,代码行数:47,代码来源:AbstractFallbackTransactionAttributeSource.cs

示例11: FindMethodOnTargetType

		/// <summary>
		/// Finds the type of the method on target.
		/// </summary>
		/// <param name="methodOnInterface">The method on interface.</param>
		/// <param name="proxyTargetType">Type of the proxy target.</param>
		/// /// <param name="checkMixins">if set to <c>true</c> will check implementation on mixins.</param>
		/// <returns></returns>
		protected MethodInfo FindMethodOnTargetType(MethodInfo methodOnInterface, Type proxyTargetType, bool checkMixins)
		{
			// The code below assumes that the target
			// class uses the same generic arguments
			// as the interface generic arguments

			MemberInfo[] members = proxyTargetType.FindMembers(MemberTypes.Method,
			                                                   BindingFlags.Public | BindingFlags.Instance,
			                                                   delegate(MemberInfo mi, object criteria)
			                                                   	{
			                                                   		if (mi.Name != criteria.ToString()) return false;

			                                                   		MethodInfo methodInfo = (MethodInfo) mi;

			                                                   		return IsEquivalentMethod(methodInfo, methodOnInterface);
			                                                   	}, methodOnInterface.Name);


			if (members.Length == 0)
			{
				// Before throwing an exception, we look for an explicit
				// interface method implementation

				MethodInfo[] privateMethods =
					MethodFinder.GetAllInstanceMethods(proxyTargetType, BindingFlags.NonPublic | BindingFlags.Instance);

				foreach(MethodInfo methodInfo in privateMethods)
				{
					// We make sure it is a method used for explicit implementation

					if (!methodInfo.IsFinal || !methodInfo.IsVirtual || !methodInfo.IsHideBySig)
					{
						continue;
					}

					if (IsEquivalentMethod(methodInfo, methodOnInterface))
					{
						throw new GeneratorException(String.Format("DynamicProxy cannot create an interface (with target) " +
						                                           "proxy for '{0}' as the target '{1}' has an explicit implementation of one of the methods exposed by the interface. " +
						                                           "The runtime prevents use from invoking the private method on the target. Method {2}",
						                                           methodOnInterface.DeclaringType.Name, methodInfo.DeclaringType.Name,
						                                           methodInfo.Name));
					}
				}
			}

			if (members.Length > 1)
			{
				throw new GeneratorException("Found more than one method on target " + proxyTargetType.FullName + " matching " +
				                             methodOnInterface.Name);
			}
			else if (members.Length == 0)
			{
				if (checkMixins && IsMixinMethod(methodOnInterface))
				{
					return FindMethodOnTargetType(methodOnInterface, method2MixinType[methodOnInterface], false);
				}
				throw new GeneratorException("Could not find a matching method on " + proxyTargetType.FullName + ". Method " + methodOnInterface.Name);
			}

			return (MethodInfo) members[0];
		}
开发者ID:pallmall,项目名称:WCell,代码行数:69,代码来源:InterfaceProxyWithTargetGenerator.cs

示例12: GetSiteMapNodeFromMvcSiteMapNodeAttribute

        /// <summary>
        /// Gets the site map node from MVC site map node attribute.
        /// </summary>
        /// <param name="attribute">IMvcSiteMapNodeAttribute to map</param>
        /// <param name="type">Type.</param>
        /// <param name="methodInfo">MethodInfo on which the IMvcSiteMapNodeAttribute is applied</param>
        /// <returns>
        /// A SiteMapNode which represents the IMvcSiteMapNodeAttribute.
        /// </returns>
        protected SiteMapNode GetSiteMapNodeFromMvcSiteMapNodeAttribute(IMvcSiteMapNodeAttribute attribute, Type type, MethodInfo methodInfo)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (methodInfo == null) // try to find Index action
            {
                var ms = type.FindMembers(MemberTypes.Method, BindingFlags.Instance | BindingFlags.Public,
                                          (mi, o) => mi != null && string.Equals(mi.Name, "Index"), null);
                foreach (MethodInfo m in ms.OfType<MethodInfo>())
                {
                    var pars = m.GetParameters();
                    if (pars.Length == 0)
                    {
                        methodInfo = m;
                        break;
                    }
                }
            }

            // Determine area (will only work if controller is defined as Assembly.<Area>.Controllers.HomeController)
            string area = "";
            if (!string.IsNullOrEmpty(attribute.AreaName))
            {
                area = attribute.AreaName;
            }
            if (string.IsNullOrEmpty(area))
            {
                var parts = type.Namespace.Split('.');
                area = parts[parts.Length - 2];

                var assemblyParts = type.Assembly.FullName.Split(',');

                if (type.Namespace == assemblyParts[0] + ".Controllers" || type.Namespace.StartsWith(area))
                {
                    // Is in default areaName...
                    area = "";
                }
            }

            // Determine controller and (index) action
            string controller = type.Name.Substring(0, type.Name.IndexOf("Controller"));
            string action = (methodInfo != null ? methodInfo.Name : null) ?? "Index";
            if (methodInfo != null) // handle custom action name
            {
                var actionNameAttribute = methodInfo.GetCustomAttributes(typeof(ActionNameAttribute), true).FirstOrDefault() as ActionNameAttribute;
                if (actionNameAttribute != null)
                {
                    action = actionNameAttribute.Name;
                }
            }

            // Generate key for node
            string key = NodeKeyGenerator.GenerateKey(
                null,
                attribute.Key,
                attribute.Url,
                attribute.Title,
                area,
                controller, action,
                attribute.Clickable);

            // Handle title and description globalization
            var explicitResourceKeys = new NameValueCollection();
            var title = attribute.Title;
            var description = attribute.Description;
            HandleResourceAttribute("title", ref title, ref explicitResourceKeys);
            HandleResourceAttribute("description", ref description, ref explicitResourceKeys);

            // Create a new SiteMap node, setting the key and url
            var siteMapNode = CreateSiteMapNode(key, explicitResourceKeys, null);

            // Set the properties on siteMapNode.
            siteMapNode.Title = title;
            siteMapNode.Description = description;
            siteMapNode.Roles = attribute.Roles;
            if (!string.IsNullOrEmpty(attribute.Route))
            {
                siteMapNode["route"] = attribute.Route;
            }
            siteMapNode["area"] = area;
            siteMapNode["controller"] = controller;
            siteMapNode["action"] = action;
            siteMapNode["dynamicNodeProvider"] = attribute.DynamicNodeProvider;
            siteMapNode["urlResolver"] = attribute.UrlResolver;
//.........这里部分代码省略.........
开发者ID:rodmjay,项目名称:MvcSiteMapProvider,代码行数:101,代码来源:DefaultSiteMapProvider.cs

示例13: MethodCountForName

 /// <summary>
 ///  Within <paramref name="type"/>, counts the number of overloads for the method with the given (case-insensitive!) <paramref name="name"/> 
 /// </summary>
 /// <param name="type">The type to be searched</param>
 /// <param name="name">the name of the method for which overloads shall be counted</param>
 /// <returns>The number of overloads for method <paramref name="name"/> within type <paramref name="type"/></returns>
 public static int MethodCountForName(Type type, string name)
 {
     AssertUtils.ArgumentNotNull(type, "type", "Type must not be null");
     AssertUtils.ArgumentNotNull(name, "name", "Method name must not be null");
     MemberInfo[] methods = type.FindMembers(
         MemberTypes.Method,
         ReflectionUtils.AllMembersCaseInsensitiveFlags,
         new MemberFilter(ReflectionUtils.MethodNameFilter),
         name);
     return methods.Length;
 }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:17,代码来源:ReflectionUtils.cs

示例14: GetTestMethodsInClass

 private static IEnumerable<MemberInfo> GetTestMethodsInClass(Type testClass)
 {
     return testClass
         .FindMembers(MemberTypes.Method, BindingFlags.Public | BindingFlags.Instance, null, null)
         .Where(s => s.IsMarkedWith<FactAttribute>());
 }
开发者ID:e-llumin-net-ltd,项目名称:VFx,代码行数:6,代码来源:TestMethodResolver.cs

示例15: GetSiteMapNodeFromMvcSiteMapNodeAttribute

        /// <summary>
        /// Gets the site map node from MVC site map node attribute.
        /// </summary>
        /// <param name="siteMap">The site map.</param>
        /// <param name="attribute">The attribute.</param>
        /// <param name="type">The type.</param>
        /// <param name="methodInfo">The method info.</param>
        /// <returns></returns>
        protected virtual ISiteMapNode GetSiteMapNodeFromMvcSiteMapNodeAttribute(ISiteMap siteMap, IMvcSiteMapNodeAttribute attribute, Type type, MethodInfo methodInfo)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (!string.IsNullOrEmpty(attribute.SiteMapCacheKey))
            {
                // Return null if the attribute doesn't apply to this cache key
                if (!this.SiteMapCacheKey.Equals(attribute.SiteMapCacheKey))
                {
                    return null;
                }
            }

            if (methodInfo == null) // try to find Index action
            {
                var ms = type.FindMembers(MemberTypes.Method, BindingFlags.Instance | BindingFlags.Public,
                                          (mi, o) => mi != null && string.Equals(mi.Name, "Index"), null);
                foreach (MethodInfo m in ms.OfType<MethodInfo>())
                {
                    var pars = m.GetParameters();
                    if (pars.Length == 0)
                    {
                        methodInfo = m;
                        break;
                    }
                }
            }

            string area = "";
            if (!string.IsNullOrEmpty(attribute.AreaName))
            {
                area = attribute.AreaName;
            }
            if (string.IsNullOrEmpty(area) && !string.IsNullOrEmpty(attribute.Area))
            {
                area = attribute.Area;
            }
            // Determine area (will only work if controller is defined as [<Anything>.]Areas.<Area>.Controllers.<AnyController>)
            if (string.IsNullOrEmpty(area))
            {
                var m = Regex.Match(type.Namespace, @"(?:[^\.]+\.|\s+|^)Areas\.(?<areaName>[^\.]+)\.Controllers");
                if (m.Success)
                {
                    area = m.Groups["areaName"].Value;
                }
            }

            // Determine controller and (index) action
            string controller = type.Name.Substring(0, type.Name.IndexOf("Controller"));
            string action = (methodInfo != null ? methodInfo.Name : null) ?? "Index";
            if (methodInfo != null)
            {
                // handle ActionNameAttribute
                var actionNameAttribute = methodInfo.GetCustomAttributes(typeof(ActionNameAttribute), true).FirstOrDefault() as ActionNameAttribute;
                if (actionNameAttribute != null)
                {
                    action = actionNameAttribute.Name;
                }
            }

            string httpMethod = string.IsNullOrEmpty(attribute.HttpMethod) ? HttpVerbs.Get.ToString().ToUpperInvariant() : attribute.HttpMethod.ToUpperInvariant();

            // Handle title
            var title = attribute.Title;

            // Handle implicit resources
            var implicitResourceKey = attribute.ResourceKey;

            // Generate key for node
            string key = nodeKeyGenerator.GenerateKey(
                null,
                attribute.Key,
                "",
                title,
                area,
                controller, action, httpMethod,
                attribute.Clickable);

            var siteMapNode = siteMapNodeFactory.Create(siteMap, key, implicitResourceKey);

            // Assign defaults
            siteMapNode.Title = title;
            siteMapNode.Description = attribute.Description;
            siteMapNode.Attributes.AddRange(attribute.Attributes, false);
            siteMapNode.Roles.AddRange(attribute.Roles);
//.........这里部分代码省略.........
开发者ID:agrynco,项目名称:MvcSiteMapProvider,代码行数:101,代码来源:ReflectionSiteMapBuilder.cs


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