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


C# MethodInfo.GetParameters方法代码示例

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


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

示例1: drawMethodGUI

    private void drawMethodGUI( int methodIndex, FunctionCallerAttribute attribute, MethodInfo methodInfo )
    {
        GUILayout.Space( 10 );

        if( _parameterDetailsDict.Count <= methodIndex )
            _parameterDetailsDict.Add( new Dictionary<string,object>() );
        var paramDict = _parameterDetailsDict[methodIndex];

        // draw the params
        foreach( var param in methodInfo.GetParameters() )
        {
            var paramKey = param.Name;

            if( !paramDict.ContainsKey( paramKey ) )
                paramDict.Add( paramKey, param.ParameterType.IsValueType ? System.Activator.CreateInstance( param.ParameterType ) : null );

            // add any supported types that you want here
            if( param.ParameterType == typeof( int ) )
                paramDict[paramKey] = EditorGUILayout.IntField( paramKey, (int)paramDict[paramKey] );
            else if( param.ParameterType == typeof( string ) )
                paramDict[paramKey] = EditorGUILayout.TextField( paramKey, (string)paramDict[paramKey] );
        }

        if( GUILayout.Button( attribute.buttonTitle ) )
        {
            var values = new object[paramDict.Count];
            paramDict.Values.CopyTo( values, 0 );
            methodInfo.Invoke( target, values );
        }
    }
开发者ID:ZeusbaseGameWorkshop,项目名称:ZeusbaseUNITY,代码行数:30,代码来源:AbstractFunctionCallerEditor.cs

示例2: GetData

    public override IEnumerable<object[]> GetData(MethodInfo testMethod)
    {
        if (testMethod == null)
            throw new ArgumentNullException("testMethod");

        ParameterInfo[] pars = testMethod.GetParameters();
        return DataSource(FileName, QueryString, pars.Select(par => par.ParameterType).ToArray());
    }
开发者ID:Vasiliauskas,项目名称:samples.xunit,代码行数:8,代码来源:ExcelDataAttribute.cs

示例3: AddAffordance

    protected void AddAffordance(MethodInfo method, AffordanceAttribute attr)
    {
        if (method == null
            || method.ReturnType != typeof(RunStatus)
            || method.GetParameters().Length != 1
            || method.GetParameters()[0].ParameterType != typeof(Character))
            throw new ApplicationException(
                this.gameObject.name
                + ": Wrong function signature for affordance");

        // Reads the methodinfo and converts it into a pre-compiled Func<>
        // expression. This should make it cheaper to invoke at runtime.
        ParameterExpression param = ParameterExpression.Parameter(typeof(Character), "c");
        Expression invoke = Expression.Call(Expression.Constant(this), method, param);
        Func<Character, RunStatus> result =
            Expression.Lambda<Func<Character, RunStatus>>(invoke, param).Compile();

        this.registry.Add(method.Name, result);
    }
开发者ID:alerdenisov,项目名称:ADAPT,代码行数:19,代码来源:SmartObject.cs

示例4: CreateSignature

 public static string CreateSignature(MethodInfo info) {
     if (info == null) throw new Exception("Method info is null");
     string type = info.DeclaringType.Name;
     string method = info.Name;
     string retnType = info.ReturnType.Name;
     ParameterInfo[] parameters = info.GetParameters();
     string[] argumentTypes = new string[parameters.Length];
     for (int i = 0; i < parameters.Length; i++) {
         argumentTypes[i] = parameters[i].ParameterType.Name;
     }
     return CreateSignature(type, method, retnType, argumentTypes);
 }
开发者ID:weichx,项目名称:AbilitySystem,代码行数:12,代码来源:MethodPointerUtils.cs

示例5: GetMemberName

            private static string GetMemberName(MethodInfo method)
            {
                string name = string.Format("{0}.{1}", method.DeclaringType.FullName, method.Name);
                   var parameters = method.GetParameters();
                   if (parameters.Length != 0)
                   {
                   string[] parameterTypeNames = parameters.Select(param => ProcessTypeName(param.ParameterType.FullName)).ToArray();
                   name += string.Format("({0})", string.Join(",", parameterTypeNames));
                   }

                   return name;
            }
开发者ID:chandmk,项目名称:httpapi,代码行数:12,代码来源:XmlCommentDocumentationProvider.cs

示例6: VerifySetMethod

        public static void VerifySetMethod(PropertyInfo property, MethodInfo method, bool exists, bool nonPublic)
        {
            Assert.Equal(exists, method != null);
            if (exists)
            {
                Assert.Equal(MemberTypes.Method, method.MemberType);
                Assert.Equal("set_" + property.Name, method.Name);
                Assert.Equal(!nonPublic, method.IsPublic);

                Assert.Equal(typeof(void), method.ReturnType);
                Assert.Equal(new Type[] { property.PropertyType }, method.GetParameters().Select(parameter => parameter.ParameterType));
            }
        }
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:13,代码来源:PropertyInfoTests.cs

示例7: VerifyGetMethod

        public static void VerifyGetMethod(PropertyInfo property, MethodInfo method, bool exists, bool nonPublic)
        {
            Assert.Equal(exists, method != null);
            if (exists)
            {
                Assert.Equal(MemberTypes.Method, method.MemberType);
                Assert.Equal("get_" + property.Name, method.Name);
                Assert.Equal(!nonPublic, method.IsPublic);

                Assert.Equal(property.PropertyType, method.ReturnType);
                Assert.Empty(method.GetParameters());
            }
        }
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:13,代码来源:PropertyInfoTests.cs

示例8: Command

    public Command(string name)
    {
        _name = name;
        _validationMessage = "";

        _info = typeof(Commands).GetMethod(_name);
        if (_info != null) _parametersInfo = _info.GetParameters();
        #if UNITY_EDITOR
        else GameConsole.instance.writeNewMessage("[" + GetType() + "] " + _name + " command doesn't exist", Console.AlertStates.error);
        #endif

        if (_info != null) _description = setDescription("");
    }
开发者ID:Rirols,项目名称:HitsPlayJam,代码行数:13,代码来源:Commands.cs

示例9: ShouldConvertMethod

	static bool ShouldConvertMethod (MethodInfo method)
	{
		var parameters = method.GetParameters ();
		if (parameters.Length == 0)
			return false;

		if (IsParams (parameters [0]))
			return false;

		if (method.Name.StartsWith ("Try"))
			return false;

		return true;
	}
开发者ID:transformersprimeabcxyz,项目名称:mono.linq.expressions,代码行数:14,代码来源:fluentextensions-generator.cs

示例10: CanBeUsedAsAction

    public static bool CanBeUsedAsAction(MethodInfo methodInfo, bool ignoreReturnType)
    {
        if (!methodInfo.IsPublic)
            return false;
        if (!ignoreReturnType && methodInfo.ReturnType != typeof(IEnumerator<React.NodeResult>))
            return false;
        if (methodInfo.GetParameters().Length != 0)
        {
            if (methodInfo.GetCustomAttributes(typeof(React.ReactActionAttribute), true).Length == 0)
                return false;
        }

        return true;
    }
开发者ID:s76,项目名称:testAI,代码行数:14,代码来源:Reactable.cs

示例11: AddHandlerForMethodInfo

    private void AddHandlerForMethodInfo(MethodInfo m)
    {
        if (!m.IsDefined(typeof(ObserverHandlerAttribute), false))
            return;

        ParameterInfo[] ps = m.GetParameters();
        if(m.ReturnType == typeof(void) && ps.Length == 1 && ps[0].ParameterType == typeof(int))
        {
            Object target = null;
            if (!m.IsStatic)
                target = Activator.CreateInstance(m.DeclaringType);

            Observer o = (Observer)Delegate.CreateDelegate(typeof(Observer), target, m);
            CounterEvent += o;
        }
    }
开发者ID:Kadete,项目名称:ave-2013-14-sem2,代码行数:16,代码来源:ObserverWithReflection.cs

