// Copy Constructor via reflection public TestEntity(TestEntity msg) { // get all the fields in the class FieldInfo[] fields_of_class = this.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); // copy each value over to 'this' foreach (FieldInfo fi in fields_of_class) { fi.SetValue(this, fi.GetValue(msg)); } }
public static TestObj ExtructTestFromFile(string fileName) { string detail = string.Empty; if (string.IsNullOrEmpty(fileName)) return null; var test = new TestObj(); TestEntity testEntity = null; bool tmpEntityEnable = false; string tmpEntityName = string.Empty; fileName = fileName.Replace("&", "&").Replace("<", "<").Replace(">", ">");//encode special characters -The characters &, <, and > are replaced with &, <, and >, respectively using (XmlReader reader = XmlReader.Create(fileName)) { while (reader.Read()) { // Only detect start elements. if (reader.IsStartElement()) { // Get element name and switch on it. switch (reader.Name) { case "Test": test = new TestObj(); break; case "Enable": tmpEntityEnable = bool.Parse(reader.ReadInnerXml()); break; case "Description": detail = reader.ReadInnerXml(); detail.Replace("&", "&").Replace("<", "<").Replace(">", ">");//encode special characters -The characters &, <, and > are replaced with &, <, and >, respectively test.Description = detail; break; case "Script": tmpEntityEnable = false; tmpEntityName = string.Empty; break; case "Comment"://here we add the new test entity (on the last property of the entity) tmpEntityName = tmpEntityName.Replace("&", "&").Replace("<", "<").Replace(">", ">"); testEntity = new TestEntity(ExtructScriptFromFile(tmpEntityName), tmpEntityName); detail = reader.ReadInnerXml(); detail = detail.Replace("&", "&").Replace("<", "<").Replace(">", ">");//encode special characters -The characters &, <, and > are replaced with &, <, and >, respectively testEntity.Comment = detail; testEntity.Enable = tmpEntityEnable; test.Entities.Add(testEntity); //tmpEntityName = reader.ReadInnerXml(); //tmpEntityName= tmpEntityName.Replace("&", "&").Replace("<", "<").Replace(">", ">");//encode special characters -The characters &, <, and > are replaced with &, <, and >, respectively //testEntity = new TestEntity(ExtructScriptFromFile(tmpEntityName), tmpEntityName); //testEntity.Comment = reader.ReadInnerXml(); //testEntity.Enable = tmpEntityEnable; //test.Entities.Add(testEntity); break; case "Name": detail = reader.ReadInnerXml(); detail.Replace("&", "&").Replace("<", "<").Replace(">", ">");//encode special characters -The characters &, <, and > are replaced with &, <, and >, respectively tmpEntityName = detail; break; case "Params": detail = reader.ReadInnerXml(); detail = detail.Replace("&", "&").Replace("<", "<").Replace(">", ">");//encode special characters -The characters &, <, and > are replaced with &, <, and >, respectively testEntity.Params = detail; break; } } } } return test; }
private void AddNodeToList(string name) { if (string.IsNullOrEmpty(name)) return; //add scripts to test list if (name.Contains(StaticFields.SCRIPT_EXTENTION)) //filter other buttons { var s = new TestEntity(FileHandler.ExtructScriptFromFile(name), name); s.Enable = true; Singleton.Instance<SaveData>().Test.Entities.Add(s); OnPropertyChanged("TestEntitiesList"); } //add test to suite if (name.Contains(StaticFields.TEST_EXTENTION)) //filter other buttons { var t = new TestSuiteEntity(FileHandler.ExtructTestFromFile(name), name); t.Enable = true; Singleton.Instance<SaveData>().TestSuite.Entities.Add(t); // SelectedSuiteName = null;//reseting the suite name (the user can't execute un saved suite) OnPropertyChanged("TestGroupList"); } }
public void AddTestEntity(TestEntity entity) { entity.Enable = true; Test.Entities.Add(entity); }