public void Parse(string text) { Condition.Requires(text).IsNotNullOrEmpty(); var list = LengthEncoder.LengthDecodeList(text); List <INodeValueManager> plugins = null; //strategy to load the managers (via assembly interrogation/plugin loading) Action initPlugins = () => { TypeContainer <INodeValueManager> types = TypeContainer <INodeValueManager> .NewDefault(); plugins = new List <INodeValueManager>(); foreach (var each in types.ContainedTypes) { try { INodeValueManager mgr = Activator.CreateInstance(each) as INodeValueManager; if (list.Contains(mgr.Id)) { plugins.Add(mgr); } } catch { } } }; //hydrate the managers list in the specified order var newList = new List <INodeValueManager>(); foreach (var each in list) { //get the mgr by id from the current managers (we want to use managers that we've explicitly added, first) // if it can't be found, get it from the plugins var mgr = this.ValueManagers.Find(x => x.Id == each); if (mgr == null) { //we can't find the manager so load the plugins if (plugins == null) { initPlugins(); } mgr = plugins.Find(x => x.Id == each); } Condition.Requires(mgr).IsNotNull(); newList.Add(mgr); } this.ValueManagers = newList; }
private SerializationManager() { this.Store = new NaturalInMemoryStore().IsOfUniqueId <ISerializationUtil>(); //hydrate it by loading types var types = TypeContainer <ISerializationUtil> .NewDefault(); types.ContainedTypes.WithEach(x => { try { var instance = Activator.CreateInstance(x); var ser = instance as ISerializationUtil; this.Store.SaveItem(ser); } catch { } }); }