Skip to content

Commit

Permalink
Support for dynamic proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Sep 27, 2010
1 parent 41eed9d commit dd20bd3
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/MefContrib.Interception.Castle/DynamicProxyInterceptor.cs
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.DynamicProxy;
using MefContrib.Interception;

namespace Composition.Interception.DynamicProxy
{
public class DynamicProxyInterceptor : IExportedValueInterceptor
{
private readonly IInterceptor[] _interceptors;
private static readonly ProxyGenerator _generator = new ProxyGenerator();

public DynamicProxyInterceptor(params IInterceptor[] interceptors)
{
_interceptors = interceptors;
}

public object Intercept(object value)
{
ProxyGenerationOptions options = new ProxyGenerationOptions();

var interfaces = value.GetType().GetInterfaces();
Type proxyInterface = interfaces.FirstOrDefault();
Type[] additionalInterfaces = interfaces.Skip(1).ToArray();
var proxy = _generator.CreateInterfaceProxyWithTargetInterface(proxyInterface, additionalInterfaces, value, _interceptors);
return proxy;
}
}
}
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{842EAC3A-8601-48B0-9023-3B23A3EE7759}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MefContrib.Interception.Castle</RootNamespace>
<AssemblyName>MefContrib.Interception.Castle</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core">
<HintPath>..\..\dependencies\desktop\castle\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\MefContrib\Properties\SharedAssemblyInfo.cs">
<Link>SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="DynamicProxyInterceptor.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MefContrib.Interception\MefContrib.Interception.csproj">
<Project>{11F6AAB8-BF84-4F7B-A03A-7A5972A15F38}</Project>
<Name>MefContrib.Interception</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

0 comments on commit dd20bd3

Please sign in to comment.