예제 #1
0
 /// <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));
     }
 }
예제 #2
0
 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));
     }
 }
예제 #3
0
        public static Action <T?, TMember?>?CreateSetter <T, TMember>(this IDelegateFactory factory, string name, bool extension)
        {
            var pi = typeof(T).GetRuntimeProperty(name);

            if (pi is null)
            {
                throw new ArgumentException("Invalid name.", nameof(name));
            }

            return(factory.CreateSetter <T, TMember>(pi, extension));
        }
        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);
        }
예제 #5
0
        public MethodTypeFilter(IEnumerable <Method> source, Type delegateType, IDelegateFactory <MethodInfo> delegateFactory) : base(source)
        {
            if (delegateType == null)
            {
                throw new ArgumentNullException(nameof(delegateType));
            }
            if (!typeof(Delegate).IsAssignableFrom(delegateType))
            {
                throw new ArgumentException($"{delegateType} is not a delegate.", nameof(delegateType));
            }
            DelegateType = delegateType;

            DelegateFactory = delegateFactory ?? throw new ArgumentNullException(nameof(delegateFactory));
        }
예제 #6
0
 public Delegate CreateSynchronizedDelegate(Delegate del)
 {
     lock (delegateFactories.SyncRoot)
     {
         Type             delType = del.GetType();
         IDelegateFactory factory = delegateFactories [delType] as IDelegateFactory;
         if (factory == null)
         {
             Type t = GetDelegateFactoryType(delType);
             factory = Activator.CreateInstance(t) as IDelegateFactory;
             delegateFactories [delType] = factory;
         }
         return(factory.Create(del, this));
     }
 }
 public static void SetFactory(IDelegateFactory factory)
 {
 }
예제 #8
0
 internal DependencyStrapper(IDelegateFactory delegateFactory)
 {
     _delegateFactory = delegateFactory;
 }
예제 #9
0
 internal void Initialize()
 {
     delegateFactoryType = DelegateFactoryType.Expression;
     delegateFactory     = new ExpressionDelegateFactory();
 }