Last active
March 19, 2017 17:09
-
-
Save dogwith1eye/7c91fca1d276591c94dfc0fa52591e55 to your computer and use it in GitHub Desktop.
Visit a type and returns a string representation of the type
This file contains 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
interface IShowable<T> | |
{ | |
T Value { get; } | |
U Accept<U>(IVisitor<T, U> visitor); | |
} | |
class ShowVisitor : IVisitor<string, string>, | |
IVisitor<int, string>, | |
IVisitor<float, string> | |
{ | |
public string Visit(string t) | |
{ | |
return t; | |
} | |
public string Visit(int t) | |
{ | |
return t.ToString(); | |
} | |
public string Visit(float t) | |
{ | |
return t.ToString(); | |
} | |
public string Show<T>(IShowable<T> showable) | |
{ | |
return showable.Accept(this as IVisitor<T, string>); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment