コード例 #1
0
        private (object, MethodModel) runMethod(MethodInfo method, object factory, Dictionary <string, object> parameters)
        {
            var methodParams = method.GetParameters();

            object[] values = methodParams.Select(m => parameters.TryGetValue(m.Name, out object val) ?
                                                  val : MethodParam.GetDefaultValue(m.ParameterType)).ToArray();
            var model = new MethodModel {
                InstanceName = getFactoryName(factory), Name = method.Name, Parameters = values, ReturnType = method.ReturnType
            };

            return(method.Invoke(factory, values), model);
        }
コード例 #2
0
ファイル: FactoryWizard.cs プロジェクト: tzachshabtay/MonoAGS
        private (object, MethodModel) runMethod(MethodBase method, object factory, Dictionary <string, ValueModel> parameters)
        {
            var methodParams = method.GetParameters();

            ValueModel[] valueModels = methodParams.Select(m => parameters.TryGetValue(m.Name, out ValueModel val) ?
                                                           val : new ValueModel(MethodParam.GetDefaultValue(m.ParameterType), type: m.ParameterType)).ToArray();
            object[] values     = valueModels.Select(v => v.Value).ToArray();
            var      returnType = method is MethodInfo methodInfo ? methodInfo.ReturnType : null;
            var      model      = new MethodModel {
                InstanceName = FactoryProvider.GetFactoryScriptName(factory, _editor.Game), Name = method.Name, Parameters = valueModels, ReturnType = returnType
            };

            if (method is ConstructorInfo constructor)
            {
                return(constructor.Invoke(values), model);
            }
            return(method.Invoke(factory, values), model);
        }