public void CopyValueTo(Result r) { if (!GetType().Equals(r.GetType())) { throw ExHelp.Argument("r", "Argument type {0} doesn't match self type {1}", r.GetType(), GetType()); } CloneTo(r); }
protected override bool ImportXml(XmlReader xr, IWarningLogger log) { // We try very hard to load composites because they are liable to // change between versions, and we don't want to trash people's // configurations. ArrayList fields = GetFieldData(); bool[] check = new bool[fields.Count]; int d = xr.Depth; while (!xr.EOF && xr.Depth >= d) { if (xr.NodeType != XmlNodeType.Element) { xr.Read(); continue; } if (xr.Name != "field") { log.Warning(3019, "Expected 'field' element inside composite but got '" + xr.Name + "' during XML import", null); xr.Read(); continue; } //Console.WriteLine ("composite doit: {0}: {1} = \"{2}\"; ac = {3}, d = {4}", xr.NodeType, xr.Name, xr.Value, // xr.AttributeCount, xr.Depth); bool is_null = false; string name = null; string decltype = null; name = xr.GetAttribute("name"); if (name == null) { log.Warning(3019, "Didn't find 'name' attribute in 'field' element during XML import", null); return(true); } decltype = xr.GetAttribute("decl_type"); if (decltype == null) { log.Warning(3019, "Didn't find 'decl_type' attribute in 'field' element during XML import; continuing", null); } if (xr.GetAttribute("is_null") != null) { is_null = true; } int i; FieldInfo fi = null; for (i = 0; i < fields.Count; i++) { fi = (FieldInfo)fields[i]; if (fi.Name == name && fi.DeclaringType.FullName == decltype) { break; } } if (!is_null) { xr.Read(); while (xr.NodeType == XmlNodeType.Whitespace) { xr.Read(); } } //Console.WriteLine ("composite after maybe read: {0}: {1} = \"{2}\"; ac = {3}, d = {4}", xr.NodeType, xr.Name, xr.Value, // xr.AttributeCount, xr.Depth); if (i == fields.Count) { log.Warning(3019, "Didn't find the field '" + name + "' in self; still trying to load. Result may need to be uncached.", null); xr.Skip(); continue; } if (is_null) { fi.SetValue(this, null); check[i] = true; continue; } string ignore; Result r = Result.ImportXml(xr, out ignore, log); if (r == null) { log.Warning(3019, "Couldn't load result for field '" + name + "'; still trying to load. Result may need to be uncached", null); continue; } try { fi.SetValue(this, r); check[i] = true; } catch (ArgumentException) { string msg = String.Format("Field {0} is of type {1}, but {2} was restored from the XML. Still trying to load. Result may" + " need to be uncached.", name, fi.MemberType, r.GetType()); log.Warning(3019, msg, r.ToString()); } } for (int i = 0; i < fields.Count; i++) { if (check[i]) { continue; } FieldInfo fi = (FieldInfo)fields[i]; log.Warning(3019, "Didn't load field '" + fi.Name + "' in composite; still trying to load. Result may need to be uncached", null); } return(false); }