Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
Created July 4, 2011 12:46
Show Gist options
  • Save hodzanassredin/1063294 to your computer and use it in GitHub Desktop.
Save hodzanassredin/1063294 to your computer and use it in GitHub Desktop.
Вариант для реализации других видов ооп в C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FpCs
{
class Program
{
static void Main(string[] args)
{
var str = "I before inc = ";
Action<Proto> log = (p) => Console.WriteLine(str + p.I());
var test = new Proto();
test.AddBefore(ref test.inc, log);
test.inc();
test.inc();
test.dec();
test.inc();
Console.ReadKey();
}
}
public class Proto
{
public Proto()
{
var i = 0;
inc = () => i++;
dec = () => i--;
I = () => i;
}
public Action inc;
public Action dec;
public Func<int> I;
public void AddBefore(ref Action action, Action<Proto> beforHandler)
{
var old = action;
action = () => { beforHandler(this); old(); };
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment