Click here to Skip to main content
15,896,111 members
Articles / Programming Languages / C#

Romeo and Juliet

Rate me:
Please Sign up or sign in to vote.
4.87/5 (34 votes)
3 Dec 2011CPOL11 min read 58.9K   413   67  
Making relationships first class citizens.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

using XTreeInterfaces;

namespace ROPLib
{
	public class Schema : IHasCollection
	{
		[Category("Name")]
		[XmlAttribute()]
		public string Name { get; set; }

		[XmlIgnore]
		[Browsable(false)]
		public Dictionary<string, dynamic> Collection { get; protected set; }

		[Browsable(false)]
		public List<RelationshipsContainer> RelationshipsContainer { get; set; }

		[Browsable(false)]
		public List<AttributesContainer> AttributesContainer { get; set; }

		[Browsable(false)]
		public List<EntitiesContainer> EntitiesContainer { get; set; }

		[Browsable(false)]
		public List<ListsContainer> ListsContainer { get; set; }

		[Browsable(false)]
		public List<PairsContainer> PairsContainer { get; set; }

		[XmlIgnore]
		public static Schema Instance { get; protected set; }

		public Schema()
		{
			RelationshipsContainer = new List<RelationshipsContainer>();
			AttributesContainer = new List<AttributesContainer>();
			EntitiesContainer = new List<EntitiesContainer>();
			ListsContainer = new List<ListsContainer>();
			PairsContainer = new List<PairsContainer>();
			Instance = this;

			Collection = new Dictionary<string, dynamic>() { 
				{"EntitiesContainer", EntitiesContainer},
				{"AttributesContainer", AttributesContainer},
				{"RelationshipsContainer", RelationshipsContainer},
				{"ListsContainer", ListsContainer},
				{"PairsContainer", PairsContainer},
			};
		}
	}

	public class RelationshipsContainer : IHasCollection
	{
		[XmlAttribute()]
		public string Name { get; set; }

		[XmlIgnore]
		[Browsable(false)]
		public Dictionary<string, dynamic> Collection { get; protected set; }

		// Serializable list.
		[Browsable(false)]
		public List<Relationship> Relationships { get; set; }

		public RelationshipsContainer()
		{
			Relationships = new List<Relationship>();
			Collection = new Dictionary<string, dynamic>() { 
				{"Relationship", Relationships},
			};
		}
	}

	public class AttributesContainer : IHasCollection
	{
		[XmlAttribute()]
		public string Name { get; set; }

		[XmlIgnore]
		[Browsable(false)]
		public Dictionary<string, dynamic> Collection { get; protected set; }

		// Serializable list.
		[Browsable(false)]
		public List<Attribute> Attributes { get; set; }

		public AttributesContainer()
		{
			Attributes = new List<Attribute>();
			Collection = new Dictionary<string, dynamic>() { 
				{"Attribute", Attributes},
			};
		}
	}

	public class EntitiesContainer : IHasCollection
	{
		[XmlAttribute()]
		public string Name { get; set; }

		[XmlIgnore]
		[Browsable(false)]
		public Dictionary<string, dynamic> Collection { get; protected set; }

		// Serializable list.
		[Browsable(false)]
		public List<Entity> Entities { get; set; }

		public EntitiesContainer()
		{
			Entities = new List<Entity>();
			Collection = new Dictionary<string, dynamic>() { 
				{"Entity", Entities},
			};
		}
	}

	public class ListsContainer : IHasCollection
	{
		[XmlAttribute()]
		public string Name { get; set; }

		[XmlIgnore]
		[Browsable(false)]
		public Dictionary<string, dynamic> Collection { get; protected set; }

		// Serializable list.
		[Browsable(false)]
		public List<ListOfItems> ListOfItems { get; set; }

		public ListsContainer()
		{
			ListOfItems = new List<ListOfItems>();
			Collection = new Dictionary<string, dynamic>() { 
				{"ListOfItems", ListOfItems},
			};
		}
	}

	public class PairsContainer : IHasCollection
	{
		[XmlAttribute()]
		public string Name { get; set; }

		[XmlIgnore]
		[Browsable(false)]
		public Dictionary<string, dynamic> Collection { get; protected set; }

		// Serializable list.
		[Browsable(false)]
		public List<ListOfPairs> ListOfPairs { get; set; }

		public PairsContainer()
		{
			ListOfPairs = new List<ListOfPairs>();
			Collection = new Dictionary<string, dynamic>() { 
				{"ListOfPairs", ListOfPairs},
			};
		}
	}
}









By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Interacx
United States United States
Blog: https://marcclifton.wordpress.com/
Home Page: http://www.marcclifton.com
Research: http://www.higherorderprogramming.com/
GitHub: https://github.com/cliftonm

All my life I have been passionate about architecture / software design, as this is the cornerstone to a maintainable and extensible application. As such, I have enjoyed exploring some crazy ideas and discovering that they are not so crazy after all. I also love writing about my ideas and seeing the community response. As a consultant, I've enjoyed working in a wide range of industries such as aerospace, boatyard management, remote sensing, emergency services / data management, and casino operations. I've done a variety of pro-bono work non-profit organizations related to nature conservancy, drug recovery and women's health.

Comments and Discussions