KingAOPSX 1.0.0

dotnet add package KingAOPSX --version 1.0.0
NuGet\Install-Package KingAOPSX -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KingAOPSX" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KingAOPSX --version 1.0.0
#r "nuget: KingAOPSX, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install KingAOPSX as a Cake Addin
#addin nuget:?package=KingAOPSX&version=1.0.0

// Install KingAOPSX as a Cake Tool
#tool nuget:?package=KingAOPSX&version=1.0.0

#KingAOP

It's an AOP framework which is essentially a free alternative of PostSharp. If you familiar with PostSharp, then you can notice that KingAOP has even the same interfaces to interract with you:)

The concept of aspect-oriented programming (AOP) offers an interesting alternative for the specification of non-functional component properties (such as fault-tolerance properties or timing behaviour), as well as other crosscutting concerns. These are implemented as so-called aspects and at some point "weaved" to the other functional parts of the software.

##How it works? It‘s use a dynamic opportunities of C# 4.0 instead of IL rewriting technique which the PostSharp use. And that brings us to a predictable and clean model. You can look through an AOP weaving stuff in very easy way.

##Basic example:

  • Implement a hello world aspect.
class HelloWorldAspect : OnMethodBoundaryAspect
{
    public override void OnEntry(MethodExecutionArgs args)
    {
        Console.WriteLine("OnEntry: Hello KingAOP");
    }

    public override void OnExit(MethodExecutionArgs args)
    {
        Console.WriteLine("OnExit: Hello KingAOP");
    }
}
  • Add the hello aspect to some class.
class HelloWorld : IDynamicMetaObjectProvider
{
    [HelloWorldAspect]
    public void HelloWorldCall()
    {
        Console.WriteLine("Hello World");
    }

    public DynamicMetaObject GetMetaObject(Expression parameter)
    {
        return new AspectWeaver(parameter, this);
    }
}
  • Enjoy.
dynamic helloWorld = new HelloWorld();
helloWorld.HelloWorldCall();

##Logging example: Using the above studied concept, we will now attempt to develop a simple logger which will use AOP to log information. It’s canonical example of AOP, as without it:). Like with PostSharp we have to inherit from the OnMethoBoundaryAspect and override the OnEntry and OnExit methods.

  • Create LoggingAspect.
internal class LoggingAspect : OnMethodBoundaryAspect
{
    public override void OnEntry(MethodExecutionArgs args)
    {
        string logData = CreateLogData("Entering", args);
        Console.WriteLine(logData);
    }

    public override void OnExit(MethodExecutionArgs args)
    {
        string logData = CreateLogData("Leaving", args);
        Console.WriteLine(logData);
    }
    
    private string CreateLogData(string methodStage, MethodExecutionArgs args)
    {
        var str = new StringBuilder();
        str.AppendLine();
        str.AppendLine(string.Format(methodStage + " {0} ", args.Method));
        foreach (var argument in args.Arguments)
        {
            var argType = argument.GetType();

            str.Append(argType.Name + ": ");

            if (argType == typeof(string) || argType.IsPrimitive)
            {
                str.Append(argument);
            }
            else
            {
                foreach (var property in argType.GetProperties())
                {
                    str.AppendFormat("{0} = {1}; ",
                        property.Name, property.GetValue(argument, null));
                }
            }
        }
        return str.ToString();
    }
}
Product Compatible and additional computed target framework versions.
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 1,138 10/23/2018

Initial Version.