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


C# System.GetMethods方法代码示例

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


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

示例1: RunMethod

		private static object RunMethod(System.Type t, string methodName, object objInstance, BindingFlags eFlags, System.Type[] parameterDefinitions, object[] parameterValues)
		{
			foreach (MethodInfo m in t.GetMethods(eFlags))
			{
				if (m.Name == methodName && MethodMatchesParameterDefinitions(m, parameterDefinitions))
				{
					if (parameterDefinitions.Length == parameterValues.Length + 1)
					{
						throw new NotImplementedException("The case in which no args are passed to params parameter.");
					}
						// if only parameter is params arg, compiler collapses it. this re-expands it: 
					else if (parameterDefinitions[parameterDefinitions.Length - 1] != parameterValues[parameterValues.Length - 1].GetType())
					{
						Array unknownTypeArray = Array.CreateInstance(parameterValues[0].GetType(), parameterValues.Length);
						parameterValues.CopyTo(unknownTypeArray, 0);

						return m.Invoke(objInstance, new object[] { unknownTypeArray });
					}
					else
					{
						return m.Invoke(objInstance, parameterValues);
					}
					
				}
			}
			throw new ArgumentException("There is no method '" + methodName + "' for type '" + t.ToString() + "' which matched the parameter type list.");
		}
开发者ID:davelondon,项目名称:dontstayin,代码行数:27,代码来源:Helper.cs

