示例#1
0
        public Dictionary <InspectorCategory, List <IProperty> > GetProperties()
        {
            var parameters = _method.GetParameters();

            if (parameters.Length == 0)
            {
                return(_props);
            }

            InspectorCategory cat = new InspectorCategory("General");

            _props[cat] = new List <IProperty>();
            foreach (var parameter in parameters)
            {
                if (_hideProperties.Contains(parameter.Name))
                {
                    continue;
                }

                _overrideDefaults.TryGetValue(parameter.Name, out var overrideDefault);
                var param = new MethodParam(parameter, null, overrideDefault);
                _props[cat].Add(param);
                ObjectTypeDescriptor.RefreshChildrenProperties(param);
            }
            return(_props);
        }
示例#2
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);
        }
示例#3
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);
        }