public async Task <Type> GenerateAsync(Type serviceType, GenerateOptions options)
        {
            AssemblyName asmName;

            if (_createOptions.AssemblyNameProvider == null)
            {
                asmName = CreateAssemblyName(serviceType);
            }
            else
            {
                asmName = _createOptions.AssemblyNameProvider.GetName(serviceType, options);
            }

            IAssemblyRepository asmRepo = _createOptions.AssemblyRepository;
            Stream asmContent           = asmRepo == null ? null : await asmRepo.GetAsync(asmName);

            Assembly asm;

            if (asmContent == null)
            {
                AssemblyBuilder asmBuilder = GenerateInternal(asmName, serviceType, options);
                using (MemoryStream dll = new MemoryStream())
                {
                    await asmBuilder.SaveAsync(dll, new SaveOptions());

                    if (asmRepo != null)
                    {
                        asmContent = await asmRepo.CreateAsync(asmName);

                        try
                        {
                            dll.Position = 0;
                            await dll.CopyToAsync(asmContent);
                        }
                        finally
                        {
                            asmRepo.DisposeStream(asmContent);
                        }
                    }
                    asm = Assembly.Load(dll.GetBuffer());
                }
            }
            else
            {
                try
                {
                    using (MemoryStream dll = new MemoryStream())
                    {
                        await asmContent.CopyToAsync(dll);

                        asm = Assembly.Load(dll.GetBuffer());
                    }
                }
                finally
                {
                    asmRepo.DisposeStream(asmContent);
                }
            }
            return(asm.GetType(_typeFullName));
        }
        static AssemblyBuilder GenerateInternal(AssemblyName assemblyName, Type serviceType, GenerateOptions options)
        {
            ValidateServiceType(serviceType);

            Type[] interfaceTypes = serviceType.GetInterfaces(); new[] { serviceType }.Concat(serviceType.GetInterfaces()).ToArray();
            ArrayAdd(ref interfaceTypes, serviceType);
            ValidateInterfaces(interfaceTypes);

            (Type DeclaringType, (string Name, Type PropertyType)[] Props)[] props1 = GetPropertiesAndValidateMembers(interfaceTypes).GroupBy(x => x.DeclaringType).Select(x => x.First()).ToArray();
Esempio n. 3
0
 public static Type Generate <TService>(this IAggregatedServiceGenerator service, GenerateOptions options)
 => service.Generate(typeof(TService), options);
Esempio n. 4
0
 public static Task <Type> GenerateAsync <TService>(this IAggregatedServiceGenerator service, GenerateOptions options)
 => service.GenerateAsync(typeof(TService), options);
 public Type Generate(Type serviceType, GenerateOptions options)
 => _generator.Generate(serviceType, options);
 public Task <Type> GenerateAsync(Type serviceType, GenerateOptions options)
 => _generator.GenerateAsync(serviceType, options);