Example #1
0
        private object CreateSingleton(params object[] parameters)
        {
            // Simple lock to prevent 2 different threads from
            // trying to store a singleton at the same time
            lock (locker)
            {
                // If Instance isn't null then another thread
                // already stored an instance.
                if (Instance == null)
                {
                    Instance = CtorInfo.Invoke(parameters);
                }
            }

            return(Instance);
        }
Example #2
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);
        }
 public override object MarshalNativeToManaged(IntPtr p)
 => CtorInfo.Invoke(new object[] { p, true });
Example #4
0
 private object CreateTransient(params object[] parameters)
 {
     return(CtorInfo.Invoke(parameters));
 }