forked from MefContrib/MefContrib
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unknown
committed
Sep 27, 2010
1 parent
41eed9d
commit dd20bd3
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/MefContrib.Interception.Castle/DynamicProxyInterceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/MefContrib.Interception.Castle/MefContrib.Interception.Castle.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |