public void Mixin_With_InterfaceProxy_With_Target() { var generator = new ProxyGenerator(); var options = new ProxyGeneratorOptions(); options.AddMixinInstance(new PropertyChangedNotifier()); var target = new MyClass_b(); var proxy = generator.CreateInterfaceProxyWithTarget <IMyClass_b>(target, options); Assert.AreEqual(0, MyClass_b.States.Count); proxy.Title = "New title"; Assert.AreEqual(1, MyClass_b.States.Count); Assert.AreEqual(StateTypes.Notify, MyClass_b.States[0]); MyClass_b.States.Clear(); proxy.UpdateTitle(); // target.Title => out of the Proxy, cannot intercept Assert.AreEqual(0, MyClass_b.States.Count); }
protected virtual void Initialize() { var options = new ProxyGeneratorOptions(); options.AddMixinInstance(new PropertyChangedMixin()); proxies.Add(typeof(MainWindowViewModel), generator.CreateClassProxy <MainWindowViewModel>(options)); }
public void Get_Unique_Proxy_Name() { var moduleDefinition = new ModuleDefinition(); var typeDefinition = moduleDefinition.GetTypeDefinition(typeof(TypeM1), null, null); var target = typeof(TypeM1); var typeDefinition2 = moduleDefinition.GetTypeDefinition(typeof(TypeM1), target, null); var o = new ProxyGeneratorOptions(); o.AddMixinInstance(new MyMixin()); var typeDefinition3 = moduleDefinition.GetTypeDefinition(typeof(TypeM1), null, o); var typeDefinition4 = moduleDefinition.GetTypeDefinition(typeof(ITypeM1), target, null); var typeDefinition5 = moduleDefinition.GetTypeDefinition(typeof(ITypeM1), target, o); Assert.AreEqual(5, moduleDefinition.TypeDefinitions.Count); Assert.AreEqual(0, moduleDefinition.TypeDefinitions.IndexOf(typeDefinition)); Assert.AreEqual("NIntercept.Proxies.TypeM1_Proxy", typeDefinition.FullName); Assert.AreEqual(1, moduleDefinition.TypeDefinitions.IndexOf(typeDefinition2)); Assert.AreEqual("NIntercept.Proxies.TypeM1_1_Proxy", typeDefinition2.FullName); Assert.AreEqual(2, moduleDefinition.TypeDefinitions.IndexOf(typeDefinition3)); Assert.AreEqual("NIntercept.Proxies.TypeM1_2_Proxy", typeDefinition3.FullName); Assert.AreEqual(0, moduleDefinition.TypeDefinitions.IndexOf(typeDefinition4)); Assert.AreEqual("NIntercept.Proxies.ITypeM1_Proxy", typeDefinition4.FullName); Assert.AreEqual(1, moduleDefinition.TypeDefinitions.IndexOf(typeDefinition5)); Assert.AreEqual("NIntercept.Proxies.ITypeM1_1_Proxy", typeDefinition5.FullName); }
protected virtual void GenerateImpl(ProxyGeneratorOptions options) { var outputAssemblyPath = options.OutputAssemblyPath; var inputAssemblies = options.InputAssemblies; var nhibernateConfiguration = CreateNHibernateConfiguration(inputAssemblies, options); if (nhibernateConfiguration.ClassMappings.Count == 0) { FailNoClassMappings(inputAssemblies); } var proxyResult = GenerateProxies(nhibernateConfiguration, options.IntermediateProxyAssemblyPath); var staticProxyFactorySourceCode = GenerateStaticProxyFactorySourceCode(inputAssemblies[0].GetName().Version, BuildProxyTable(proxyResult.Proxies)); var result = CompileStaticProxyFactory(nhibernateConfiguration, proxyResult.Assembly, staticProxyFactorySourceCode, options.IntermediateStaticProxyFactoryAssemblyPath); if (result.Errors.HasErrors) { var errors = new StringBuilder(); foreach (var error in result.Errors) { errors.AppendLine(error.ToString()); } throw new ProxyGeneratorException(errors.ToString()); } MergeStaticProxyFactoryWithProxies(result.CompiledAssembly, proxyResult.Assembly, inputAssemblies, outputAssemblyPath); }
public void Find_IndexOf() { var moduleDefinition = new ModuleDefinition(); var typeDefinition = moduleDefinition.GetTypeDefinition(typeof(TypeM1), null, null); var target = typeof(TypeM1); var typeDefinition2 = moduleDefinition.GetTypeDefinition(typeof(TypeM1), target, null); var o = new ProxyGeneratorOptions(); o.AddMixinInstance(new MyMixin()); var typeDefinition3 = moduleDefinition.GetTypeDefinition(typeof(TypeM1), null, o); var typeDefinition4 = moduleDefinition.GetTypeDefinition(typeof(ITypeM1), target, null); var typeDefinition5 = moduleDefinition.GetTypeDefinition(typeof(ITypeM1), target, o); Assert.AreEqual(5, moduleDefinition.TypeDefinitions.Count); Assert.AreEqual(0, moduleDefinition.TypeDefinitions.IndexOf(typeDefinition)); Assert.AreEqual(1, moduleDefinition.TypeDefinitions.IndexOf(typeDefinition2)); Assert.AreEqual(2, moduleDefinition.TypeDefinitions.IndexOf(typeDefinition3)); Assert.AreEqual(0, moduleDefinition.TypeDefinitions.IndexOf(typeDefinition4)); Assert.AreEqual(1, moduleDefinition.TypeDefinitions.IndexOf(typeDefinition5)); }
public CastleProxyGeneratorOptions ValidateOptions(ProxyGeneratorOptions options) { CastleProxyGeneratorOptions castleOptions = options as CastleProxyGeneratorOptions; if (castleOptions == null) throw new ProxyGeneratorException("options must be of type {0}", typeof(CastleProxyGeneratorOptions).Name); if (string.IsNullOrEmpty(castleOptions.OutputAssemblyPath)) throw new ProxyGeneratorException("options.OutputAssemblyPath is Required"); if (!Path.IsPathRooted(castleOptions.OutputAssemblyPath)) { castleOptions.OutputAssemblyPath = Path.GetFullPath(castleOptions.OutputAssemblyPath); } if (castleOptions.InputAssemblyPaths == null || castleOptions.InputAssemblyPaths.Length == 0) throw new ProxyGeneratorException("At least one input assembly is required"); if (string.IsNullOrEmpty(castleOptions.IntermediateProxyAssemblyPath)) { castleOptions.IntermediateProxyAssemblyPath = ModuleScope.DEFAULT_FILE_NAME; } if (string.IsNullOrEmpty(castleOptions.IntermediateCastleStaticProxyFactoryAssemblyPath)) { castleOptions.IntermediateCastleStaticProxyFactoryAssemblyPath = typeof(CastleStaticProxyFactory).Name + ".dll"; } return castleOptions; }
protected virtual void CleanUpIntermediateFiles(ProxyGeneratorOptions castleOptions) { if (File.Exists(castleOptions.IntermediateProxyAssemblyPath)) { File.Delete(castleOptions.IntermediateProxyAssemblyPath); } var intermediateProxyAssemblyPdbPath = Path.ChangeExtension(castleOptions.IntermediateProxyAssemblyPath, "pdb"); if (File.Exists(intermediateProxyAssemblyPdbPath)) { File.Delete(intermediateProxyAssemblyPdbPath); } if (File.Exists(castleOptions.IntermediateStaticProxyFactoryAssemblyPath)) { File.Delete(castleOptions.IntermediateStaticProxyFactoryAssemblyPath); } var intermediateCastleStaticProxyFactoryAssemblyPdbPath = Path.ChangeExtension(castleOptions.IntermediateStaticProxyFactoryAssemblyPath, "pdb"); if (File.Exists(intermediateCastleStaticProxyFactoryAssemblyPdbPath)) { File.Delete(intermediateCastleStaticProxyFactoryAssemblyPdbPath); } }
public ProxyTypeDefinition GetTypeDefinition(Type type, Type targetType, ProxyGeneratorOptions options) { if (type is null) { throw new ArgumentNullException(nameof(type)); } lock (locker) { ProxyTypeDefinition typeDefinition = typeDefinitions.GetByType(type, targetType, options); if (typeDefinition != null) { return(typeDefinition); } if (type.IsInterface) { typeDefinition = new InterfaceProxyDefinition(this, type, targetType, options); } else { typeDefinition = new ClassProxyDefinition(this, type, targetType, options); } SetMixinDefinitions(typeDefinition, options); typeDefinitions.Add(typeDefinition); return(typeDefinition); } }
public int Execute(TextWriter error, params string[] args) { var generatorOptions = new ProxyGeneratorOptions(); if (Parser.ParseHelp(args)) { Parser.ParseArguments(args, generatorOptions); } else if (Parser.ParseArguments(args, generatorOptions) == false) { error.WriteLine(Parser.ArgumentsUsage(generatorOptions.GetType())); return(Error.InvalidArguments); } if (ProxyGenerator == null) { try { ProxyGenerator = CreateProxyGenerator(generatorOptions.Generator); } catch (Exception exc) { error.WriteLine(exc.Message); return(Error.CreateProxyGenerator); } } generatorOptions = ProxyGenerator.GetOptions(); if (generatorOptions == null) { error.WriteLine("{0}.GetOptions() returned null. Please use a different Generator.", ProxyGenerator.GetType().FullName); return(Error.InvalidGenerator); } if (Parser.ParseHelp(args)) { error.WriteLine(Parser.ArgumentsUsage(generatorOptions.GetType())); return(Error.None); } if (Parser.ParseArguments(args, generatorOptions) == false) { error.WriteLine(Parser.ArgumentsUsage(generatorOptions.GetType())); return(Error.InvalidArguments); } try { ProxyGenerator.Generate(generatorOptions); } catch (Exception exc) { error.WriteLine(exc.Message); error.WriteLine(exc.StackTrace); return(Error.Unknown); } return(Error.None); }
protected virtual void Initialize() { var options = new ProxyGeneratorOptions(); options.AdditionalCode = new ViewModelBuilder(); // create clean properties (without invocations) that raise OnPropertyChanged and CanExecuteChanged // options.InterceptableMethodBuilder = new CleanGetAndSetMethodBuilder(); proxies.Add(typeof(MainWindowViewModel), generator.CreateClassProxy <MainWindowViewModel>(options)); }
public void EmptyOptionsEquals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); var o2 = new ProxyGeneratorOptions(); Assert.AreEqual(true, comparer.Equals(o1, o2)); }
public int Execute(TextWriter error, params string[] args ) { var generatorOptions = new ProxyGeneratorOptions(); if (Parser.ParseHelp(args)) { Parser.ParseArguments(args, generatorOptions); } else if (Parser.ParseArguments(args, generatorOptions) == false) { error.WriteLine(Parser.ArgumentsUsage(generatorOptions.GetType())); return Error.InvalidArguments; } if (ProxyGenerator == null) { try { ProxyGenerator = CreateProxyGenerator(generatorOptions.Generator); } catch (Exception exc) { error.WriteLine(exc.Message); return Error.CreateProxyGenerator; } } generatorOptions = ProxyGenerator.GetOptions(); if( generatorOptions == null ) { error.WriteLine("{0}.GetOptions() returned null. Please use a different Generator.", ProxyGenerator.GetType().FullName); return Error.InvalidGenerator; } if (Parser.ParseHelp(args)) { error.WriteLine(Parser.ArgumentsUsage(generatorOptions.GetType())); return Error.None; } if (Parser.ParseArguments(args, generatorOptions) == false) { error.WriteLine(Parser.ArgumentsUsage(generatorOptions.GetType())); return Error.InvalidArguments; } try { ProxyGenerator.Generate(generatorOptions); } catch (Exception exc) { error.WriteLine(exc.Message); error.WriteLine(exc.StackTrace); return Error.Unknown; } return Error.None; }
public void NullAndNotNullNotEquals() { var comparer = new ProxyGeneratorOptionsComparer(); var o = new ProxyGeneratorOptions(); Assert.AreEqual(false, comparer.Equals(o, null)); Assert.AreEqual(false, comparer.Equals(null, o)); }
public void MixinNumberNotEquals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.AddMixinInstance(new TypeITD()); var o2 = new ProxyGeneratorOptions(); Assert.AreEqual(false, comparer.Equals(o1, o2)); }
public void SameMxinsTypeNotEquals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.AddMixinInstance(new TypeITD()); var o2 = new ProxyGeneratorOptions(); o2.AddMixinInstance(new TypeITD()); Assert.AreEqual(true, comparer.Equals(o1, o2)); }
public void AdditonalTypeAttributes_Same_Count_Same_Attributes_Equals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.AdditionalTypeAttributes.Add(new CustomAttributeDefinition(typeof(MyAttribute).GetConstructors()[0], new object[0])); var o2 = new ProxyGeneratorOptions(); o2.AdditionalTypeAttributes.Add(new CustomAttributeDefinition(typeof(MyAttribute).GetConstructors()[0], new object[0])); Assert.AreEqual(true, comparer.Equals(o1, o2)); }
public void MemberSelector_Same_Equals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.ClassProxyMemberSelector = new ClassProxyMemberSelectorMock1(); var o2 = new ProxyGeneratorOptions(); o2.ClassProxyMemberSelector = new ClassProxyMemberSelectorMock1(); Assert.AreEqual(true, comparer.Equals(o1, o2)); }
public void InterceptorSelector_Same_Equals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.InterceptorSelector = new MYInterceptorSelectorMock(); var o2 = new ProxyGeneratorOptions(); o2.InterceptorSelector = new MYInterceptorSelectorMock(); Assert.AreEqual(true, comparer.Equals(o1, o2)); }
public void Constructor_Not_Same__Not_Equals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.ConstructorSelector = new ConstructorSelectorMock1(); var o2 = new ProxyGeneratorOptions(); o2.ConstructorSelector = new ConstructorSelectorMock2(); Assert.AreEqual(false, comparer.Equals(o1, o2)); }
public void AdditonalCode_Equals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.AdditionalCode = new AdditionalCodeMock1(); var o2 = new ProxyGeneratorOptions(); o2.AdditionalCode = new AdditionalCodeMock1(); Assert.AreEqual(true, comparer.Equals(o1, o2)); }
public void ServiceProvider_Same_Equals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.InterceptableMethodBuilder = new InterceptableMethodBuilderMock1(); var o2 = new ProxyGeneratorOptions(); o2.InterceptableMethodBuilder = new InterceptableMethodBuilderMock1(); Assert.AreEqual(true, comparer.Equals(o1, o2)); }
public Assembly Generate(ProxyGeneratorOptions options) { ValidateOptions(options); try { CrossAppDomainCaller.RunInOtherAppDomain(Generate, this, options); } finally { CleanUpIntermediateFiles(options); } return(Assembly.LoadFrom(options.OutputAssemblyPath)); }
public void Select_Constructor() { var generator = new ProxyGenerator(); var options = new ProxyGeneratorOptions(); options.ConstructorSelector = new MostParameterConstructorSelector(); var proxy = generator.CreateClassProxy <TypeInj_Multi_Ctor>(options); Assert.IsNotNull(proxy); Assert.AreEqual(true, TypeInj_Multi_Ctor.IsMostCalled); Assert.IsNull(TypeInj_Multi_Ctor.InjService1); Assert.IsNull(TypeInj_Multi_Ctor.InjService2); }
private static void RunMixinsSample(ProxyGenerator generator) { Console.WriteLine("---------------------- Mixins ----------------------"); var options = new ProxyGeneratorOptions(); options.AddMixinInstance(new PropertyChangedMixin()); var proxy = generator.CreateClassProxy <MyClassWithMixin>(options); // new LogInterceptor()); proxy.Title = "New title"; proxy.UpdateTitle(); // caution with ClassProxy and InterfaceProxy with targets, cannot work because the target is called, and this is not the property Title of the proxy that is called }
public Assembly Generate(ProxyGeneratorOptions options) { ValidateOptions(options); try { CrossAppDomainCaller.RunInOtherAppDomain(Generate, this, options); } finally { CleanUpIntermediateFiles(options); } return Assembly.LoadFrom(options.OutputAssemblyPath); }
public ProxyTypeDefinition GetByType(Type type, Type targetType, ProxyGeneratorOptions options) { if (type is null) { throw new ArgumentNullException(nameof(type)); } foreach (var item in items) { if (Equals(item, type, targetType, options)) { return(item); } } return(null); }
public void AdditonalCode_Null_And_Not_Null_Not_Equals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.AdditionalCode = new AdditionalCodeMock1(); var o2 = new ProxyGeneratorOptions(); Assert.AreEqual(false, comparer.Equals(o1, o2)); var o3 = new ProxyGeneratorOptions(); var o4 = new ProxyGeneratorOptions(); o4.AdditionalCode = new AdditionalCodeMock1(); Assert.AreEqual(false, comparer.Equals(o3, o4)); }
protected override Configuration CreateNHibernateConfiguration( Assembly[] inputAssemblies, ProxyGeneratorOptions options ) { ActiveRecordConfigurationSource activeRecordConfiguration = new ActiveRecordConfigurationSource(); activeRecordConfiguration.Add(typeof(ActiveRecordBase), GetDefaultNHibernateProperties(options)); ActiveRecordStarter.Initialize(inputAssemblies, activeRecordConfiguration); Configuration nhibernateConfiguration = ActiveRecordMediator.GetSessionFactoryHolder().GetConfiguration(typeof(ActiveRecordBase)); nhibernateConfiguration.SetProperties(GetDefaultNHibernateProperties(options)); foreach(Assembly inputAssembly in inputAssemblies) { nhibernateConfiguration.AddAssembly(inputAssembly); } return nhibernateConfiguration; }
public void ServiceProvider_Null_And_Not_Null_Not_Equals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.InterceptableMethodBuilder = new InterceptableMethodBuilderMock1(); var o2 = new ProxyGeneratorOptions(); Assert.AreEqual(false, comparer.Equals(o1, o2)); var o3 = new ProxyGeneratorOptions(); var o4 = new ProxyGeneratorOptions(); o4.InterceptableMethodBuilder = new InterceptableMethodBuilderMock1(); Assert.AreEqual(false, comparer.Equals(o3, o4)); }
public void InterceptorSelector_Null_And_Not_Null_Not_Equals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.InterceptorSelector = new MYInterceptorSelectorMock(); var o2 = new ProxyGeneratorOptions(); Assert.AreEqual(false, comparer.Equals(o1, o2)); var o3 = new ProxyGeneratorOptions(); var o4 = new ProxyGeneratorOptions(); o4.InterceptorSelector = new MYInterceptorSelectorMock(); Assert.AreEqual(false, comparer.Equals(o3, o4)); }
public void MemberSelector_Null_And_Not_Null_Not_Equals() { var comparer = new ProxyGeneratorOptionsComparer(); var o1 = new ProxyGeneratorOptions(); o1.ClassProxyMemberSelector = new ClassProxyMemberSelectorMock1(); var o2 = new ProxyGeneratorOptions(); Assert.AreEqual(false, comparer.Equals(o1, o2)); var o3 = new ProxyGeneratorOptions(); var o4 = new ProxyGeneratorOptions(); o4.ClassProxyMemberSelector = new ClassProxyMemberSelectorMock1(); Assert.AreEqual(false, comparer.Equals(o3, o4)); }
private void SetMixinDefinitions(ProxyTypeDefinition typeDefinition, ProxyGeneratorOptions options) { if (options != null) { int length = options.MixinInstances.Count; MixinDefinition[] mixinDefinitions = new MixinDefinition[length]; for (int i = 0; i < length; i++) { var mixinInstance = options.MixinInstances[i]; mixinDefinitions[i] = new MixinDefinition(this, typeDefinition, mixinInstance); } typeDefinition.MixinDefinitions = mixinDefinitions; } else { typeDefinition.MixinDefinitions = new MixinDefinition[0]; } }
public void Return_Same_TypeDefinition_With_Same_Type_And_Same_Target_Type_And_Same_Options() { var moduleDefinition = new ModuleDefinition(); var target = typeof(TypeM1); var o = new ProxyGeneratorOptions(); o.AddMixinInstance(new MyMixin()); var typeDefinition = moduleDefinition.GetTypeDefinition(typeof(TypeM1), target, o); Assert.AreEqual(TypeDefinitionType.ClassProxy, typeDefinition.TypeDefinitionType); Assert.AreEqual(typeof(ClassProxyDefinition), typeDefinition.GetType()); Assert.AreEqual(typeof(TypeM1), typeDefinition.Type); Assert.AreEqual(target, typeDefinition.TargetType); Assert.AreEqual(1, moduleDefinition.TypeDefinitions.Count); Assert.AreEqual(typeDefinition, moduleDefinition.TypeDefinitions[0]); // returns same type definition for same type with same target type or null and same options var target2 = typeof(TypeM1); var o2 = new ProxyGeneratorOptions(); o2.AddMixinInstance(new MyMixin()); var typeDefinition2 = moduleDefinition.GetTypeDefinition(typeof(TypeM1), target2, o2); Assert.AreEqual(TypeDefinitionType.ClassProxy, typeDefinition2.TypeDefinitionType); Assert.AreEqual(typeof(ClassProxyDefinition), typeDefinition2.GetType()); Assert.AreEqual(typeof(TypeM1), typeDefinition2.Type); Assert.AreEqual(target2, typeDefinition2.TargetType); var comparer = new ProxyGeneratorOptionsComparer(); Assert.AreEqual(true, comparer.Equals(o2, typeDefinition2.Options)); Assert.AreEqual(typeDefinition2, typeDefinition); Assert.AreEqual(1, moduleDefinition.TypeDefinitions.Count); Assert.AreEqual(typeDefinition, moduleDefinition.TypeDefinitions[0]); }
private static void RunInterceptorSelectorSample(ProxyGenerator generator) { Console.WriteLine("---------------------- InterceptorSelector ----------------------"); var options = new ProxyGeneratorOptions(); options.InterceptorSelector = new MyInterceptorSelector(); options.ClassProxyMemberSelector = new MyClassProxyMemberSelector(); var proxy = generator.CreateClassProxy <MyClassWithInterceptorSelector>(options, new GetMethodInterceptor(), new SetMethodInterceptor(), new MethodInterceptor()); proxy.MyProperty = "New Value"; Console.WriteLine($"Get: {proxy.MyProperty}"); proxy.MyMethod(); proxy.MyMethod("My parameter"); proxy.MyMethod2(); // not intercepted }
private static void ValidateOptions(ProxyGeneratorOptions options) { if (options == null) throw new ProxyGeneratorException("options must be of type {0}", typeof (ProxyGeneratorOptions).Name); if (string.IsNullOrEmpty(options.OutputAssemblyPath)) throw new ProxyGeneratorException("options.OutputAssemblyPath is Required"); if (!Path.IsPathRooted(options.OutputAssemblyPath)) options.OutputAssemblyPath = Path.GetFullPath(options.OutputAssemblyPath); if (options.InputAssemblyPaths == null || options.InputAssemblyPaths.Length == 0) throw new ProxyGeneratorException("At least one input assembly is required"); }
protected virtual IDictionary<string, string> GetDefaultNHibernateProperties(ProxyGeneratorOptions options) { Dictionary<string, string> properties = new Dictionary<string, string>(); properties["cache.provider_class"] = typeof(HashtableCacheProvider).AssemblyQualifiedName; properties["dialect"] = options.Dialect; properties["proxyfactory.factory_class"] = typeof(CastleProxyFactoryFactory).AssemblyQualifiedName; return properties; }
protected virtual Configuration CreateNHibernateConfiguration( Assembly[] inputAssemblies, ProxyGeneratorOptions options ) { Configuration nhibernateConfiguration = new Configuration(); //nhibernateConfiguration.AddProperties(GetDefaultNHibernateProperties(options)); nhibernateConfiguration.SetProperties(GetDefaultNHibernateProperties(options)); foreach (Assembly inputAssembly in inputAssemblies) { nhibernateConfiguration.AddAssembly(inputAssembly); } return nhibernateConfiguration; }
protected virtual Configuration CreateNHibernateConfiguration(IEnumerable<Assembly> inputAssemblies, ProxyGeneratorOptions options) { var nhibernateConfiguration = new Configuration(); nhibernateConfiguration.SetProperties(GetDefaultNHibernateProperties(options)); foreach (var inputAssembly in inputAssemblies) { nhibernateConfiguration.AddAssembly(inputAssembly); } return nhibernateConfiguration; }
protected virtual void GenerateImpl(ProxyGeneratorOptions options) { var outputAssemblyPath = options.OutputAssemblyPath; var inputAssemblies = options.InputAssemblies; var nhibernateConfiguration = CreateNHibernateConfiguration(inputAssemblies, options); if (nhibernateConfiguration.ClassMappings.Count == 0) FailNoClassMappings(inputAssemblies); var proxyResult = GenerateProxies(nhibernateConfiguration, options.IntermediateProxyAssemblyPath); var staticProxyFactorySourceCode = GenerateStaticProxyFactorySourceCode(inputAssemblies[0].GetName().Version, BuildProxyTable(proxyResult.Proxies)); var result = CompileStaticProxyFactory(nhibernateConfiguration, proxyResult.Assembly, staticProxyFactorySourceCode, options.IntermediateStaticProxyFactoryAssemblyPath); if (result.Errors.HasErrors) { var errors = new StringBuilder(); foreach (var error in result.Errors) { errors.AppendLine(error.ToString()); } throw new ProxyGeneratorException(errors.ToString()); } MergeStaticProxyFactoryWithProxies(result.CompiledAssembly, proxyResult.Assembly, inputAssemblies, outputAssemblyPath); }