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


C# Type.GetMethod方法代码示例

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


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

示例1: GetMethodInfo

 public static MethodInfo GetMethodInfo(Type type, string methodName, Type[] argsTypes)
 {
     MethodInfo methodInfo;
     //
     string cacheKey = type.FullName + ":" + methodName;
     if (argsTypes != null)
     {
         foreach (Type argType in argsTypes)
         {
             cacheKey += ":" + argType.FullName;
         }
     }
     //
     if (methodCache.TryGetValue(cacheKey, out methodInfo))
     {
         return methodInfo;
     }
     //
     lock (Locker)
     {
         MethodInfo method = null;
         if (argsTypes != null)
             method = type.GetMethod(methodName, argsTypes);
         else
             method = type.GetMethod(methodName);
         methodCache[cacheKey] = method;
         return method;
     }
 }
开发者ID:Houfeng,项目名称:AjaxEngine,代码行数:29,代码来源:MethodFactory.cs

示例2: RegisterWithKey

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    protected override void RegisterWithKey (object regKey, Type regKeyType)
    {
      // 
      // Unified registration functionality for accepting both RegistrationAttribute.Key and RegistryKey objects.
      // 

      try
      {
        MethodInfo 
          regKeySetValue = regKeyType.GetMethod ("SetValue", new [] { typeof (string), typeof (object) }),
          regKeyClose = regKeyType.GetMethod("Close");

        if (regKeySetValue == null)
        {
          throw new InvalidOperationException ();
        }

        if (regKeyClose == null)
        {
          throw new InvalidOperationException ();
        }

        regKeySetValue.Invoke (regKey, new object [] { string.Empty, m_portSupplierType.AssemblyQualifiedName });

        regKeySetValue.Invoke (regKey, new object [] { "CLSID", m_portSupplierType.GUID.ToString ("B") });

        regKeySetValue.Invoke (regKey, new object [] { "Name", m_portSupplierName });

        regKeyClose.Invoke (regKey, null);
      }
      catch (Exception e)
      {
        LoggingUtils.HandleException (e);
      }
    }
开发者ID:ashumeow,项目名称:android-plus-plus,代码行数:39,代码来源:ProvideDebugPortSupplierAttribute.cs

