Skip to content

Instantly share code, notes, and snippets.

View mgroves's full-sized avatar

Matthew D. Groves mgroves

View GitHub Profile
@mgroves
mgroves / gist:1756948
Created February 7, 2012 03:26
kitchen sink Action Filter
[MyCustomControllerAttribute1]
[MyCustomControllerAttribute2]
public class HomeController : Controller
{
public ActionExecutingContext FilterContext;
[KitchenSinkActionExecutingFilter]
[MyCustomActionAttribute1]
[MyCustomActionAttribute2]
public ActionResult Index(string id, string anotherParam)
@mgroves
mgroves / gist:1777078
Created February 9, 2012 03:38
SheepAspect Hello World
using System;
using SheepAspect.Attributes;
using SheepAspect.Runtime;
namespace SheepAspectExample
{
class Program
{
static void Main(string[] args)
{
// better like this?
var isMyFavoriteLetter = new List<string> { "A", "B", "C"}.Contains(myFavoriteLetter);
// or better like this?
var isMyFavoriteLetter = myFavoriteLetter == "A" || myFavoriteLetter == "B" || myFavoriteLetter == "C";
@mgroves
mgroves / gist:1830804
Created February 14, 2012 21:50
Simple trace aspect in PostSharp
[Serializable]
public class TraceAttribute : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionEventArgs args)
{
Trace.TraceInformation("Entering {0}.", args.Method);
}
public override void OnExit(MethodExecutionEventArgs args)
{
@mgroves
mgroves / CustomerController.cs
Created February 15, 2012 03:38
Audit ActionFilter in ASP.NET MVC
public class CustomerController : Controller
{
public ViewResult Index()
{
return View();
}
public ViewResult Edit()
{
var existingCustomer = new Customer();
@mgroves
mgroves / gist:1833093
Created February 15, 2012 04:03
OnActionExecuted kitchen sink
[MyCustomControllerAttribute1]
[MyCustomControllerAttribute2]
public class HomeController : Controller
{
public ActionExecutedContext FilterExecutedContext;
public ActionResult Index(string id, string anotherParam)
{
return View();
}
@mgroves
mgroves / Person1.cs
Created February 22, 2012 15:30
notifypropertyweaver example
// this is how your code might look without using notifypropertyweaver
public class Person1 : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
@mgroves
mgroves / gist:1897521
Created February 24, 2012 04:11
PrototypeJS AOP
<html>
<head>
<title>Javascript AOP Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js" type="text/javascript"></script>
<script type="text/javascript">
String.prototype.capitalize = String.prototype.capitalize.wrap(
function(callOriginal, eachWord) {
if (eachWord && this.include(" ")) {
// capitalize each word in the string
return this.split(" ").invoke("capitalize").join(" ");
@mgroves
mgroves / gist:1970694
Created March 4, 2012 04:41
more AOP terminology
public class MyClass
{
[MyAspect]
public void MyMethod()
{
Console.WriteLine("inside of my method");
}
}
[Serializable]
@mgroves
mgroves / gist:2023152
Created March 12, 2012 16:25
OnResultExecuting Kitchen Sink
// in the controller class
[KitchenSinkresultExecutingFilter]
public ActionResult OnResultExecuting(string id, string anotherParam)
{
return View();
}
// outside the controller class
public class KitchenSinkresultExecutingFilterAttribute : ActionFilterAttribute
{