/// <summary> /// Adds the block. /// </summary> /// <param name="block">The block.</param> public BaseConfigBlock AddBlock(BaseConfigBlock block) { if (block == null) { throw new ArgumentNullException("block"); } if (this.ContainsBlock(block.GetType())) { throw new ArgumentException("Block alredy added.", "block"); } _blockHash.Add(block.GetType(), block); return(block); }
public void Load(string xml) { if (xml == null || xml == string.Empty) { return; } /* * <IncidentBoxDocument> * <Block Type=""> * <Param Name="" Type="" Value="" /> * </Block> * </IncidentBoxDocument> */ XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); // List and load block foreach (XmlNode xmlBlockNode in xmlDoc.SelectNodes("IncidentBoxDocument/Block")) { BaseConfigBlock CurrentBlock = null; string TypeName = xmlBlockNode.Attributes["Type"] != null?xmlBlockNode.Attributes["Type"].Value:typeof(BaseConfigBlock).AssemblyQualifiedName; Type BoxType = LoadType(TypeName); CurrentBlock = this.GetBlock(BoxType); if (CurrentBlock == null) { // Register a new block CurrentBlock = this.AddBlock((BaseConfigBlock)Activator.CreateInstance(BoxType)); } // List And Load Params foreach (XmlNode xmlParam in xmlBlockNode.SelectNodes("Param")) { string Name = xmlParam.Attributes["Name"].Value; string Value = xmlParam.Attributes["Value"] != null?xmlParam.Attributes["Value"].Value:null; string Type = xmlParam.Attributes["Type"] != null?xmlParam.Attributes["Type"].Value:null; CurrentBlock.Params.Add(Name, GetValueFromString(Type, Value)); } } }