-
Notifications
You must be signed in to change notification settings - Fork 102
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
Showing
17 changed files
with
828 additions
and
0 deletions.
There are no files selected for viewing
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,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2013 Antya Dev | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KingAOP", "KingAOP\KingAOP.csproj", "{ED8B42DC-F376-42A7-9281-452A026AA864}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{ED8B42DC-F376-42A7-9281-452A026AA864}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{ED8B42DC-F376-42A7-9281-452A026AA864}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{ED8B42DC-F376-42A7-9281-452A026AA864}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{ED8B42DC-F376-42A7-9281-452A026AA864}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
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,49 @@ | ||
// Copyright (c) 2013 Antya Dev | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
// software and associated documentation files (the "Software"), to deal in the Software | ||
// without restriction, including without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
// to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
|
||
using System.Collections.Generic; | ||
using System.Dynamic; | ||
|
||
namespace KingAOP.Aspects | ||
{ | ||
/// <summary> | ||
/// Encapsulation of method arguments. | ||
/// </summary> | ||
public class Arguments | ||
{ | ||
private readonly List<object> _objects = new List<object>(); | ||
|
||
public Arguments(IEnumerable<DynamicMetaObject> objects) | ||
{ | ||
foreach (var obj in objects) | ||
{ | ||
_objects.Add(obj.Value); | ||
} | ||
} | ||
|
||
public object this[int index] | ||
{ | ||
get { return _objects[index]; } | ||
} | ||
|
||
public int Count | ||
{ | ||
get { return _objects.Count; } | ||
} | ||
} | ||
} |
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,33 @@ | ||
// Copyright (c) 2013 Antya Dev | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
// software and associated documentation files (the "Software"), to deal in the Software | ||
// without restriction, including without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
// to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
|
||
using System; | ||
|
||
namespace KingAOP.Aspects | ||
{ | ||
/// <summary> | ||
/// Base class for all aspects that are declared | ||
/// </summary> | ||
public abstract class Aspect : Attribute, IAspect | ||
{ | ||
/// <summary> | ||
/// Gets or sets the weaving priority of the aspect. | ||
/// </summary> | ||
public int AspectPriority { get; set; } | ||
} | ||
} |
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,32 @@ | ||
// Copyright (c) 2013 Antya Dev | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
// software and associated documentation files (the "Software"), to deal in the Software | ||
// without restriction, including without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
// to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
|
||
namespace KingAOP.Aspects | ||
{ | ||
/// <summary> | ||
/// Enumerates the possible behaviors of the calling method after the calling method has returned. | ||
/// </summary> | ||
public enum FlowBehavior | ||
{ | ||
Default, | ||
Continue, | ||
RethrowException, | ||
Return, | ||
ThrowException, | ||
} | ||
} |
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,26 @@ | ||
// Copyright (c) 2013 Antya Dev | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
// software and associated documentation files (the "Software"), to deal in the Software | ||
// without restriction, including without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
// to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
|
||
namespace KingAOP.Aspects | ||
{ | ||
/// <summary> | ||
/// Base interface for all aspects that are declared | ||
/// </summary> | ||
interface IAspect | ||
{ } | ||
} |
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,26 @@ | ||
// Copyright (c) 2013 Antya Dev | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
// software and associated documentation files (the "Software"), to deal in the Software | ||
// without restriction, including without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
// to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
|
||
namespace KingAOP.Aspects | ||
{ | ||
/// <summary> | ||
/// Base interface for all aspects which should applied to methods. | ||
/// </summary> | ||
interface IMethodAspect : IAspect | ||
{ } | ||
} |
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,66 @@ | ||
// Copyright (c) 2013 Antya Dev | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
// software and associated documentation files (the "Software"), to deal in the Software | ||
// without restriction, including without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
// to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
|
||
using System; | ||
using System.Reflection; | ||
|
||
namespace KingAOP.Aspects | ||
{ | ||
/// <summary> | ||
/// Arguments of aspect which in executing | ||
/// </summary> | ||
public sealed class MethodExecutionArgs | ||
{ | ||
public MethodExecutionArgs(object instance, MethodInfo method, Arguments arguments) | ||
{ | ||
Instance = instance; | ||
Method = method; | ||
Arguments = arguments; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the object instance on which the method is being executed. | ||
/// </summary> | ||
public object Instance { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the method being executed. | ||
/// </summary> | ||
public MethodInfo Method { get; private set; } | ||
|
||
/// <summary> | ||
/// Determines the control flow of the target method once the advice is exited. | ||
/// </summary> | ||
public FlowBehavior FlowBehavior { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the arguments with which the method has been invoked. | ||
/// </summary> | ||
public Arguments Arguments { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the method return value. | ||
/// </summary> | ||
public object ReturnValue { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the exception currently flying. | ||
/// </summary> | ||
public Exception Exception { get; set; } | ||
} | ||
} |
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,56 @@ | ||
// Copyright (c) 2013 Antya Dev | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
// software and associated documentation files (the "Software"), to deal in the Software | ||
// without restriction, including without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
// to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
|
||
namespace KingAOP.Aspects | ||
{ | ||
/// <summary> | ||
/// Represents a class that can wrap itself around any given method call. | ||
/// </summary> | ||
public abstract class OnMethodBoundaryAspect : Aspect | ||
{ | ||
/// <summary> | ||
/// Method executed before the body of method to which this aspect is applied. | ||
/// </summary> | ||
/// <param name="args">Method arguments including return value and all necessary info.</param> | ||
public virtual void OnEntry(MethodExecutionArgs args) | ||
{ } | ||
|
||
/// <summary> | ||
/// Method executed after the body of method to which this aspect is applied | ||
/// (this method is invoked from the finally block, it's mean that this method will be invoked in any way) | ||
/// </summary> | ||
/// <param name="args">Method arguments including return value and all necessary info.</param> | ||
public virtual void OnExit(MethodExecutionArgs args) | ||
{ } | ||
|
||
/// <summary> | ||
/// Method executed after the body of method to which this aspect is applied, | ||
/// but only when the method successfully returns | ||
/// </summary> | ||
/// <param name="args">Method arguments including return value and all necessary info.</param> | ||
public virtual void OnSuccess(MethodExecutionArgs args) | ||
{ } | ||
|
||
/// <summary> | ||
/// When an exception is happened then this method will be called. | ||
/// </summary> | ||
/// <param name="args">Method arguments including return value and all necessary info.</param> | ||
public virtual void OnException(MethodExecutionArgs args) | ||
{ } | ||
} | ||
} |
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,42 @@ | ||
// Copyright (c) 2013 Antya Dev | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
// software and associated documentation files (the "Software"), to deal in the Software | ||
// without restriction, including without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
// to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
|
||
using System; | ||
using System.Collections; | ||
|
||
namespace KingAOP.Core | ||
{ | ||
/// <summary> | ||
/// Represent a global aspect cache factory. | ||
/// </summary> | ||
internal class AspectCacheFactory | ||
{ | ||
private static readonly Hashtable Cache = new Hashtable(); | ||
|
||
public static object GetAspect(Type aspectType) | ||
{ | ||
var aspect = Cache[aspectType]; | ||
if (aspect == null) | ||
{ | ||
aspect = Activator.CreateInstance(aspectType); | ||
Cache[aspectType] = aspect; | ||
} | ||
return aspect; | ||
} | ||
} | ||
} |
Oops, something went wrong.