public static TClient CreateServiceFromAnother <TClient, TConfig>(AmazonServiceClient originalServiceClient) where TClient : AmazonServiceClient where TConfig : ClientConfig, new()
        {
            AWSCredentials credentials = originalServiceClient.Credentials;
            TConfig        val         = originalServiceClient.CloneConfig <TConfig>();

            return(TypeFactory.GetTypeInfo(typeof(TClient)).GetConstructor(new ITypeInfo[2]
            {
                TypeFactory.GetTypeInfo(typeof(AWSCredentials)),
                TypeFactory.GetTypeInfo(val.GetType())
            }).Invoke(new object[2]
            {
                credentials,
                val
            }) as TClient);
        }
        public static TClient CreateServiceFromAssembly <TClient>(string assemblyName, string serviceClientClassName, AmazonServiceClient originalServiceClient) where TClient : class
        {
            ITypeInfo    typeInfo     = LoadServiceClientType(assemblyName, serviceClientClassName);
            ClientConfig clientConfig = CreateServiceConfig(assemblyName, serviceClientClassName.Replace("Client", "Config"));

            originalServiceClient.CloneConfig(clientConfig);
            return(typeInfo.GetConstructor(new ITypeInfo[2]
            {
                TypeFactory.GetTypeInfo(typeof(AWSCredentials)),
                TypeFactory.GetTypeInfo(clientConfig.GetType())
            }).Invoke(new object[2]
            {
                originalServiceClient.Credentials,
                clientConfig
            }) as TClient);
        }
Example #3
0
        public static TClient CreateServiceFromAnother <TClient, TConfig>(AmazonServiceClient originalServiceClient)
            where TConfig : ClientConfig, new ()
            where TClient : AmazonServiceClient
        {
            var credentials = originalServiceClient.Credentials;
            var newConfig   = originalServiceClient.CloneConfig <TConfig>();

            var newServiceClientTypeInfo = TypeFactory.GetTypeInfo(typeof(TClient));

            var constructor = newServiceClientTypeInfo.GetConstructor(new ITypeInfo[]
            {
                TypeFactory.GetTypeInfo(typeof(AWSCredentials)),
                TypeFactory.GetTypeInfo(newConfig.GetType())
            });

            var newServiceClient = constructor.Invoke(new object[] { credentials, newConfig }) as TClient;

            return(newServiceClient);
        }
        public static TClient CreateServiceFromAssembly <TClient>(string assemblyName, string serviceClientClassName, AmazonServiceClient originalServiceClient)
            where TClient : class
        {
            var serviceClientType = LoadServiceClientType(assemblyName, serviceClientClassName);

            var config = CreateServiceConfig(assemblyName, serviceClientClassName);

            originalServiceClient.CloneConfig(config);


            var constructor = serviceClientType.GetConstructor(new ITypeInfo[]
            {
                TypeFactory.GetTypeInfo(typeof(AWSCredentials)),
                TypeFactory.GetTypeInfo(config.GetType())
            });

            var newServiceClient = constructor.Invoke(new object[] { originalServiceClient.Credentials, config }) as TClient;

            return(newServiceClient);
        }