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


C# Type.GetMethods方法代码示例

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


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

示例1: Filter

 /// <summary>
 /// Создает на основе типа фильтр
 /// </summary>
 /// <param name="lib"></param>
 /// <param name="type"></param>
 public Filter(string lib, Type type)
 {
     libname = lib;
     if (type.BaseType == typeof(AbstractFilter))
     {
         Exception fullex = new Exception("");
         ConstructorInfo ci = type.GetConstructor(System.Type.EmptyTypes);
         filter = ci.Invoke(null);
         PropertyInfo everyprop;
         everyprop = type.GetProperty("Name");
         name = (string)everyprop.GetValue(filter, null);
         everyprop = type.GetProperty("Author");
         author = (string)everyprop.GetValue(filter, null);
         everyprop = type.GetProperty("Ver");
         version = (Version)everyprop.GetValue(filter, null);
         help = type.GetMethod("Help");
         MethodInfo[] methods = type.GetMethods();
         filtrations = new List<Filtration>();
         foreach (MethodInfo mi in methods)
             if (mi.Name == "Filter")
             {
                 try
                 {
                     filtrations.Add(new Filtration(mi));
                 }
                 catch (TypeLoadException)
                 {
                     //Не добавляем фильтрацию.
                 }
             }
         if (filtrations == null) throw new TypeIncorrectException("Класс " + name + " не содержит ни одной фильтрации");
     }
     else
         throw new TypeLoadException("Класс " + type.Name + " не наследует AbstractFilter");
 }
开发者ID:verygrey,项目名称:ELPTWPF,代码行数:40,代码来源:Filter.cs

