Esempio n. 1
0
        private static ProxyGeneratorResult GenerateProxy(
            Type typeOfProxy,
            ProxyGenerationOptions options,
            IEnumerable <Type> additionalInterfacesToImplement,
            IEnumerable <object> argumentsForConstructor,
            IFakeCallProcessorProvider fakeCallProcessorProvider)
        {
            Guard.AgainstNull(typeOfProxy, nameof(typeOfProxy));
            Guard.AgainstNull(additionalInterfacesToImplement, nameof(additionalInterfacesToImplement));
            Guard.AgainstNull(fakeCallProcessorProvider, nameof(fakeCallProcessorProvider));

            if (typeOfProxy.GetTypeInfo().IsValueType)
            {
                return(GetProxyResultForValueType(typeOfProxy));
            }

            if (typeOfProxy.GetTypeInfo().IsSealed)
            {
                return(new ProxyGeneratorResult(DynamicProxyMessages.ProxyIsSealedType(typeOfProxy)));
            }

            GuardAgainstConstructorArgumentsForInterfaceType(typeOfProxy, argumentsForConstructor);

            return(CreateProxyGeneratorResult(typeOfProxy, options, additionalInterfacesToImplement, argumentsForConstructor, fakeCallProcessorProvider));
        }
        public static bool CanGenerateProxy(Type typeOfProxy, [NotNullWhen(false)] out string?failReason)
        {
            if (typeOfProxy.IsSealed)
            {
                failReason = DynamicProxyMessages.ProxyIsSealedType(typeOfProxy);
                return(false);
            }

            failReason = null;
            return(true);
        }
Esempio n. 3
0
        public static bool CanGenerateProxy(Type typeOfProxy, out string failReason)
        {
            if (typeOfProxy.GetTypeInfo().IsValueType)
            {
                failReason = DynamicProxyMessages.ProxyIsValueType(typeOfProxy);
                return(false);
            }

            if (typeOfProxy.GetTypeInfo().IsSealed)
            {
                failReason = DynamicProxyMessages.ProxyIsSealedType(typeOfProxy);
                return(false);
            }

            failReason = null;
            return(true);
        }