Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Delegates/F-Sharp/delegates.fs
Normal file
26
Task/Delegates/F-Sharp/delegates.fs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
type Delegator() =
|
||||
let defaultOperation() = "default implementation"
|
||||
let mutable del = null
|
||||
|
||||
// write-only property "Delegate"
|
||||
member x.Delegate with set(d:obj) = del <- d
|
||||
|
||||
member x.operation() =
|
||||
if del = null then
|
||||
defaultOperation()
|
||||
else
|
||||
match del.GetType().GetMethod("thing", [||]) with
|
||||
| null -> defaultOperation()
|
||||
| thing -> thing.Invoke(del, [||]) :?> string
|
||||
|
||||
type Delegate() =
|
||||
member x.thing() = "delegate implementation"
|
||||
|
||||
let d = new Delegator()
|
||||
assert (d.operation() = "default implementation")
|
||||
|
||||
d.Delegate <- "A delegate may be any object"
|
||||
assert (d.operation() = "default implementation")
|
||||
|
||||
d.Delegate <- new Delegate()
|
||||
assert (d.operation() = "delegate implementation")
|
||||
Loading…
Add table
Add a link
Reference in a new issue