示例3: FGConsole

 static FGConsole()
 {
     consoleWindowType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ConsoleWindow");
     if (consoleWindowType != null)
     {
         consoleWindowField = consoleWindowType.GetField("ms_ConsoleWindow", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
         consoleListViewField = consoleWindowType.GetField("m_ListView", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
         consoleActiveTextField = consoleWindowType.GetField("m_ActiveText", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
         consoleOnGUIMethod = consoleWindowType.GetMethod("OnGUI", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
     }
     listViewStateType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ListViewState");
     if (listViewStateType != null)
     {
         listViewStateRowField = listViewStateType.GetField("row", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
     }
     editorWindowPosField = typeof(EditorWindow).GetField("m_Pos", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
     logEntriesType = typeof(EditorWindow).Assembly.GetType("UnityEditorInternal.LogEntries");
     if (logEntriesType != null)
     {
         getEntryMethod = logEntriesType.GetMethod("GetEntryInternal", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
         startGettingEntriesMethod = logEntriesType.GetMethod("StartGettingEntries", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
         endGettingEntriesMethod = logEntriesType.GetMethod("EndGettingEntries", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
     }
     logEntryType = typeof(EditorWindow).Assembly.GetType("UnityEditorInternal.LogEntry");
     if (logEntryType != null)
     {
         logEntry = System.Activator.CreateInstance(logEntryType);
         logEntryFileField = logEntryType.GetField("file", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
         logEntryLineField = logEntryType.GetField("line", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
         logEntryInstanceIDField = logEntryType.GetField("instanceID", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
     }
 }
开发者ID:hnguyen091188,项目名称:BurstLine,代码行数:32,代码来源:FGConsole.cs

示例4: ParseLinkCommand

 public static System.Reflection.MethodInfo ParseLinkCommand(string cmdNm, string cmdArg, Type miType)
 {
     if (!string.IsNullOrEmpty(cmdArg))
         return miType.GetMethod(cmdNm, flags, null, new Type[] { typeof(System.Web.UI.Control), typeof(System.String[]) }, null);
     else
         return miType.GetMethod(cmdNm, flags, null, new Type[] { typeof(System.Web.UI.Control) }, null);
 }
开发者ID:tenshino,项目名称:RainstormStudios,代码行数:7,代码来源:LinkButtonParser.cs

示例5: CanSerialize

 public bool CanSerialize(Type type) {
   return
     ReflectionTools.HasDefaultConstructor(type) &&
     type.GetInterface(typeof(IEnumerable).FullName) != null &&
     type.GetMethod("Add") != null &&
     type.GetMethod("Add").GetParameters().Length == 1;
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:7,代码来源:EnumerableSerializer.cs

示例6: ActionServiceBehavior

        /// <summary>
        /// 
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="incomingActionMethod"></param>
        /// <param name="outgoingActionMethod"></param>
        public ActionServiceBehavior(Type provider, string incomingActionMethod, string outgoingActionMethod)
        {
            if (provider == null)
                throw new ServiceArgumentException("The provider for getting ISessionFactory object cannot be null.", "provider");

            if (string.IsNullOrEmpty(incomingActionMethod))
                throw new ServiceArgumentException("The incoming action method cannot be null.", "incomingActionMethod");

            if (string.IsNullOrEmpty(outgoingActionMethod))
                throw new ServiceArgumentException("The outgoing action method cannot be null.", "outgoingActionMethod");

            const BindingFlags flags = BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
            MethodInfo incomingMethod = provider.GetMethod(incomingActionMethod, flags);
            MethodInfo outgoingMethod = provider.GetMethod(outgoingActionMethod, flags);

            if (incomingMethod == null)
                throw new ServiceArgumentException(string.Format("No incoming method found, name method: {0}", incomingActionMethod), "incomingActionMethod");

            if (outgoingActionMethod == null)
                throw new ServiceArgumentException(string.Format("No outgoing method found, name method: {0}", outgoingActionMethod), "outgoingActionMethod");

            try
            {
                this.incomingAction = (Action) Delegate.CreateDelegate(typeof(Action), incomingMethod, true);
                this.outgoingAction = (Action) Delegate.CreateDelegate(typeof(Action), outgoingMethod, true);
            }
            catch (Exception ex)
            {
                throw new ServiceBehaviorException("An inner exception occurs when the calling instance tried to compile own action for inspectors, for details see innerException.", ex);
            }
        }
开发者ID:TheHunter,项目名称:WcfExtensions,代码行数:37,代码来源:ActionServiceBehavior.cs

示例7: CreateHandler

        private Func<Exception, IEnumerable<IResult>> CreateHandler(ActionExecutionContext context, Type targetType)
        {
            Func<Exception, IEnumerable<IResult>> handler = null;
#if SILVERLIGHT
            // you may not invoke private methods in SL
            const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
#elif WPF
            const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
#endif

            var method = targetType.GetMethod(MethodName, bindingFlags, Type.DefaultBinder, new[] { typeof(Exception) }, null)
                ?? targetType.GetMethod(MethodName, bindingFlags);

            if (method == null)
                throw new Exception(string.Format("Could not find method {0} on type {1}",
                                                  MethodName,
                                                  targetType.Name));

            var obj = method.IsStatic ? null : context.Target;
            handler = ex =>
                      {
                          var param = method.GetParameters().Any() ? new object[] { ex } : new object[0];
                          object result = method.Invoke(obj, param);

                          if (result is IResult) return new[] { result as IResult };
                          if (result is IEnumerable<IResult>) return result as IEnumerable<IResult>;

                          return new IResult[0];
                      };

            return handler;
        }
开发者ID:hispafox,项目名称:CMContrib,代码行数:32,代码来源:RescueAttribute.cs

示例8: Process

        public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) {
            IFacet facet = null;

            if (!type.IsInterface && typeof (IViewModel).IsAssignableFrom(type)) {
                MethodInfo deriveMethod = type.GetMethod("DeriveKeys", new Type[] {});
                MethodInfo populateMethod = type.GetMethod("PopulateUsingKeys", new[] {typeof (string[])});

                var toRemove = new List<MethodInfo> {deriveMethod, populateMethod};

                if (typeof (IViewModelEdit).IsAssignableFrom(type)) {
                    facet = new ViewModelEditFacetConvention(specification);
                }
                else if (typeof (IViewModelSwitchable).IsAssignableFrom(type)) {
                    MethodInfo isEditViewMethod = type.GetMethod("IsEditView");
                    toRemove.Add(isEditViewMethod);
                    facet = new ViewModelSwitchableFacetConvention(specification);
                }
                else {
                    facet = new ViewModelFacetConvention(specification);
                }
                methodRemover.RemoveMethods(toRemove.ToArray());
            }

            FacetUtils.AddFacet(facet);
        }
开发者ID:Robin--,项目名称:NakedObjectsFramework,代码行数:25,代码来源:ViewModelFacetFactory.cs

示例9: runMain

        //
#if !mono

        public void runMain(Type mainType, object main, Scanner scanner, string ansExpected, object answerType)
        {
            var input = mainType.GetMethod("createInput").Invoke(main, new object[] { scanner });


            //string ans = ( (InputFileConsumer<LostInput,string>) main).processInput(input);
            var ans = mainType.GetMethod("processInput").Invoke(main, new object[] { input });

            if ("double".Equals(answerType))
            {
                Logger.LogInfo("String [{}]", (string)ans);
                try
                {
                    double ans_d = double.Parse((string)ans, new CultureInfo("en-US"));
                    double expected_d = double.Parse(ansExpected, new CultureInfo("en-US"));
                    Assert.AreEqual(expected_d, ans_d, 0.00001);
                }
                catch (System.FormatException)
                {
                    Logger.LogInfo("ERROR [{}] [{}]", (string)ans, ansExpected);
                    Assert.IsTrue(false);
                }
            }
            else
            {
                Assert.AreEqual(ansExpected, ans);
            }

        }
开发者ID:eric7237cire,项目名称:CodeJam,代码行数:32,代码来源:TestRunner.cs

示例10: ZipTools

		static ZipTools()
		{
			try
			{
				var windowsBase = typeof (Package).Assembly;
				ZipArchive = windowsBase.GetType("MS.Internal.IO.Zip.ZipArchive");
				ZipArchive_OpenOnFile = ZipArchive.GetMethod("OpenOnFile", BindingFlags.NonPublic | BindingFlags.Static);
				ZipArchive_GetFiles = ZipArchive.GetMethod("GetFiles", BindingFlags.NonPublic | BindingFlags.Instance);
				ZipArchive_ZipIOBlockManager = ZipArchive.GetField("_blockManager", BindingFlags.NonPublic | BindingFlags.Instance);

				ZipFileInfo = windowsBase.GetType("MS.Internal.IO.Zip.ZipFileInfo");
				ZipFileInfo_GetStream = ZipFileInfo.GetMethod("GetStream", BindingFlags.NonPublic | BindingFlags.Instance);
				ZipFileInfo_Name = ZipFileInfo.GetProperty("Name", BindingFlags.NonPublic | BindingFlags.Instance);
				ZipFileInfo_FolderFlag = ZipFileInfo.GetProperty("FolderFlag", BindingFlags.NonPublic | BindingFlags.Instance);

				ZipIOBlockManager = windowsBase.GetType("MS.Internal.IO.Zip.ZipIOBlockManager");
				ZipIOBlockManager_Encoding = ZipIOBlockManager.GetField("_encoding", BindingFlags.NonPublic | BindingFlags.Instance);

				Enabled = true;
			}
			catch
			{
				Enabled = false;
			}
		}
开发者ID:CodingEric,项目名称:KMCCC,代码行数:25,代码来源:ZipTools.cs

示例11: CreateCollectionDefinition

        internal static SequenceDefinition CreateCollectionDefinition(Type type)
        {
            // IEnumerable<T> with Add(T) method
            Type itemType = type.GetGenericInterfaceType(typeof(IEnumerable<>));
            if (itemType != null)
            {
                MethodInfo addMethod = type.GetMethod("Add", new[] { itemType });
                if (addMethod != null)
                {
                    return new CollectionDefinition(type, itemType, ObjectInterfaceProvider.GetAction(addMethod));
                }
            }

            // IEumerable with Add(object) method
            if (type.CanBeCastTo(typeof(IEnumerable)))
            {
                MethodInfo addMethod = type.GetMethod("Add", new[] { typeof(object) });
                if (addMethod != null)
                {
                    return new CollectionDefinition(type, typeof(object), ObjectInterfaceProvider.GetAction(addMethod));
                }
            }

            return null;
        }
开发者ID:soxtoby,项目名称:ForSerial,代码行数:25,代码来源:CollectionDefinition.cs

示例12: CustomizationApi

        static CustomizationApi()
        {
            CustomAssembly = Assembly.GetEntryAssembly();
            CUSTOM_NAMESPACE = (from t in CustomAssembly.GetExportedTypes() where t.Name == CUSTOM_BOT_CLASS_NAME select t.Namespace).FirstOrDefault();
            if (CUSTOM_NAMESPACE == null)
                LogMessage.Exit("Could not find class " + CUSTOM_BOT_CLASS_NAME + " in the entry assembly.");
            bot_type = CustomAssembly.GetType(CUSTOM_NAMESPACE + "." + CUSTOM_BOT_CLASS_NAME);
            if (bot_type == null)
                LogMessage.Exit("Could not find class " + CUSTOM_NAMESPACE + "." + CUSTOM_BOT_CLASS_NAME + " in the entry assembly.");

            try
            {
                session_creating = (Action)Delegate.CreateDelegate(typeof(Action), bot_type.GetMethod("SessionCreating", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static));
            }
            catch
            {
                Log.Main.Warning("Method " + CUSTOM_NAMESPACE + "." + CUSTOM_BOT_CLASS_NAME + ".SessionCreating was not found.");
            }
            try
            {
                session_closing = (Action)Delegate.CreateDelegate(typeof(Action), bot_type.GetMethod("SessionClosing", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static));
            }
            catch
            {
                Log.Main.Warning("Method " + CUSTOM_NAMESPACE + "." + CUSTOM_BOT_CLASS_NAME + ".SessionClosing was not found.");
            }
            try
            {
                fill_start_input_item_queue = (Action<InputItemQueue, Type>)Delegate.CreateDelegate(typeof(Action<InputItemQueue, Type>), bot_type.GetMethod("FillStartInputItemQueue", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static));
            }
            catch
            {
                Log.Main.Warning("Method " + CUSTOM_NAMESPACE + "." + CUSTOM_BOT_CLASS_NAME + ".FillStartInputItemQueue was not found.");
            }
        }
开发者ID:sergeystoyan,项目名称:FhrCliverHost,代码行数:35,代码来源:CustomizationApi.cs

示例13: getGetter

 public MethodInfo getGetter(Type clazz, string field)
 {
     MethodInfo m = null;
     getProf.enter();
     string cacheKey = clazz.FullName.ToString() + "#get" + field;
     m = reflCache[cacheKey];
     if (m == null)
     {
         try
         {
             string name = buildMethodName("is", field);
             m = clazz.GetMethod(name);
             reflCache.Add(cacheKey, m);
         }
         catch (NoSuchMethodException e)
         {
             if (m == null)
             {
                 string name = buildMethodName("get", field);
                 m = clazz.GetMethod(name);
                 reflCache.Add(cacheKey, m);
             }
         }
     }
     getProf.exit();
     return m;
 }
开发者ID:mfender7,项目名称:ormada,代码行数:27,代码来源:DefaultReflector.cs

示例14: GetPrimitives

        public static bool GetPrimitives(Type containerType, Type type, out MethodInfo writer, out MethodInfo reader)
        {
            if (type.IsEnum)
                type = Enum.GetUnderlyingType(type);

            if (type.IsGenericType == false)
            {
                writer = containerType.GetMethod("WritePrimitive", BindingFlags.Static | BindingFlags.Public | BindingFlags.ExactBinding, null,
                    new Type[] { typeof(Stream), type }, null);

                reader = containerType.GetMethod("ReadPrimitive", BindingFlags.Static | BindingFlags.Public | BindingFlags.ExactBinding, null,
                    new Type[] { typeof(Stream), type.MakeByRefType() }, null);
            }
            else
            {
                var genType = type.GetGenericTypeDefinition();

                writer = GetGenWriter(containerType, genType);
                reader = GetGenReader(containerType, genType);
            }

            if (writer == null && reader == null)
                return false;
            else if (writer != null && reader != null)
                return true;
            else
                throw new InvalidOperationException(String.Format("Missing a {0}Primitive() for {1}",
                    reader == null ? "Read" : "Write", type.FullName));
        }
开发者ID:hxzqlh,项目名称:enode,代码行数:29,代码来源:Helpers.cs

示例15: FactoryProxy

 public FactoryProxy(Type factoryType, object target)
 {
     _factoryType = factoryType;
       _target = target;
       _create = _factoryType.GetMethod("Create");
       _deactivate = _factoryType.GetMethod("Deactivate");
 }
开发者ID:benlovell,项目名称:machine,代码行数:7,代码来源:FactoryProxy.cs


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