Ejemplo n.º 1
0
        private static object TryGenerateCreate(Type protocol, Actor actor, IMailbox mailbox, ProxyGenerator generator, string targetClassName, string lookupTypeName)
        {
            try
            {
                var originalProtocol = protocol;

                if(protocol.IsGenericType && !protocol.IsGenericTypeDefinition)
                {
                    protocol = protocol.GetGenericTypeDefinition();
                }

                var result = generator.GenerateFor(protocol);
                var input = new Input(
                    protocol,
                    targetClassName,
                    lookupTypeName,
                    result.Source,
                    result.SourceFile,
                    ClassLoaderFor(actor),
                    generator.Type,
                    true);

                var proxyCompiler = new DynaCompiler();
                var proxyClass = proxyCompiler.Compile(input);
                if(proxyClass != null && proxyClass.IsGenericTypeDefinition)
                {
                    proxyClass = proxyClass.MakeGenericType(originalProtocol.GetGenericArguments());
                }
                return TryCreateWithProxyClass(proxyClass, actor, mailbox);
            }
            catch (Exception e)
            {
                throw new ArgumentException($"Actor proxy {protocol.Name} not created because: {e.Message}", e);
            }
        }
Ejemplo n.º 2
0
        private static object TryGenerateCreate(Type protocol, Actor actor, IMailbox mailbox, ProxyGenerator generator, string targetClassName, string lookupTypeName)
        {
            try
            {
                var originalProtocol = protocol;

                if (protocol.IsGenericType && !protocol.IsGenericTypeDefinition)
                {
                    protocol = protocol.GetGenericTypeDefinition();
                }

                // Allows to determine if async/await keyword was used
                var asyncAwaitedMethods = actor.GetType().GetTypeInfo().ImplementedInterfaces
                                          .Select(ii => actor.GetType().GetInterfaceMap(ii))
                                          .Where(im => im.InterfaceType == originalProtocol)
                                          .SelectMany(im => im.TargetMethods)
                                          .Where(IsAsyncStateMachine)
                                          .ToArray();
                var result = generator.GenerateFor(protocol, asyncAwaitedMethods);
                var input  = new Input(
                    protocol,
                    targetClassName,
                    lookupTypeName,
                    result.Source,
                    result.SourceFile,
                    ClassLoaderFor(actor),
                    generator.Type,
                    true);

                var proxyCompiler = new DynaCompiler();
                var proxyClass    = proxyCompiler.Compile(input);
                if (proxyClass != null && proxyClass.IsGenericTypeDefinition)
                {
                    proxyClass = proxyClass.MakeGenericType(originalProtocol.GetGenericArguments());
                }

                return(TryCreateWithProxyClass(proxyClass !, actor, mailbox));
            }
            catch (Exception e)
            {
                throw new ArgumentException($"Actor proxy {protocol.Name} not created because: {e.Message}", e);
            }
        }
Ejemplo n.º 3
0
        private static object TryGenerateCreate(Type protocol, Actor actor, IMailbox mailbox, ProxyGenerator generator, string targetClassName)
        {
            try
            {
                var result = generator.GenerateFor(protocol);
                var input  = new Input(
                    protocol,
                    targetClassName,
                    result.Source,
                    result.SourceFile,
                    classLoader,
                    generator.Type,
                    true);

                var proxyClass = proxyCompiler.Compile(input);
                return(TryCreateWithProxyClass(proxyClass, actor, mailbox));
            }
            catch (Exception e)
            {
                throw new ArgumentException($"Actor proxy {protocol.Name} not created because: {e.Message}", e);
            }
        }