public FactoryImplementationOption(HasFactoryAttribute attr, AGSEditor editor)
 {
     _editor     = editor;
     _factory    = FactoryProvider.GetFactory(attr.FactoryType, editor.Game);
     _methodName = attr.MethodName;
     Name        = attr.DisplayName ?? attr.MethodName.Humanize();
 }
Example #2
0
        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);
        }