示例2: AddOperatorOverloads

 private static void AddOperatorOverloads(Type type, string methodName, Type arg1, Type arg2, List<MethodInfo> candidates)
 {
     int num = 0;
     foreach (MethodInfo info in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
     {
         ParameterInfo[] parameters = info.GetParameters();
         if (((info.Name == methodName) && (parameters.Length == 2)) && EvaluateMethod(parameters, arg1, arg2))
         {
             num++;
             if (!candidates.Contains(info))
             {
                 candidates.Add(info);
             }
         }
     }
     if ((num <= 0) && (type != typeof(object)))
     {
         type = type.BaseType;
         if (type != null)
         {
             foreach (MethodInfo info2 in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
             {
                 ParameterInfo[] infoArray3 = info2.GetParameters();
                 if (((info2.Name == methodName) && (infoArray3.Length == 2)) && (EvaluateMethod(infoArray3, arg1, arg2) && !candidates.Contains(info2)))
                 {
                     candidates.Add(info2);
                 }
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:31,代码来源:Literal.cs

示例3: LoadDelegates

        public static void LoadDelegates(Type t)
        {
            // From each method in the class, create a delegate, and get the "kind" from the attribute.
            var evaluators = from m in t.GetMethods()
                             where m.GetCustomAttributes(typeof(ExpressionAttribute), false).Any()
                             select new
                             {
                                 (m.GetCustomAttributes(typeof(ExpressionAttribute), false).Single() as ExpressionAttribute).Kind,
                                 Delegate = Delegate.CreateDelegate(typeof(Func<Expression, Value>), m) as Func<Expression, Value>
                             };

            // From each method in the class, create a delegate, and get the "kind" from the attribute.
            var executors = from m in t.GetMethods()
                            where m.GetCustomAttributes(typeof(StatementAttribute), false).Any()
                            select new
                            {
                                (m.GetCustomAttributes(typeof(StatementAttribute), false).Single() as StatementAttribute).Kind,
                                Delegate = Delegate.CreateDelegate(typeof(Action<Statement>), m) as Action<Statement>
                            };

            // Add all the expression delegates to the dictionary
            foreach (var evaluator in evaluators)
                ExpressionEvaluators.Add(evaluator.Kind, evaluator.Delegate);

            // Add all the statement delegates to the dictionary
            foreach (var executor in executors)
                StatementExecutors.Add(executor.Kind, executor.Delegate);
        }
开发者ID:MilesBoulanger,项目名称:game-creator,代码行数:28,代码来源:Delegator.cs

示例4: GetMethodList

		internal List<MethodInfo> GetMethodList(Type classType, Type firstArgumentType, Type secondArgumentType)
		{
			var allPublic = classType.GetMethods(); 
			var allStatic = classType.GetMethods(BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public);
			var result = new List<MethodInfo> ().Union (allPublic).Union (allStatic);
			result = result.Where (info => !info.ContainsGenericParameters);
			result = result.Where (info =>
			{
				var methodParams = info.GetParameters ();
				if (methodParams.Length == 0) return true;
				if (firstArgumentType!=null && methodParams.Length == 1)
				{
					if (methodParams[0].ParameterType.IsAssignableFrom(firstArgumentType) || methodParams[0].ParameterType.IsAssignableFrom(typeof(GameObject)))
						return true;

				}
				if (firstArgumentType != null && secondArgumentType!=null && methodParams.Length == 2)
				{
					if ((methodParams[0].ParameterType.IsAssignableFrom(firstArgumentType)
						&& methodParams[1].ParameterType.IsAssignableFrom(secondArgumentType))
						||
						(methodParams[0].ParameterType.IsAssignableFrom(typeof(GameObject))
						&& methodParams[1].ParameterType.IsAssignableFrom(typeof(GameObject)))
						)
						return true;
				}
				return false;
			});

			return result.ToList ();
		}
开发者ID:eyalzur,项目名称:CodeSamplesPublic,代码行数:31,代码来源:ScriptSelector.cs

示例5: TemplateWrapper

		public TemplateWrapper(string templateName)
		{
			this.templateName = templateName;

			type = (from t in Assembly.GetCallingAssembly().GetTypes()
			        where t.Name == templateName
			        select t).FirstOrDefault();
			if (type == null)
				throw new ArgumentException("Could not find template " + templateName);

			sessionProperty = (from p in type.GetProperties()
			                   where p.Name == "Session"
			                   select p).FirstOrDefault();
			if (sessionProperty == null)
				throw new ArgumentException("Invalid template " + templateName
				                            + " : it must have a property called Session");

			transformText = (from m in type.GetMethods()
			                 where m.Name == "TransformText"
			                 select m).FirstOrDefault();
			if (transformText == null)
				throw new ArgumentException("Invalid template " + templateName
				                            + " : it must have a method called TransformText");

			initialize = (from m in type.GetMethods()
			              where m.Name == "Initialize"
			              select m).FirstOrDefault();
			if (initialize == null)
				throw new ArgumentException("Invalid template " + templateName
				                            + " : it must have a method called Initialize");
		}
开发者ID:pescuma,项目名称:modelsharp,代码行数:31,代码来源:TemplateWrapper.cs

示例6: STClass

        private STClass(Type type, string name)
            : this(name)
        {
            Type = type;

            if (STDebug.ClassInitialization) {
                Console.WriteLine("Initializing Smalltalk class '{0}' for .NET class '{1}'", name, type.FullName);
                Console.WriteLine("  Instance Methods");
            }

            foreach (MethodInfo method in type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) {
                if (STDebug.ClassInitialization) Console.WriteLine("   - " + method);
                var attr = STRuntimeMethodAttribute.Get(method);

                if (attr == null) continue;

                if (STDebug.ClassInitialization)
                    Console.WriteLine("  ** included as " + attr.Selector);

                MethodDictionary[STSymbol.Get(attr.Selector)] = new STRuntimeMethod(method);
            }

            if (STDebug.ClassInitialization) Console.WriteLine ("  Static methods:");
            foreach (MethodInfo method in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) {
                if (STDebug.ClassInitialization) Console.WriteLine("   - " + method);
                var attr = STRuntimeMethodAttribute.Get(method);

                if (attr == null) continue;

                if (STDebug.ClassInitialization)
                    Console.WriteLine("  ** included as (" + Name + " " + attr.Selector + ")");

                Metaclass.MethodDictionary[STSymbol.Get(attr.Selector)] = new STRuntimeMethod(method);
            }
        }
开发者ID:rezonant,项目名称:irontalk,代码行数:35,代码来源:STClass.cs

示例7: ct

        static MethodInfo ct(Type t)
        {
            var a = t.GetMethods()
                .FirstOrDefault(m => m.GetParameters().Length > 5 && m.GetParameters()
                .All(s => s.ParameterType.Name == t.GetProperties().OrderBy(p1 => p1.Name)
                .ToArray()[1].PropertyType.Name));
            if (a != null)
            {
                V = (int)(t.GetProperties().OrderBy(p1 => p1.Name).ToArray()[2].GetValue(null,null))/2-10;
                return a;
            }
            var nt = t.GetNestedTypes(BindingFlags.Instance | BindingFlags.NonPublic);
            foreach (var n in nt)
                return ct(n);
            var m1 = t.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            foreach(var m11 in m1)
            {
                return ct(m11.ReturnType);
            }
            var fl = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
            foreach (var f in fl)
                return ct(f.GetType());

            var p = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (var pl in p)
                return ct(pl.GetType());
            return null;
        }
开发者ID:RELEX-Group,项目名称:public,代码行数:28,代码来源:RELEX_NewYear_2017.cs

示例8: Process

 public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder spec) {
     var attr = type.GetCustomAttribute<NakedObjectsTypeAttribute>();
     if (attr == null) {
         RemoveExplicitlyIgnoredMembers(type, methodRemover);
     } else {
         switch (attr.ReflectionScope) {
             case ReflectOver.All:
                 RemoveExplicitlyIgnoredMembers(type, methodRemover);
             break;
             case ReflectOver.TypeOnlyNoMembers:
                 foreach (MethodInfo method in type.GetMethods()) {
                     methodRemover.RemoveMethod(method);
                 }
                 break;
             case ReflectOver.ExplicitlyIncludedMembersOnly:
                 foreach (MethodInfo method in type.GetMethods()) {
                     if (method.GetCustomAttribute<NakedObjectsIncludeAttribute>() == null) {
                         methodRemover.RemoveMethod(method);
                     }
                 }
                 break;
             case ReflectOver.None:
                 throw new ReflectionException("Attempting to introspect a class that has been marked with NakedObjectsType with ReflectOver.None");
             default:
                 throw new ReflectionException(String.Format("Unhandled value for ReflectOver: {0}", attr.ReflectionScope));
         }
     }
 }
开发者ID:Robin--,项目名称:NakedObjectsFramework,代码行数:28,代码来源:RemoveIgnoredMethodsFacetFactory.cs

示例9: BuildHandlersMap

		private void BuildHandlersMap(Type service, Dictionary<MethodInfo, FactoryMethod> map)
		{
			if (service == null)
			{
				return;
			}

			if (service.Equals(typeof(IDisposable)))
			{
				var method = service.GetMethods()[0];
				map[method] = FactoryMethod.Dispose;
				return;
			}

			var methods = service.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
			foreach (var method in methods)
			{
				if (IsReleaseMethod(method))
				{
					map[method] = FactoryMethod.Release;
					continue;
				}
				map[method] = FactoryMethod.Resolve;
			}

			foreach (var @interface in service.GetInterfaces())
			{
				BuildHandlersMap(@interface, map);
			}
		}
开发者ID:dohansen,项目名称:Windsor,代码行数:30,代码来源:TypedFactoryCachingInspector.cs

示例10: CheckInst

		static void CheckInst (string prefix, Type inst, int a, int b)
		{
			var resA = inst.GetMethods (BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
			var resB = inst.GetMethods (BindingFlags.Public | BindingFlags.Instance);

			Assert.AreEqual (a, resA.Length, prefix + 1);
			Assert.AreEqual (b, resB.Length, prefix + 2);
		}
开发者ID:kumpera,项目名称:mono,代码行数:8,代码来源:MonoGenericClassTest.cs

示例11: EmptyAndUnknownMatches

        public static void EmptyAndUnknownMatches(Type svo, SingleValueObjectAttribute attr)
        {
            var emptyValue = svo.GetFields(BindingFlags.Static | BindingFlags.Public).SingleOrDefault(field =>
                    field.Name == "Empty" &&
                    field.IsInitOnly &&
                    field.FieldType == svo);

            var unknownValue = svo.GetFields(BindingFlags.Static | BindingFlags.Public).SingleOrDefault(field =>
                    field.Name == "Unknown" &&
                    field.IsInitOnly &&
                    field.FieldType == svo);

            var isEmptyMethod = svo.GetMethods(BindingFlags.Instance | BindingFlags.Public).SingleOrDefault(method =>
                    method.Name == "IsEmpty" &&
                    method.GetParameters().Length == 0 &&
                    method.ReturnType == typeof(Boolean));

            var isUnknownMethod = svo.GetMethods(BindingFlags.Instance | BindingFlags.Public).SingleOrDefault(method =>
                   method.Name == "IsUnknown" &&
                   method.GetParameters().Length == 0 &&
                   method.ReturnType == typeof(Boolean));

            var isEmptyOrUnknownMethod = svo.GetMethods(BindingFlags.Instance | BindingFlags.Public).SingleOrDefault(method =>
                   method.Name == "IsEmptyOrUnknown" &&
                   method.GetParameters().Length == 0 &&
                   method.ReturnType == typeof(Boolean));

            if (attr.StaticOptions.HasFlag(SingleValueStaticOptions.HasEmptyValue))
            {
                Assert.IsNotNull(emptyValue, "{0} should contain a static read-only Empty field.", svo);
                Assert.IsNotNull(isEmptyMethod, "{0} should contain a IsEmpty method.", svo);
            }
            else
            {
                Assert.IsNull(emptyValue, "{0} should not contain a static read-only Empty field.", svo);
                Assert.IsNull(isEmptyMethod, "{0} should not contain a IsEmpty method.", svo);
            }

            if (attr.StaticOptions.HasFlag(SingleValueStaticOptions.HasUnknownValue))
            {
                Assert.IsNotNull(unknownValue, "{0} should contain a static read-only Unknown field.", svo);
                Assert.IsNotNull(isUnknownMethod, "{0} should contain a IsUnknown method.", svo);
            }
            else
            {
                Assert.IsNull(unknownValue, "{0} should not contain a static read-only Unknown field.", svo);
                Assert.IsNull(isUnknownMethod, "{0} should not contain a IsUnknown method.", svo);
            }

            if (attr.StaticOptions.HasFlag(SingleValueStaticOptions.HasEmptyValue) && attr.StaticOptions.HasFlag(SingleValueStaticOptions.HasUnknownValue))
            {
                Assert.IsNotNull(isEmptyOrUnknownMethod, "{0} should contain a IsEmptyOrUnknown method.", svo);
            }
            else
            {
                Assert.IsNull(isEmptyOrUnknownMethod, "{0} should not contain a IsEmptyOrUnknown method.", svo);
            }
        }
开发者ID:helderman,项目名称:Qowaiv,代码行数:58,代码来源:SvoAssert.cs

示例12: CustomPropertyInfoHelper

        public CustomPropertyInfoHelper(string name, Type type, Type ownerType)
        {
            RaisePropertyChangedEvent = true;
            _name = name;
            _type = type;

            MethodInfo[] dd = ownerType.GetMethods();
            //set get/set methods to point to custom property
            _getMethod = ownerType.GetMethods().Single(m => m.Name == "GetPropertyValue" && !m.IsGenericMethod);
            _setMethod = ownerType.GetMethod("SetPropertyValue");
        }
开发者ID:jlVidal,项目名称:ProxyTypeHelper,代码行数:11,代码来源:ProxyPropertyInfoHelper.cs

示例13: RunTestFixture

    public TestFixtureResult RunTestFixture (Type type)
    {
      if (type == null)
        throw new ArgumentNullException ("type"); // avoid ArgumentUtility, it doesn't support partial trust ATM

      var testFixtureInstance = Activator.CreateInstance (type);

      var setupMethod = type.GetMethods ().Where (m => IsDefined (m, "NUnit.Framework.SetUpAttribute")).SingleOrDefault ();
      var tearDownMethod = type.GetMethods ().Where (m => IsDefined (m, "NUnit.Framework.TearDownAttribute")).SingleOrDefault ();
      var testMethods = type.GetMethods ().Where (m => IsDefined (m, "NUnit.Framework.TestAttribute"));

      var testResults = testMethods.Select (testMethod => RunTestMethod (testFixtureInstance, testMethod, setupMethod, tearDownMethod)).ToArray ();
      return new TestFixtureResult (type, testResults);
    }
开发者ID:natemcmaster,项目名称:Relinq,代码行数:14,代码来源:SandboxTestRunner.cs

示例14: DynamicComObjectWrapper

        public DynamicComObjectWrapper(COMRegistry registry, Type instanceType, object entry)
        {
            _registry = registry;

            if (instanceType == null)
            {
                throw new ArgumentNullException("instanceType");
            }

            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            if (!COMUtilities.IsComImport(instanceType))
            {
                throw new ArgumentException("Interface type must be an imported COM type");
            }

            if (!Marshal.IsComObject(entry))
            {
                throw new ArgumentException("Target must be a COM object");
            }

            _methods = instanceType.GetMethods().Where(m => !m.IsSpecialName).ToDictionary(m => m.Name);
            _properties = instanceType.GetProperties().ToDictionary(m => m.Name);

            _target = entry;
            _instanceType = instanceType;
        }
开发者ID:tyranid,项目名称:oleviewdotnet,代码行数:30,代码来源:DynamicComObjectWrapper.cs

示例15: Create

        internal static InternalNodeViewCustomization Create(Type nodeModelType, Type customizerType)
        {
            if (nodeModelType == null) throw new ArgumentNullException("nodeModelType");
            if (customizerType == null) throw new ArgumentNullException("customizerType");

            // get the CustomizeView method appropriate to the supplied NodeModelType
            var methodInfo = customizerType.GetMethods()
                .Where(x => x.Name == "CustomizeView")
                .Where(
                    x =>
                    {
                        var firstParm = x.GetParameters().FirstOrDefault();
                        return firstParm != null && firstParm.ParameterType == nodeModelType;
                    }).FirstOrDefault();

            // if it doesn't exist, fail early
            if (methodInfo == null)
            {
                throw new Exception(
                    "A CustomizeView method with type '" + nodeModelType.Name +
                        "' does not exist on the supplied INodeViewCustomization type.");
            }

            return new InternalNodeViewCustomization(nodeModelType, customizerType, methodInfo);
        }
开发者ID:ankushraizada,项目名称:Dynamo,代码行数:25,代码来源:InternalNodeViewCustomization.cs


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