Skip to content

Instantly share code, notes, and snippets.

@jmhdez
Last active December 20, 2015 11:19
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 jmhdez/6122223 to your computer and use it in GitHub Desktop.
Save jmhdez/6122223 to your computer and use it in GitHub Desktop.
Compartiendo elementos en posiciones dependientes del contenedor
public interface IElement
{
IEnumerable<ChildElement> Children { get; }
}
public class ChildElement
{
public readonly IElement Value;
public readonly Point Point;
public ChildElement(int x, int y, IElement value)
{
Point = new Point(x, y);
Value = value;
}
}
public class Container : IElement
{
private readonly ISet<ChildElement> children = new HashSet<ChildElement>();
public Container Add(int x, int y, IElement child)
{
children.Add(new ChildElement(x, y, child));
return this;
}
public IEnumerable<ChildElement> Children
{
get { return children.AsEnumerable();
}
}
var shared = new FormElement();
var page1 = new Container()
.Add(3, 1, new CircleElement(radius: 6))
.Add(25, 25, shared);
.Add(10, 50, new Container()
.Add(1, 1, new TextElement(text: "Sample Text Element"))
.Add(5, 5, new BoxElement(width: 100, height: 25)));
var page2 = new Container()
.Add(4, 4, new TitleElement(text: "The Title of this Page"))
.Add(10, 10, shared);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment