Skip to content
This repository was archived by the owner on Aug 3, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
Help/

# Visual Studo 2015 cache/options directory
.vs/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding addin-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
*.[Cc]ache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
bower_components/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt
20 changes: 18 additions & 2 deletions src/LinFu.AOP.Interfaces/CompositeAroundInvoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@

namespace LinFu.AOP.Interfaces
{
internal class CompositeAroundInvoke : IAroundInvoke
/// <summary>
/// Represents a class that can wrap itself around any given method call.
/// </summary>
public class CompositeAroundInvoke : IAroundInvoke
{
private readonly IList<IAroundInvoke> _aroundInvokeList = new List<IAroundInvoke>();

/// <summary>
/// Constructs a composit around invoke.
/// </summary>
/// <param name="aroundInvokeList">An collection of <see cref="IAroundInvoke"/> to </param>
public CompositeAroundInvoke(IEnumerable<IAroundInvoke> aroundInvokeList)
{
if (aroundInvokeList == null)
Expand All @@ -22,7 +29,11 @@ public CompositeAroundInvoke(IEnumerable<IAroundInvoke> aroundInvokeList)
}
}


/// <summary>
/// This method will be called immediately after the actual method call is executed.
/// </summary>
/// <param name="context">The <see cref="IInvocationInfo"/> associated with the method call.</param>
/// <param name="returnValue">The value returned from the actual method call.</param>
public void AfterInvoke(IInvocationInfo context, object returnValue)
{
foreach (var invoke in _aroundInvokeList)
Expand All @@ -31,6 +42,11 @@ public void AfterInvoke(IInvocationInfo context, object returnValue)
}
}

/// <summary>
/// This method will be called just before the actual method call is executed.
/// </summary>
/// <param name="context">The <see cref="IInvocationInfo"/> associated with the method call.</param>
/// <seealso cref="IInvocationInfo"/>
public void BeforeInvoke(IInvocationInfo context)
{
foreach (var invoke in _aroundInvokeList)
Expand Down
64 changes: 64 additions & 0 deletions src/LinFu.AOP.Interfaces/CompositeAroundInvokeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace LinFu.AOP.Interfaces
{
class CompositeAroundInvokeProvider : IAroundInvokeProvider
{
/// <summary>
/// Gets or sets the valud indicating the Predicates that will determine weather or not
/// the method should be intercepted by the associated <see cref="IAroundInvoke"/>.
/// </summary>
public IDictionary<IAroundInvoke, Func<IInvocationInfo, bool>> MethodInvokesAndPredicates { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="CompositeAroundInvokeProvider"/> class.
/// </summary>
/// <param name="aroundInvokeAndPredicates">
/// Dictionary of <see cref="IAroundInvoke"/> and predicates to determine if a method should be intercepted.
/// </param>
/// <remarks>
/// Specifing null for the aroundInvokeAndPredicates predicate will use the default ShouldReplace predicate
/// in <see cref="CompositeAroundInvokeProvider"/>.
/// </remarks>
public CompositeAroundInvokeProvider(IDictionary<IAroundInvoke, Func<IInvocationInfo, bool>> aroundInvokeAndPredicates)
{
if (aroundInvokeAndPredicates != null)
{
MethodInvokesAndPredicates = new Dictionary<IAroundInvoke, Func<IInvocationInfo, bool>>();
foreach (var invokeAndPredicate in aroundInvokeAndPredicates)
{
MethodInvokesAndPredicates.Add(invokeAndPredicate.Key, invokeAndPredicate.Value ?? ShouldReplace);
}
}
}

/// <summary>
/// Determines whether or not a particular method body should be invoked around at runtime.
/// </summary>
/// <param name="context">The context surrounding the method call.</param>
/// <returns>Returns <c>true</c>.</returns>
public virtual bool ShouldReplace(IInvocationInfo context)
{
return true;
}

#region IAroundInvokeProvider Members
/// <summary>
/// Gets the surrounding implemetation for a given <see cref="IInvocationInfo">invocation context</see>.
/// </summary>
/// <param name="context">The context surrounding the method call.</param>
/// <returns>The interceptor that will invoke around the method at runtime.</returns>
public IAroundInvoke GetSurroundingImplementation(IInvocationInfo context)
{
var invokes = new HashSet<IAroundInvoke>();
foreach (var invokePredicate in MethodInvokesAndPredicates.Where(x => x.Value != null && x.Value(context)))
{
invokes.Add(invokePredicate.Key);
}
return (invokes.Count > 0) ? new CompositeAroundInvoke(invokes) : null;
}
#endregion
}
}
2 changes: 2 additions & 0 deletions src/LinFu.AOP.Interfaces/LinFu.AOP.Interfaces.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Compile Include="BootstrapException.cs" />
<Compile Include="BootStrapRegistry.cs" />
<Compile Include="CallCounter.cs" />
<Compile Include="CompositeAroundInvokeProvider.cs" />
<Compile Include="CompositeAroundInvoke.cs" />
<Compile Include="Counter.cs" />
<Compile Include="CountingInterceptor.cs" />
Expand Down Expand Up @@ -97,6 +98,7 @@
<Compile Include="MethodBodyReplacementProviderRegistry.cs" />
<Compile Include="MethodCallReplacementProviderRegistry.cs" />
<Compile Include="MultithreadedCallCounter.cs" />
<Compile Include="SimpleAroundInvokeProvider.cs" />
<Compile Include="SimpleMethodReplacementProvider.cs" />
<Compile Include="SingleThreadedCallCounter.cs" />
<Compile Include="TypeActivationContext.cs" />
Expand Down
55 changes: 55 additions & 0 deletions src/LinFu.AOP.Interfaces/SimpleAroundInvokeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;

namespace LinFu.AOP.Interfaces
{
/// <summary>
/// Represents the simplest possible <see cref="IAroundInvokeProvider"/> implementation
/// that will allow the user to use the original around invoke implementation as part
/// of the interceptor call.
/// </summary>
public class SimpleAroundInvokeProvider : IAroundInvokeProvider
{
/// <summary>
/// Gets or sets the value indicating the Predicate that will determine whether or not
/// the method should be intercepted.
/// </summary>
/// <value>The interceptor predicate.</value>
public Func<IInvocationInfo, bool> MethodInvokePredicate { get; set; }

private readonly IAroundInvoke _around;

/// <summary>
/// Initializes a new instance of the <see cref="SimpleAroundInvokeProvider"/> class.
/// </summary>
/// <param name="around">The around invoke interceptor.</param>
public SimpleAroundInvokeProvider(IAroundInvoke around)
{
_around = around;
MethodInvokePredicate = ShouldReplace;
}

/// <summary>
/// Determines whether or not a particular method body should be invoked around at runtime.
/// </summary>
/// <param name="context">The context surrounding the method call.</param>
/// <returns>Returns <c>true</c>.</returns>
public virtual bool ShouldReplace(IInvocationInfo context)
{
return true;
}

#region IAroundInvokeProvider Members
/// <summary>
/// Gets the surrounding implemetation for a given <see cref="IInvocationInfo">invocation context</see>.
/// </summary>
/// <param name="context">The context surrounding the method call.</param>
/// <returns>The interceptor that will invoke around the method at runtime.</returns>
public IAroundInvoke GetSurroundingImplementation(IInvocationInfo context)
{
if (MethodInvokePredicate == null || !MethodInvokePredicate(context))
return null;
return _around;
}
#endregion
}
}