示例12: MethodicParameters

    /// <summary>
    /// Sets up the parameters.
    /// </summary>
    /// <param name="method">The method to invoke.</param>
    public MethodicParameters(MethodInfo method)
    {
        info = method.GetParameters();
        parameters = new object[info.Length];

        // Set the parameters to default values
        for (int i = 0; i < parameters.Length; i++) {
            var type = info[i].ParameterType;

            if (type.IsValueType) {
                parameters[i] = System.Activator.CreateInstance(type);
            } else if (type == typeof(string)) {
                parameters[i] = "";
            } else if (type == typeof(AnimationCurve)) {
                parameters[i] = new AnimationCurve();
            }
        }
    }
开发者ID:Optixdesigns,项目名称:homeworld,代码行数:22,代码来源:MethodicParameters.cs

示例13: AddHandlerForMethodInfo

    // NUNCA FAZER PROGRAMAÇÃO ORIENTADA À EXCEPÇÃO
    /*
    private void AddHandlerForMethodInfo(MethodInfo m) {
        try
        {
            Observer o = (Observer)Delegate.CreateDelegate(typeof(Observer), m);
            CounterEvent += o;
        }
        catch (ArgumentException e){}
    }
    */

    private void AddHandlerForMethodInfo(MethodInfo m)
    {
        ParameterInfo[] ps = m.GetParameters();
        if(m.ReturnType == typeof(void) && ps.Length == 1 && ps[0].ParameterType == typeof(int))
        {
            Object target = null;

            if (!m.IsStatic)
                target = Activator.CreateInstance(m.DeclaringType);

            // Opção 1: criar o delegate via reflexão
            // Observer o = (Observer)Delegate.CreateDelegate(typeof(Observer), target, m);

            // Opção 2: criação EXPLÍCITA do delegate para um método anónimo 
            // (resultante da Lambda) e chamada ao método via reflexão.
            Observer o = n => m.Invoke(target, new object[] { n });

            CounterEvent += o;
        }
    }
开发者ID:hmcaetano,项目名称:ave-2013-14-sem2,代码行数:32,代码来源:ObserverWithReflection.cs

示例14: GetDelegateParams

    static string GetDelegateParams(MethodInfo mi)
    {
        ParameterInfo[] infos = mi.GetParameters();
        List<string> list = new List<string>();

        for (int i = 0; i < infos.Length; i++)
        {
            string str = IsParams(infos[i]) ? "params " : "";
            string s2 = GetTypeStr(infos[i].ParameterType) + " param" + i;

            if (infos[i].ParameterType.IsByRef)
            {
                s2 = "ref " + s2;
            }

            str += s2;
            list.Add(str);
        }

        return string.Join(",", list.ToArray());
    }
开发者ID:xlwangcs,项目名称:LuaFramework_UGUI,代码行数:21,代码来源:ToLuaExport.cs

示例15: GenFunction

    static void GenFunction(MethodInfo m)
    {
        string name = GetMethodName(m);
        sb.AppendLineEx("\r\n\t[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]");
        sb.AppendFormat("\tstatic int {0}(IntPtr L)\r\n", name == "Register" ? "_Register" : name);
        sb.AppendLineEx("\t{");

        if (HasAttribute(m, typeof(UseDefinedAttribute)))
        {
            FieldInfo field = extendType.GetField(name + "Defined");
            string strfun = field.GetValue(null) as string;
            sb.AppendLineEx(strfun);
            sb.AppendLineEx("\t}");
            return;
        }

        ParameterInfo[] paramInfos = m.GetParameters();
        int offset = m.IsStatic ? 0 : 1;
        bool haveParams = HasOptionalParam(paramInfos);
        int rc = m.ReturnType == typeof(void) ? 0 : 1;

        BeginTry();

        if (!haveParams)
        {
            int count = paramInfos.Length + offset;
            sb.AppendFormat("\t\t\tToLua.CheckArgsCount(L, {0});\r\n", count);
        }
        else
        {
            sb.AppendLineEx("\t\t\tint count = LuaDLL.lua_gettop(L);");
        }

        rc += ProcessParams(m, 3, false);
        sb.AppendFormat("\t\t\treturn {0};\r\n", rc);
        EndTry();
        sb.AppendLineEx("\t}");
    }
开发者ID:xlwangcs,项目名称:LuaFramework_UGUI,代码行数:38,代码来源:ToLuaExport.cs


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