Author: hammett Date: Thu Sep 9 07:06:15 2004 New Revision: 43596 Added: avalon/trunk/central/laboratory/avalon-net/DynamicProxy/Builder/DefaultProxyBuilder.cs (contents, props changed) Removed: avalon/trunk/central/laboratory/avalon-net/DynamicProxy/Builder/ProxyBuilderImpl.cs Modified: avalon/trunk/central/laboratory/avalon-net/DynamicProxy/Apache.Avalon.DynamicProxy.csproj avalon/trunk/central/laboratory/avalon-net/DynamicProxy/DynamicProxyTest/CustomProxyGeneratorTestCase.cs avalon/trunk/central/laboratory/avalon-net/DynamicProxy/DynamicProxyTest/ProxyGeneratorTestCase.cs avalon/trunk/central/laboratory/avalon-net/DynamicProxy/ProxyGenerator.cs Log: Endless refactoring :-)
Modified: avalon/trunk/central/laboratory/avalon-net/DynamicProxy/Apache.Avalon.DynamicProxy.csproj ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/DynamicProxy/Apache.Avalon.DynamicProxy.csproj (original) +++ avalon/trunk/central/laboratory/avalon-net/DynamicProxy/Apache.Avalon.DynamicProxy.csproj Thu Sep 9 07:06:15 2004 @@ -104,12 +104,12 @@ BuildAction = "Compile" /> <File - RelPath = "Builder\IProxyBuilder.cs" + RelPath = "Builder\DefaultProxyBuilder.cs" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "Builder\ProxyBuilderImpl.cs" + RelPath = "Builder\IProxyBuilder.cs" SubType = "Code" BuildAction = "Compile" /> Added: avalon/trunk/central/laboratory/avalon-net/DynamicProxy/Builder/DefaultProxyBuilder.cs ============================================================================== --- (empty file) +++ avalon/trunk/central/laboratory/avalon-net/DynamicProxy/Builder/DefaultProxyBuilder.cs Thu Sep 9 07:06:15 2004 @@ -0,0 +1,55 @@ +using Apache.Avalon.DynamicProxy.Builder.CodeGenerators; +// Copyright 2004 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Apache.Avalon.DynamicProxy.Builder +{ + using System; + + /// <summary> + /// Summary description for DefaultProxyBuilder. + /// </summary> + public class DefaultProxyBuilder : IProxyBuilder + { + #region IProxyBuilder Members + + public Type CreateInterfaceProxy(Type[] interfaces) + { + InterfaceProxyGenerator generator = new InterfaceProxyGenerator(); + return generator.GenerateCode( interfaces ); + } + + public Type CreateClassProxy(Type theClass) + { + ClassProxyGenerator generator = new ClassProxyGenerator(); + return generator.GenerateCode( theClass ); + } + + public Type CreateCustomInterfaceProxy(Type[] interfaces, EnhanceTypeDelegate enhance, + ScreenInterfacesDelegate screenInterfaces) + { + InterfaceProxyGenerator generator = new InterfaceProxyGenerator(enhance, screenInterfaces); + return generator.GenerateCode( interfaces ); + } + + public Type CreateCustomClassProxy(Type theClass, EnhanceTypeDelegate enhance, + ScreenInterfacesDelegate screenInterfaces) + { + ClassProxyGenerator generator = new ClassProxyGenerator(enhance, screenInterfaces); + return generator.GenerateCode( theClass ); + } + + #endregion + } +} Modified: avalon/trunk/central/laboratory/avalon-net/DynamicProxy/DynamicProxyTest/CustomProxyGeneratorTestCase.cs ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/DynamicProxy/DynamicProxyTest/CustomProxyGeneratorTestCase.cs (original) +++ avalon/trunk/central/laboratory/avalon-net/DynamicProxy/DynamicProxyTest/CustomProxyGeneratorTestCase.cs Thu Sep 9 07:06:15 2004 @@ -28,6 +28,7 @@ [TestFixture] public class CustomProxyGeneratorTestCase : Assertion { + private ProxyGenerator m_generator; private bool m_enhanceInvoked; private bool m_screenInvoked; private bool m_constructorInvoked; @@ -35,6 +36,7 @@ [SetUp] public void Init() { + m_generator = new ProxyGenerator(); m_enhanceInvoked = false; m_screenInvoked = false; m_constructorInvoked = false; @@ -43,7 +45,7 @@ [Test] public void CreateCustomProxy() { - object proxy = ProxyGenerator.CreateCustomProxy( + object proxy = m_generator.CreateCustomProxy( typeof (IMyInterface), new StandardInvocationHandler(new MyInterfaceImpl()), new EnhanceTypeDelegate(EnhanceType), @@ -58,7 +60,7 @@ [Test] public void CreateCustomClassProxy() { - object proxy = ProxyGenerator.CreateCustomClassProxy( + object proxy = m_generator.CreateCustomClassProxy( typeof (ServiceClass), new StandardInvocationHandler(new ServiceClass()), new EnhanceTypeDelegate(EnhanceType), Modified: avalon/trunk/central/laboratory/avalon-net/DynamicProxy/DynamicProxyTest/ProxyGeneratorTestCase.cs ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/DynamicProxy/DynamicProxyTest/ProxyGeneratorTestCase.cs (original) +++ avalon/trunk/central/laboratory/avalon-net/DynamicProxy/DynamicProxyTest/ProxyGeneratorTestCase.cs Thu Sep 9 07:06:15 2004 @@ -29,10 +29,18 @@ [TestFixture] public class ProxyGeneratorTestCase : Assertion { + private ProxyGenerator m_generator; + + [SetUp] + public void Init() + { + m_generator = new ProxyGenerator(); + } + [Test] public void ProxyForClass() { - object proxy = ProxyGenerator.CreateClassProxy( + object proxy = m_generator.CreateClassProxy( typeof(ServiceClass), new ResultModifiedInvocationHandler( new ServiceClass() ) ); AssertNotNull( proxy ); @@ -47,7 +55,7 @@ [Test] public void ProxyForClassWithSuperClass() { - object proxy = ProxyGenerator.CreateClassProxy( + object proxy = m_generator.CreateClassProxy( typeof(SpecializedServiceClass), new ResultModifiedInvocationHandler( new SpecializedServiceClass() ) ); AssertNotNull( proxy ); @@ -64,7 +72,7 @@ [Test] public void ProxyForClassWhichImplementsInterfaces() { - object proxy = ProxyGenerator.CreateClassProxy( + object proxy = m_generator.CreateClassProxy( typeof(MyInterfaceImpl), new ResultModifiedInvocationHandler( new MyInterfaceImpl() ) ); AssertNotNull( proxy ); @@ -79,7 +87,7 @@ [Test] public void ProxyingClassWithoutVirtualMethods() { - object proxy = ProxyGenerator.CreateClassProxy( + object proxy = m_generator.CreateClassProxy( typeof(NoVirtualMethodClass), new ResultModifiedInvocationHandler( new SpecializedServiceClass() ) ); AssertNotNull( proxy ); @@ -93,7 +101,7 @@ [Test] public void ProxyingClassWithSealedMethods() { - object proxy = ProxyGenerator.CreateClassProxy( + object proxy = m_generator.CreateClassProxy( typeof(SealedMethodsClass), new ResultModifiedInvocationHandler( new SpecializedServiceClass() ) ); AssertNotNull( proxy ); @@ -109,7 +117,7 @@ { try { - ProxyGenerator.CreateClassProxy( + m_generator.CreateClassProxy( typeof(ICloneable), new StandardInvocationHandler( new SpecializedServiceClass() ) ); } catch(ArgumentException) @@ -119,7 +127,7 @@ try { - ProxyGenerator.CreateClassProxy( + m_generator.CreateClassProxy( null, new StandardInvocationHandler( new SpecializedServiceClass() ) ); } catch(ArgumentNullException) @@ -129,7 +137,7 @@ try { - ProxyGenerator.CreateClassProxy( + m_generator.CreateClassProxy( typeof(SpecializedServiceClass), null ); } catch(ArgumentNullException) @@ -141,7 +149,7 @@ [Test] public void TestGenerationSimpleInterface() { - object proxy = ProxyGenerator.CreateProxy( + object proxy = m_generator.CreateProxy( typeof(IMyInterface), new StandardInvocationHandler( new MyInterfaceImpl() ) ); AssertNotNull( proxy ); @@ -161,7 +169,7 @@ [Test] public void TestGenerationWithInterfaceHeritage() { - object proxy = ProxyGenerator.CreateProxy( + object proxy = m_generator.CreateProxy( typeof(IMySecondInterface), new StandardInvocationHandler( new MySecondInterfaceImpl() ) ); AssertNotNull( proxy ); @@ -185,7 +193,7 @@ { ServiceStatusImpl service = new ServiceStatusImpl(); - object proxy = ProxyGenerator.CreateProxy( + object proxy = m_generator.CreateProxy( typeof(IServiceStatus), new StandardInvocationHandler( service ) ); AssertNotNull( proxy ); Modified: avalon/trunk/central/laboratory/avalon-net/DynamicProxy/ProxyGenerator.cs ============================================================================== --- avalon/trunk/central/laboratory/avalon-net/DynamicProxy/ProxyGenerator.cs (original) +++ avalon/trunk/central/laboratory/avalon-net/DynamicProxy/ProxyGenerator.cs Thu Sep 9 07:06:15 2004 @@ -42,21 +42,31 @@ /// <example> /// <code> /// MyInvocationHandler handler = ... + /// ProxyGenerator generator = new ProxyGenerator(); /// IInterfaceExposed proxy = - /// ProxyGenerator.CreateProxy( new Type[] { typeof(IInterfaceExposed) }, handler ); + /// generator.CreateProxy( new Type[] { typeof(IInterfaceExposed) }, handler ); /// </code> /// </example> - public abstract class ProxyGenerator + public class ProxyGenerator { - private static IProxyBuilder m_builder = new ProxyBuilderImpl(); + private IProxyBuilder m_builder; - public static IProxyBuilder ProxyBuilder + public ProxyGenerator(IProxyBuilder builder) + { + m_builder = builder; + } + + public ProxyGenerator() : this( new ProxyBuilderImpl() ) + { + } + + public IProxyBuilder ProxyBuilder { get { return m_builder; } set { m_builder = value; } } - public static object CreateClassProxy(Type baseClass, IInvocationHandler handler) + public virtual object CreateClassProxy(Type baseClass, IInvocationHandler handler) { AssertCreateClassProxyArguments(baseClass, handler); @@ -64,7 +74,7 @@ return CreateProxyInstance( newType, handler ); } - public static object CreateCustomClassProxy(Type baseClass, IInvocationHandler handler, + public virtual object CreateCustomClassProxy(Type baseClass, IInvocationHandler handler, EnhanceTypeDelegate enhance, ScreenInterfacesDelegate screenInterfaces, ConstructorArgumentsDelegate constructorArguments) @@ -82,7 +92,7 @@ /// <param name="theInterface">Interface to be implemented</param> /// <param name="handler">instance of <see cref="IInvocationHandler"/></param> /// <returns>Proxy instance</returns> - public static object CreateProxy(Type theInterface, IInvocationHandler handler) + public virtual object CreateProxy(Type theInterface, IInvocationHandler handler) { return CreateProxy(new Type[] {theInterface}, handler); } @@ -94,7 +104,7 @@ /// <param name="interfaces">Array of interfaces to be implemented</param> /// <param name="handler">instance of <see cref="IInvocationHandler"/></param> /// <returns>Proxy instance</returns> - public static object CreateProxy(Type[] interfaces, IInvocationHandler handler) + public virtual object CreateProxy(Type[] interfaces, IInvocationHandler handler) { AssertCreateProxyArguments(interfaces, handler); @@ -111,7 +121,7 @@ /// <param name="screenInterfaces"></param> /// <param name="constructorArguments"></param> /// <returns></returns> - public static object CreateCustomProxy(Type theInterface, + public virtual object CreateCustomProxy(Type theInterface, IInvocationHandler handler, EnhanceTypeDelegate enhance, ScreenInterfacesDelegate screenInterfaces, ConstructorArgumentsDelegate constructorArguments ) @@ -129,7 +139,7 @@ /// <param name="screenInterfaces"></param> /// <param name="constructorArguments"></param> /// <returns></returns> - public static object CreateCustomProxy(Type[] interfaces, + public virtual object CreateCustomProxy(Type[] interfaces, IInvocationHandler handler, EnhanceTypeDelegate enhance, ScreenInterfacesDelegate screenInterfaces, ConstructorArgumentsDelegate constructorArguments ) @@ -139,12 +149,12 @@ return CreateCustomProxyInstance( newType, handler, constructorArguments ); } - private static object CreateProxyInstance(Type type, IInvocationHandler handler) + protected virtual object CreateProxyInstance(Type type, IInvocationHandler handler) { return Activator.CreateInstance(type, new object[] {handler}); } - private static object CreateCustomProxyInstance(Type type, IInvocationHandler handler, ConstructorArgumentsDelegate constructorArguments) + protected virtual object CreateCustomProxyInstance(Type type, IInvocationHandler handler, ConstructorArgumentsDelegate constructorArguments) { if (constructorArguments != null) { @@ -157,7 +167,7 @@ } } - private static void AssertCreateProxyArguments(Type[] interfaces, IInvocationHandler handler) + protected static void AssertCreateProxyArguments(Type[] interfaces, IInvocationHandler handler) { if (interfaces == null) { @@ -173,7 +183,7 @@ } } - private static void AssertCreateClassProxyArguments(Type baseClass, IInvocationHandler handler) + protected static void AssertCreateClassProxyArguments(Type baseClass, IInvocationHandler handler) { if (baseClass == null) { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]