Skip to content

Instantly share code, notes, and snippets.

@dogwith1eye
Last active March 19, 2017 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogwith1eye/7c91fca1d276591c94dfc0fa52591e55 to your computer and use it in GitHub Desktop.
Save dogwith1eye/7c91fca1d276591c94dfc0fa52591e55 to your computer and use it in GitHub Desktop.
Visit a type and returns a string representation of the type
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