/// <summary> /// Adds the static method reflection taken from the specified /// <paramref name="type"/> by the <paramref name="methodName"/> /// in the <see cref="FunctionCollection{T}"/> with the /// function name, taken from real method name.</summary> /// <param name="methodName"> /// Type's method name to be imported.</param> /// <param name="type">Type object.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="type"/> is null.<br/>-or-<br/> /// <paramref name="methodName"/>is null.</exception> /// <exception cref="ArgumentException">Method with /// <paramref name="methodName"/> is not founded. /// <br/>-or-<br/>Founded method is not valid to be /// added into this <see cref="FunctionCollection{T}"/>. /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> with /// same name and the same arguments count already exist /// in the collection (overload impossible).</exception> /// <exception cref="System.Reflection.AmbiguousMatchException"> /// <paramref name="type"/> contains more than one methods /// matching the specified <paramref name="methodName"/>. /// </exception> public void Import(string methodName, Type type) { var method = FunctionFactory <T> .TryResolve(type, methodName, -1); Validator.CheckVisible(method); AddFunc(FunctionFactory <T> .FromReflection(method, null, true)); }
/// <summary> /// Adds the static method reflection /// to the <see cref="FunctionCollection{T}"/> /// with the specified function name.</summary> /// <param name="name">Function group name.</param> /// <param name="method"> /// <see cref="MethodInfo"/> instance to add.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="method"/> is null.</exception> /// <exception cref="ArgumentException"> /// <paramref name="method"/> is not valid method to /// be added to the <see cref="FunctionCollection{T}"/>. /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> with the /// same name and same arguments count already exist /// in the collection (overload impossible).</exception> public void AddStatic(string name, MethodInfo method) { if (method == null) { throw new ArgumentNullException("method"); } Validator.CheckVisible(method); AddFunc(name, FunctionFactory <T> .FromReflection(method, null, true)); }
/// <summary> /// Adds the <typeparamref name="TDelegate"/> delegate /// to the <see cref="FunctionCollection{T}"/> with the /// function name, taken from real method name.</summary> /// <typeparam name="TDelegate">Delegate type.</typeparam> /// <param name="target"> /// <typeparamref name="TDelegate"/> instance to add.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="target"/> is null.</exception> /// <exception cref="ArgumentException"> /// <typeparamref name="TDelegate"/> /// is not delegate type.<br/>-or-<br/> /// <paramref name="target"/> is not valid delegate /// to be added to the <see cref="FunctionCollection{T}"/>. /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> with the /// same name and same arguments count already exist /// in the collection (overload impossible).</exception> public void Add <TDelegate>(TDelegate target) { var delType = typeof(TDelegate); if (!typeof(Delegate).IsAssignableFrom(delType)) { throw new ArgumentException(); } AddFunc(FunctionFactory <T> .FromDelegate((Delegate)(object)target, true)); }
/// <summary> /// Adds the <typeparamref name="TDelegate"/> delegate /// to the <see cref="FunctionCollection{T}"/> /// with the specified function name.</summary> /// <typeparam name="TDelegate">Delegate type.</typeparam> /// <param name="name">Function group name.</param> /// <param name="target"> /// <typeparamref name="TDelegate"/> instance to add.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="target"/> is null.</exception> /// <exception cref="ArgumentException"> /// <typeparamref name="TDelegate"/> /// is not delegate type.<br/>-or-<br/> /// <paramref name="target"/> is not valid delegate /// to be added to the <see cref="FunctionCollection{T}"/>. /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> with the /// same name and same arguments count already exist /// in the collection (overload impossible).</exception> public void AddDel <TDelegate>(string name, TDelegate target) { Type type = typeof(TDelegate); if (!typeof(Delegate).IsAssignableFrom(type)) { throw new ArgumentException(); } Validator.CheckVisible(type); AddFunc(name, FunctionFactory <T> .FromDelegate((Delegate)(object)target, true)); }
/// <summary> /// Adds the static method reflection taken from the specified /// <paramref name="type"/> by the <paramref name="methodName"/> /// and arguments count to the <see cref="FunctionCollection{T}"/> /// with the function name, taken from real method name.</summary> /// <param name="type">Type object.</param> /// <param name="methodName">Type's method name to be imported.</param> /// <param name="parametersCount">Method parameters count.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="type"/> is null.<br/>-or-<br/> /// <paramref name="methodName"/>is null.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="parametersCount"/> is less than 0.</exception> /// <exception cref="ArgumentException"> /// Method with <paramref name="methodName"/> is not founded. /// <br/>-or-<br/>Founded method is not valid to be added /// to the <see cref="FunctionCollection{T}"/>. /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> /// with the same name and the same arguments count already /// exist in the collection (overload impossible).</exception> public void Import( string methodName, Type type, int parametersCount) { if (parametersCount < 0) { throw new ArgumentOutOfRangeException("parametersCount"); } var method = FunctionFactory <T> .TryResolve( type, methodName, parametersCount); Validator.CheckVisible(method); AddFunc(FunctionFactory <T> .FromReflection(method, null, true)); }
/// <summary> /// Adds the instance method reflection to the /// <see cref="FunctionCollection{T}"/> with the /// function name, taken from real method name.</summary> /// <param name="method"> /// <see cref="MethodInfo"/> instance to add.</param> /// <param name="target">Instance method target object.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="method"/> is null.<br/>-or-<br/> /// <paramref name="target"/> is null.</exception> /// <exception cref="ArgumentException"> /// <paramref name="method"/> is not valid method to /// be added to the <see cref="FunctionCollection{T}"/>. /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> with the /// same name and same arguments count already exist /// in the collection (overload impossible).</exception> public void AddInstance(MethodInfo method, object target) { if (method == null) { throw new ArgumentNullException("method"); } if (target == null) { throw new ArgumentNullException("target"); } Validator.CheckVisible(method); AddFunc(FunctionFactory <T> .FromReflection(method, target, true)); }
void InternalImport(Type type, BindingFlags flags) { if (type == null) { throw new ArgumentNullException("type"); } foreach (var method in type.GetMethods(flags)) { var func = FunctionFactory <T> .FromReflection(method, null, false); if (func != null) { AddFunc(func); } } }
/// <summary> /// Adds the <see cref="EvalFuncN{T}"/> delegate /// to the <see cref="FunctionCollection{T}"/> with the /// function name, taken from real method name.</summary> /// <param name="target"> /// <see cref="EvalFuncN{T}"/> instance to add.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="target"/> is null.</exception> /// <exception cref="ArgumentException"> /// <paramref name="target"/> is not valid delegate /// to be added to the <see cref="FunctionCollection{T}"/>. /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> with the /// same name and same arguments count already exist /// in the collection (overload impossible).</exception> /// <remarks>Not available on .NET CF 2.0 because /// it's impossible to resolve method name.</remarks> public void Add(EvalFuncN <T> target) { AddFunc(FunctionFactory <T> .FromDelegate(target, true)); }
/// <summary> /// Adds the <see cref="EvalFunc2{T}"/> delegate /// to the <see cref="FunctionCollection{T}"/> with the /// function name, taken from real method name.</summary> /// <param name="target"> /// <see cref="EvalFunc2{T}"/> instance to add.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="target"/> is null.</exception> /// <exception cref="ArgumentException"> /// <paramref name="target"/> is not valid delegate /// to be added to the <see cref="FunctionCollection{T}"/>. /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> with the /// same name and same arguments count already exist /// in the collection (overload impossible).</exception> /// <remarks>Not available on .NET CF 2.0 because /// it's impossible to resolve method name.</remarks> public void Add(EvalFunc2 <T> target) { AddFunc(FunctionFactory <T> .FromKnownDelegate(target, 2, true)); }
/// <summary> /// Adds the <see cref="EvalFuncN{T}"/> delegate /// to the <see cref="FunctionCollection{T}"/> /// with the specified function name.</summary> /// <param name="name">Function group name.</param> /// <param name="target"> /// <see cref="EvalFuncN{T}"/> instance to add.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="target"/> is null.</exception> /// <exception cref="ArgumentException"> /// <paramref name="target"/> is not valid delegate /// to be added to the <see cref="FunctionCollection{T}"/>. /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> with the /// same name and same arguments count already exist /// in the collection (overload impossible).</exception> public void Add(string name, EvalFuncN <T> target) { AddFunc(name, FunctionFactory <T> .FromDelegate(target, true)); }