示例#1
0
        internal static ConstructorInvoker Constructor(Type type, BindingFlags bindingFlags, ConstructorInfo ctor, Type[] parameterTypes)
        {
            bindingFlags &= FasterflectFlags.InstanceAnyDeclaredOnly;
            CtorInfo           info  = new CtorInfo(type, bindingFlags, parameterTypes);
            ConstructorInvoker value = Constructors.Get(info);

            if (value != null)
            {
                return(value);
            }
            if (ctor == null && (!type.IsValueType || parameterTypes.Length != 0))
            {
                ctor = ReflectLookup.Constructor(type, bindingFlags, parameterTypes) ?? throw new MissingMemberException(type.FullName, "ctor()");
            }
            value = (ConstructorInvoker) new CtorInvocationEmitter(type, ctor).GetDelegate();
            Constructors.Insert(info, value);
            return(value);
        }
 /// <summary>
 /// Creates a delegate which can invoke the constructor whose parameter types are <paramref name="parameterTypes" />
 /// and matching <paramref name="bindingFlags"/> on the given <paramref name="type"/>.
 /// Leave <paramref name="parameterTypes"/> empty if the constructor has no argument.
 /// </summary>
 public static ConstructorInvoker DelegateForCreateInstance(this Type type, FasterflectFlags bindingFlags,
                                                            params Type[] parameterTypes)
 {
     return(Reflect.Constructor(ReflectLookup.Constructor(type, bindingFlags, parameterTypes)));
 }
 /// <summary>
 /// Gets the constructor matching the given <paramref name="bindingFlags"/> and corresponding to the
 /// supplied <paramref name="parameterTypes"/> on the given <paramref name="type"/>.
 /// </summary>
 /// <param name="type">The type to reflect on.</param>
 /// <param name="bindingFlags">The search criteria to use when reflecting.</param>
 /// <param name="parameterTypes">The types of the constructor parameters in order.</param>
 /// <returns>The matching constructor or null if no match was found.</returns>
 public static ConstructorInfo Constructor(this Type type, FasterflectFlags bindingFlags, params Type[] parameterTypes)
 {
     return(ReflectLookup.Constructor(type, bindingFlags, parameterTypes));
 }
 /// <summary>
 /// Gets the constructor corresponding to the supplied <paramref name="parameterTypes"/> on the
 /// given <paramref name="type"/>.
 /// </summary>
 /// <param name="type">The type to reflect on.</param>
 /// <param name="parameterTypes">The types of the constructor parameters in order.</param>
 /// <returns>The matching constructor or null if no match was found.</returns>
 public static ConstructorInfo Constructor(this Type type, params Type[] parameterTypes)
 {
     return(ReflectLookup.Constructor(type, parameterTypes));
 }