示例2: ProcessStaticMethodAttributes

 private static void ProcessStaticMethodAttributes(System.Type type)
 {
   List<string> methodNames = (List<string>) null;
   List<RuntimeInitializeLoadType> loadTypes = (List<RuntimeInitializeLoadType>) null;
   MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
   for (int index = 0; index < methods.GetLength(0); ++index)
   {
     MethodInfo methodInfo = methods[index];
     if (Attribute.IsDefined((MemberInfo) methodInfo, typeof (RuntimeInitializeOnLoadMethodAttribute)))
     {
       RuntimeInitializeLoadType initializeLoadType = RuntimeInitializeLoadType.AfterSceneLoad;
       object[] customAttributes = methodInfo.GetCustomAttributes(typeof (RuntimeInitializeOnLoadMethodAttribute), false);
       if (customAttributes != null && customAttributes.Length > 0)
         initializeLoadType = ((RuntimeInitializeOnLoadMethodAttribute) customAttributes[0]).loadType;
       if (methodNames == null)
       {
         methodNames = new List<string>();
         loadTypes = new List<RuntimeInitializeLoadType>();
       }
       methodNames.Add(methodInfo.Name);
       loadTypes.Add(initializeLoadType);
     }
     if (Attribute.IsDefined((MemberInfo) methodInfo, typeof (InitializeOnLoadMethodAttribute)))
       methodInfo.Invoke((object) null, (object[]) null);
   }
   if (methodNames == null)
     return;
   EditorAssemblies.StoreRuntimeInitializeClassInfo(type, methodNames, loadTypes);
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:29,代码来源:EditorAssemblies.cs

示例3: EnumExtensionMethods

 /// <summary>
 ///  Finds all Extension methods defined by a type
 /// </summary>
 /// <param name="extending_type"></param>
 /// <returns></returns>
 public static IEnumerable<ExtensionMethodRecord> EnumExtensionMethods(System.Type extending_type)
 {
     var ext_methods = extending_type.GetMethods().Where(IsExtensionMethod).ToList();
     foreach (var ext_method in ext_methods)
     {
         var first_param = ext_method.GetParameters()[0];
         var extended_type = first_param.ParameterType;
         var rec = new ExtensionMethodRecord(extending_type, extended_type, ext_method);
         yield return rec;
     }
 }
开发者ID:saveenr,项目名称:saveenr,代码行数:16,代码来源:ReflectionUtil.cs

示例4: GetMethods

 private static MethodInfo[] GetMethods(System.Type type)
 {
     MethodInfo[] methods = type.GetMethods(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
     List<MethodInfo> list = new List<MethodInfo>();
     foreach (MethodInfo info in methods)
     {
         if (((info.GetBaseDefinition().DeclaringType != typeof(object)) & !info.IsSpecialName) && !info.IsAbstract)
         {
             list.Add(info);
         }
     }
     return list.ToArray();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:ObjectDataSourceChooseMethodsPanel.cs

示例5: CreateInterfaceStub

        /// <summary>
        /// Overrides all methods in the given interface type with methods that throw a <see cref="NotImplementedException"/>.
        /// </summary>
        /// <param name="interfaceType">The interface type that will be implemented by the target type.</param>
        /// <param name="type">The target type.</param>
        /// <returns>The list of stubbed methods.</returns>
        private static IEnumerable<MethodDefinition> CreateInterfaceStub(System.Type interfaceType, TypeDefinition type)
        {
            var module = type.Module;
            var overrider = new MethodOverrider();
            var methods = interfaceType.GetMethods();
            var stubbedMethods = new List<MethodDefinition>();
            foreach (var method in methods)
            {
                var newMethod = CreateMethodStub(type, module, overrider, method);
                stubbedMethods.Add(newMethod);
            }

            return stubbedMethods;
        }
开发者ID:philiplaureano,项目名称:Hiro,代码行数:20,代码来源:InterfaceStubBuilder.cs

示例6: GetTypeInterfaceGenericArguments

        public static IEnumerable<System.Type> GetTypeInterfaceGenericArguments(System.Type type, System.Type interfaceType)
        {
            System.Type[] arguments = interfaceType.GetGenericArguments();

            if (arguments != null)
            {
                return arguments;
            }

            if (interfaceType == typeof(ICollection<>))
            {
                return type.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).
                    Where(methodInfo => methodInfo.Name == "Add" && methodInfo.ParameterTypes.Length == 1).First().ParameterTypes;
            }

            if (interfaceType == typeof(IDictionary<,>))
            {
                return type.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).
                    Where(methodInfo => methodInfo.Name == "Add" && methodInfo.ParameterTypes.Length == 2).First().ParameterTypes;
            }

            throw new Granular.Exception("Can't get generic arguments for type \"{0}\" interface \"{1}\"", type.Name, interfaceType.Name);
        }
开发者ID:highzion,项目名称:Granular,代码行数:23,代码来源:Type.cs

示例7: AddOperationsFromType

 internal void AddOperationsFromType(System.Type type)
 {
     foreach (MethodInfo info in type.GetMethods(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance))
     {
         if (info.GetCustomAttributes(typeof(WebGetAttribute), true).Length != 0)
         {
             this.AddServiceOperation(info, "GET");
         }
         else if (info.GetCustomAttributes(typeof(WebInvokeAttribute), true).Length != 0)
         {
             this.AddServiceOperation(info, "POST");
         }
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:14,代码来源:BaseServiceProvider.cs

示例8: CallMethod

        public static object CallMethod(object target, System.Type type, string methodCMD)
        {
            string method_str = "";
            string parasCMD = "";
            object[] paras = null;

            method_str = methodCMD.Substring(0,methodCMD.IndexOf("("));
            parasCMD =  methodCMD.Substring(methodCMD.IndexOf("("), methodCMD.Length - methodCMD.IndexOf("("));
            parasCMD = parasCMD.Substring( 1, parasCMD.Length - 2);
            if(!parasCMD .Equals( "" )){
                if(parasCMD.Contains(",")){
                    string[] strParas = parasCMD.Split(',');
                    paras = new object[strParas.Length];
                    for (int pos = 0; pos < strParas.Length; pos++) {
                        //  TODO loop in strParas
            //					paras[pos] = int.Parse( strParas[pos] );
            //					if(strParas[pos].Contains("\"")){
            //						paras.SetValue(parasCMD.Replace("\"",""),pos);
            //					}
            //
            //					else
            //						paras.SetValue(int.Parse(strParas[pos]),pos);
                        paras.SetValue(GetParaFromString(strParas[pos]),pos);
                    }
                }else{
                    paras = new object[1];
                    paras.SetValue(GetParaFromString(parasCMD),0);

            //				if(parasCMD.Contains("\"")){
            //					parasCMD = parasCMD.Replace("\"","");
            //					paras.SetValue(parasCMD,0);
            ////					paras.SetValue(parasCMD,0);
            //				}
            //				else
            //					paras.SetValue(int.Parse(parasCMD),0);
            //				paras[0] = int.Parse( parasCMD );
                }
            }
            MethodInfo[] thods = type.GetMethods();

            //		MethodInfo method = type.GetMethod(method_str,System.Reflection.BindingFlags.);
            MethodInfo method = type.GetMethod(method_str);
            if( null == method){
                XLogger.Log(target + " not have a " + method_str + " method." );
                return null;
            }
            object returnValue = method.Invoke(target,paras);
            return returnValue;
        }
开发者ID:wuxingogo,项目名称:WuxingogoExtension,代码行数:49,代码来源:XReflectionManager.cs

示例9: GetBusinessObject

		protected object GetBusinessObject(string name, System.Type type, params object[] parameters)
		{
			object businessObjects = Session[name];
			if (businessObjects == null || (!object.ReferenceEquals(businessObjects.GetType(), type)) )
			{
				foreach (MethodInfo method in type.GetMethods())        // Looking for a method which returns Business Object of type pased in parm
				{   
					if (object.ReferenceEquals(method.ReturnType, type) && !method.IsConstructor && method.IsStatic)
					{
						bool methodMatch = false;                       // Check if parameters match.
						ParameterInfo[] methodParameters = method.GetParameters();
						if (parameters == null)                         //    no parameters
						{
							methodMatch = methodParameters.Length == 0;
						}
						else if (parameters.Length == methodParameters.Length)
						{
							methodMatch = true;                         //    compare parameters.
							for (int i = 0; i <= parameters.Length - 1; i++)
							{
								if (parameters[i] == null)
								{
									methodMatch = methodMatch && methodParameters[i].IsOptional;
								}
								else
								{
									methodMatch = methodMatch && object.ReferenceEquals(parameters[i].GetType(), methodParameters[i].ParameterType);
								}
							}
						}
						if (methodMatch)                                // Execute it, if found. It will return Business Object with data. Save it in Session storage
						{
							try
							{
								businessObjects = method.Invoke(null, parameters);
							}
							catch
							{
							}
							Session[name] = businessObjects;            // Save in Session storage
							break; 
						}
					}
				}
			}
			return businessObjects;
		}
开发者ID:nicholasceliano,项目名称:.NET-JavaScript-JSON-AJAX-nTier,代码行数:47,代码来源:CommonControl.cs

示例10: ConnectDefaultHandlers

    private static void ConnectDefaultHandlers(GType gtype, System.Type t)
    {
        foreach (MethodInfo minfo in t.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly)) {
            MethodInfo baseinfo = minfo.GetBaseDefinition ();
            if (baseinfo == minfo)
                continue;

            foreach (object attr in baseinfo.GetCustomAttributes (typeof (DefaultSignalHandlerAttribute), false)) {
                DefaultSignalHandlerAttribute sigattr = attr as DefaultSignalHandlerAttribute;
                MethodInfo connector = sigattr.Type.GetMethod (sigattr.ConnectionMethod, BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeof (GType) }, new ParameterModifier [0]);
                object[] parms = new object [1];
                parms [0] = gtype;
                connector.Invoke (null, parms);
                break;
            }
        }
    }
开发者ID:abock,项目名称:clutter-sharp,代码行数:17,代码来源:patch.cs

示例11: CreateTypeTree

		private ContainerRowModel CreateTypeTree(System.Type type)
		{
			var children = new List<RowModel>();
			object[] attrs;
			Attribute attr;
			BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
			Lazy<object> instance = null;
			if (IsConstructable(type)) {
				flags |= BindingFlags.Instance;
				instance = new Lazy<object>(() => Activator.CreateInstance(type), LazyThreadSafetyMode.ExecutionAndPublication);
			}

			foreach (MethodInfo method in type.GetMethods(flags).Where(m => IsTestMethod(m, true, true, true)))
			{
				// Create a row for this method
				attrs = method.GetCustomAttributes(true);
				attr = FindAttribute(attrs, "TestAttribute") ?? FindAttribute(attrs, "BenchmarkAttribute");
				var eea = FindAttribute(attrs, "ExpectedExceptionAttribute");
				bool isTestSet = method.IsStatic && MayBeTestSuite(method.ReturnType) && IsTestMethod(method, true, true, false);
				var utt = new UnitTestTask(method, instance, attr, eea, isTestSet);
				var row = new TaskRowModel(method.Name, TestNodeType.Test, utt, true);
				
				if (IsTestMethod(method, false, false, true)) // benchmark?
					row.BasePriority--; // Give benchmarks low priority by default

				children.Add(row);
			}

			foreach (Type nested in type.GetNestedTypes().Where(IsTestFixtureOrSuite))
				children.Add(CreateTypeTree(nested));
			
			// Create a row for this type
			var result = new ContainerRowModel(type.Name, TestNodeType.TestFixture, children);
			result.SetSummary(type.FullName);
			attrs = type.GetCustomAttributes(true);
			attr = FindAttribute(attrs, "TestFixtureAttribute");
			string description = GetPropertyValue<string>(attr, "Description", null);
			if (description != null)
				result.SetSummary(string.Format("{0} ({1})", description, type.FullName));
			return result;
		}
开发者ID:default0,项目名称:LoycCore,代码行数:41,代码来源:AssemblyScanTask.cs

示例12: GetCommandMethods

        internal static IEnumerable<System.Reflection.MethodInfo> GetCommandMethods(System.Type mytype)
        {
            var cmdsettype = typeof(VA.Scripting.CommandSet);

            if (!cmdsettype.IsAssignableFrom(mytype))
            {
                string msg = string.Format("{0} must derive from {1}", mytype.Name, cmdsettype.Name);
            }

            var methods = mytype.GetMethods().Where(m => m.IsPublic && !m.IsStatic);

            foreach (var method in methods)
            {
                if (method.Name == "ToString" || method.Name == "GetHashCode" || method.Name == "GetType" || method.Name == "Equals")
                {
                    continue;
                }

                yield return method;
            }
        }
开发者ID:firestream99,项目名称:VisioAutomation,代码行数:21,代码来源:CommandSet.cs

示例13: GetCommands

        internal static IEnumerable<Command> GetCommands(System.Type mytype)
        {
            var cmdsettype = typeof(CommandSet);

            if (!cmdsettype.IsAssignableFrom(mytype))
            {
                string msg = $"{mytype.Name} must derive from {cmdsettype.Name}";
            }

            var methods = mytype.GetMethods().Where(m => m.IsPublic && !m.IsStatic);

            foreach (var method in methods)
            {
                if (method.Name == "ToString" || method.Name == "GetHashCode" || method.Name == "GetType" || method.Name == "Equals")
                {
                    continue;
                }

                var cmd = new Command(method);
                yield return cmd;
            }
        }
开发者ID:shekharssorot2002,项目名称:VisioAutomation2.0,代码行数:22,代码来源:CommandSet.cs

示例14: FindControllerMethods

		/// <summary>
		/// 得到一个类型中,所有标记为ControllerMethod的方法
		/// </summary>
		/// <param name="type"></param>
		/// <returns></returns>
		private static ControllerInfo FindControllerMethods(System.Type type)
		{
			MethodInfo[] mis = type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

			List<ControllerMethodInfo> methodList = new List<ControllerMethodInfo>();
			MethodInfo defaultMethod = null;

			foreach (MethodInfo mi in mis)
			{
				ControllerMethodAttribute cma = AttributeHelper.GetCustomAttribute<ControllerMethodAttribute>(mi);

				if (cma != null)
				{
					ControllerMethodInfo cmi = new ControllerMethodInfo(mi, cma.ForceIgnoreParameters);

					methodList.Add(cmi);

					if (defaultMethod == null && cma.Default)
						defaultMethod = mi;
				}
			}

			return new ControllerInfo(methodList.ToArray(), defaultMethod);
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:29,代码来源:ControllerHelper.cs

示例15: GetPublicMembers

        /// <summary>
        /// Get public MethodInfos in a type.
        /// <param name="type">The type of the target object to get the methods.</param>
        /// <param name="staticMethods">If True returns only static members; otherwise returns instance members.</param>
        /// <returns>Public methods in a type.</returns>
        /// </summary>
        public static MethodInfo[] GetPublicMembers (System.Type type, bool staticMethods) {
            List<MethodInfo> methodInfos = new List<MethodInfo>();
            BindingFlags bindingFlags = staticMethods ? BindingFlags.Public | BindingFlags.Static : BindingFlags.Public | BindingFlags.Instance;

            foreach (MethodInfo method in type.GetMethods(bindingFlags)) {
                Type returnType = method.ReturnParameter.ParameterType;
                
                if (returnType == typeof(void) || FunctionUtility.IsSupported(returnType)) {
                    bool validParameters = true;

                    foreach (ParameterInfo parameter in method.GetParameters()) {
                        if (!FunctionUtility.IsSupported(parameter.ParameterType)) {
                            validParameters = false;
                            break;
                        }
                    }
                    
                    if (validParameters)
                        methodInfos.Add(method);
                }
            }

            return methodInfos.ToArray();
        }
开发者ID:xclouder,项目名称:godbattle,代码行数:30,代码来源:FunctionUtility.cs


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