/// <summary> /// Initializes a new instance of the <see cref="Method{TSignature}"/> class. /// </summary> internal Method(Method method, IDelegateFactory <MethodInfo> delegateFactory) : base(NotNull(method).Info, method.Instance) { if (!delegateFactory.TryCreate(Instance, Info, out @delegate !)) { string error = $"Method {method.Info} doesn't match expected signature."; throw new ArgumentException(error, nameof(method)); } }
internal Constructor(Constructor constructor, IDelegateFactory <ConstructorInfo> delegateFactory) : base(NotNull(constructor).Info, constructor.Instance) { if (!delegateFactory.TryCreate(Instance, Info, out @delegate !)) { string error = $"Constructor {constructor.Info} doesn't match expected signature."; throw new ArgumentException(error, nameof(constructor)); } }
internal static bool TryCreate <TMethodBase, TDelegate>(this IDelegateFactory <TMethodBase> delegateFactory, object?target, TMethodBase method, out TDelegate? @delegate) where TMethodBase : MethodBase where TDelegate : Delegate { if (delegateFactory == null) { throw new ArgumentNullException(nameof(delegateFactory)); } bool created = delegateFactory.TryCreate(typeof(TDelegate), target, method, out Delegate? d); @delegate = (TDelegate?)d; return(created); }