Esempio n. 1
0
        private object CreateEventProvider(
            [DynamicallyAccessedMembers(
                 DynamicallyAccessedMemberTypes.PublicConstructors
                 | DynamicallyAccessedMemberTypes.NonPublicConstructors
                 )]
            RuntimeType t
            )
        {
            // Create the event provider for the specified type.
            object EvProvider = Activator.CreateInstance(
                t,
                BindingFlags.Instance
                | BindingFlags.Public
                | BindingFlags.NonPublic
                | BindingFlags.CreateInstance,
                null,
                new object[] { this },
                null
                ) !;

            // Attempt to cache the wrapper on the object.
            if (!SetData(t, EvProvider))
            {
                // Dispose the event provider if it implements IDisposable.
                if (EvProvider is IDisposable DisposableEvProv)
                {
                    DisposableEvProv.Dispose();
                }

                // Another thead already cached the wrapper so use that one instead.
                EvProvider = GetData(t) !;
            }

            return(EvProvider);
        }
Esempio n. 2
0
        private object CreateEventProvider(RuntimeType t)
        {
            // Create the event provider for the specified type.
            object EvProvider = Activator.CreateInstance(t, Activator.ConstructorDefault | BindingFlags.NonPublic, null, new object[] { this }, null);

            // Attempt to cache the wrapper on the object.
            if (!SetData(t, EvProvider))
            {
                // Dispose the event provider if it implements IDisposable.
                if (EvProvider is IDisposable DisposableEvProv)
                {
                    DisposableEvProv.Dispose();
                }

                // Another thead already cached the wrapper so use that one instead.
                EvProvider = GetData(t);
            }

            return(EvProvider);
        }