/src/LinFu.Proxy/ProxyImplementor.cs
http://github.com/philiplaureano/LinFu · C# · 37 lines · 23 code · 3 blank · 11 comment · 1 complexity · 9b5292d9ca221e7e0186f5576e7a189c MD5 · raw file
- using LinFu.AOP.Interfaces;
- using LinFu.IoC.Configuration;
- using LinFu.Proxy.Interfaces;
- using LinFu.Reflection.Emit;
- using LinFu.Reflection.Emit.Interfaces;
- using Mono.Cecil;
- using CallingConventions = Mono.Cecil.MethodCallingConvention;
- namespace LinFu.Proxy
- {
- /// <summary>
- /// A class that provides the default implementation
- /// for the IProxy interface.
- /// </summary>
- [Implements(typeof(ITypeBuilder), LifecycleType.OncePerRequest, ServiceName = "ProxyImplementor")]
- internal class ProxyImplementor : ITypeBuilder
- {
- /// <summary>
- /// Constructs a type that implements the
- /// <see cref="IProxy" /> interface.
- /// </summary>
- /// <param name="module">The module that will hold the target type.</param>
- /// <param name="targetType">The type that will implement the <see cref="IProxy" /> interface.</param>
- public void Construct(ModuleDefinition module, TypeDefinition targetType)
- {
- var proxyInterfaceType = module.Import(typeof(IProxy));
- var interceptorType = module.Import(typeof(IInterceptor));
- // Implement the IProxy interface only once
- if (targetType.Interfaces.Contains(proxyInterfaceType))
- return;
- targetType.Interfaces.Add(proxyInterfaceType);
- targetType.AddProperty("Interceptor", interceptorType);
- }
- }
- }