internal void SetParameter(ReflectionParameter p) { _function = p._function; _index = p._index; _type = p._type; _allowsNull = p._allowsNull; _name = p._name; _defaultValue = p._defaultValue; }
internal ReflectionParameter(ReflectionFunctionAbstract function, int index, Type type, bool allowsNull, string name, PhpValue defaultValue = default(PhpValue)) { Debug.Assert(function != null); Debug.Assert(index >= 0); Debug.Assert(!string.IsNullOrEmpty(name)); _function = function; _index = index; _type = type; _allowsNull = allowsNull; _name = name; _defaultValue = defaultValue; }
internal ReflectionParameter(ReflectionFunctionAbstract function, int index, ParameterInfo p, bool allowsNull, bool isVariadic, PhpValue?defaultValue = default) { Debug.Assert(function != null); Debug.Assert(index >= 0); _p = p ?? throw new ArgumentNullException(nameof(p)); _function = function; _index = index; _type = p.ParameterType; _allowsNull = allowsNull; _isVariadic = isVariadic; _name = p.Name; _defaultValue = defaultValue; }
public static List <ReflectionParameter> ResolveReflectionParameters(ReflectionFunctionAbstract function, MethodInfo[] overloads) { var parameters = new List <ReflectionParameter>(); for (int mi = 0; mi < overloads.Length; mi++) { var ps = overloads[mi].GetParameters(); var implicitps = Core.Reflection.ReflectionUtils.ImplicitParametersCount(ps); // number of implicit compiler-generated parameters int pi = implicitps; for (; pi < ps.Length; pi++) { var p = ps[pi]; var allowsNull = p.IsNullable(); var defaultValue = p.HasDefaultValue ? PhpValue.FromClr(p.RawDefaultValue) : default(PhpValue); var isVariadic = p.GetCustomAttribute <ParamArrayAttribute>() != null; int index = pi - implicitps; if (index == parameters.Count) { if (mi != 0) // we are adding and optional parameter! { if (defaultValue.IsDefault) // optional parameter has not specified default value, set void so it is treated as optional { defaultValue = PhpValue.Void; } } parameters.Add(new ReflectionParameter(function, index, p.ParameterType, allowsNull, isVariadic, p.Name, defaultValue)); } else { // update existing Debug.Assert(index < parameters.Count); parameters[index].AddOverload(p.ParameterType, allowsNull, isVariadic, p.Name, defaultValue); } } // remaining parameters have to be marked as optional for (var index = pi - implicitps; index < parameters.Count; index++) { parameters[index].SetOptional(); } } // return(parameters); }