/// <summary> /// Loads container of services. /// </summary> /// <param name="tr">XmlReader.</param> public void Load(XmlReader tr) { var converter = new StiObjectStringConverter(); StiService service = null; tr.Read(); while (tr.Read()) { if (tr.IsStartElement()) { #region service if (tr.Name == "service") { string assembly = tr.GetAttribute("assembly"); string serviceType = tr.GetAttribute("type"); if (assemlyToSkip[assembly.ToLower(System.Globalization.CultureInfo.InvariantCulture)] == null) { try { service = CreateService(assembly, serviceType); if (service != null) { Add(service, false); } } catch { } } } #endregion #region property else if (tr.Name == "property" && service != null) { string propName = tr.GetAttribute("name"); string typeStr = tr.GetAttribute("type"); var propInfo = service.GetType().GetProperty(propName); if (propInfo != null) { if (tr.GetAttribute("isNull") != null) { propInfo.SetValue(service, null, null); } else if (tr.GetAttribute("isList") != null) { int count = int.Parse(tr.GetAttribute("count")); Type elementType = StiTypeFinder.GetType(typeStr); Array list = Array.CreateInstance(elementType, count); int index = 0; while (tr.Read()) { if (tr.IsStartElement()) { string nm = tr.Name; string valueStr = tr.ReadString(); object value = converter.StringToObject(valueStr, elementType); if (value != null) { list.SetValue(value, new int[] { index++ }); } if (index >= count) { break; } } } propInfo.SetValue(service, list, null); } else { string valueStr = tr.GetAttribute("value"); object value = converter.StringToObject(valueStr, StiTypeFinder.GetType(typeStr)); if (value != null) { propInfo.SetValue(service, value, null); } } } } #endregion } } }
/// <summary> /// Returns string presentation of the service. /// </summary> /// <param name="service">Service.</param> /// <returns>String.</returns> public static string GetStringFromService(StiService service) { return(GetStringFromService(service.GetType())); }