Created
July 4, 2011 12:46
-
-
Save hodzanassredin/1063294 to your computer and use it in GitHub Desktop.
Вариант для реализации других видов ооп в C#
This file contains hidden or 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
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