public IInitContext AcquireInitContext(InitOptions initOptions) { if (this.contexts == null) { this.contexts = new Stack <InitialisationContext>(); } var context = new InitialisationContext(this, initOptions); this.contexts.Push(context); return(context); }
internal Entity(IEnumerable <IProperty> properties, IEnumerable <Behaviour> behaviours, EntityVersion version) { this.Version = version; // create public read-only collections this.propertiesList = new List <IProperty>(properties); this.behavioursList = new List <Behaviour>(behaviours); this.Properties = new ReadOnlyCollection <IProperty>(propertiesList); this.Behaviours = new ReadOnlyCollection <Behaviour>(behavioursList); // add properties this.properties = new Dictionary <string, IProperty>(); foreach (var item in Properties) { this.properties.Add(item.Name, item); } // sort behaviours by their type var catagorised = new Dictionary <Type, List <Behaviour> >(); foreach (var item in Behaviours) { CatagoriseBehaviour(catagorised, item); item.Owner = this; } // add behaviours this.behaviours = new Dictionary <Type, Behaviour[]>(); foreach (var item in catagorised) { this.behaviours.Add(item.Key, item.Value.ToArray()); } // create initialisation context this.initialisationContext = new InitialisationContext(this); // allow behaviours to add their own properties CreateProperties(); }