private bool CopmareIndicators(IChartIndicator indi1, IChartIndicator indi2) { if (indi1 == null || indi2 == null) return false; if (indi1.GetType() != indi2.GetType()) return false; var equal = true; foreach (var property in indi1.GetType().GetProperties()) { if (!property.GetCustomAttributes(true).Any(a => a is DisplayNameAttribute)) continue; if (!property.PropertyType.IsValueType) continue; if (property.PropertyType == typeof (Color)) { var c1 = (Color) property.GetValue(indi1); var c2 = (Color) property.GetValue(indi2); if (c1.ToArgb() != c2.ToArgb()) { equal = false; break; } } else if (!property.GetValue(indi1).Equals(property.GetValue(indi2))) { equal = false; break; } } return equal; }
public static void MakeIndicatorXMLNode(IChartIndicator indi, XmlNode node) { var xmlAttr = node.OwnerDocument.CreateAttribute("ClassName"); xmlAttr.Value = indi.GetType().ToString(); node.Attributes.Append(xmlAttr); foreach (var prop in indi.GetType().GetProperties()) { var attrs = prop.GetCustomAttributes(typeof(DisplayNameAttribute), true); var attr = (DisplayNameAttribute)attrs.FirstOrDefault(a => a is DisplayNameAttribute); if (attr == null) { continue; } var propVal = prop.GetValue(indi, null); // есть свой сериализатор для свойства? attrs = prop.GetCustomAttributes(typeof(CustomXmlSerializationAttribute), true); if (attrs.Length > 0) { var atrSerializer = (CustomXmlSerializationAttribute)attrs[0]; atrSerializer.SerializeProperty(propVal, node); continue; } var attrName = prop.Name; var attrVal = propVal == null ? string.Empty : prop.PropertyType == typeof(string) ? string.IsNullOrEmpty((string)propVal) ? "" : (string)propVal : prop.PropertyType == typeof(Color) ? ((Color)propVal).ToArgb().ToString() : string.Format(CultureProvider.Common, "{0}", propVal ?? "null"); xmlAttr = node.OwnerDocument.CreateAttribute(attrName); xmlAttr.Value = attrVal; node.Attributes.Append(xmlAttr); } }
private bool CopmareIndicators(IChartIndicator indi1, IChartIndicator indi2) { if (indi1 == null || indi2 == null) { return(false); } if (indi1.GetType() != indi2.GetType()) { return(false); } var equal = true; foreach (var property in indi1.GetType().GetProperties()) { if (!property.GetCustomAttributes(true).Any(a => a is DisplayNameAttribute)) { continue; } if (!property.PropertyType.IsValueType) { continue; } if (property.PropertyType == typeof(Color)) { var c1 = (Color)property.GetValue(indi1); var c2 = (Color)property.GetValue(indi2); if (c1.ToArgb() != c2.ToArgb()) { equal = false; break; } } else if (!property.GetValue(indi1).Equals(property.GetValue(indi2))) { equal = false; break; } } return(equal); }
private static void LoadIndicatorProperties(IChartIndicator indi, XmlElement node) { foreach (var prop in indi.GetType().GetProperties()) { var attrs = prop.GetCustomAttributes(typeof(DisplayNameAttribute), true); var attr = (DisplayNameAttribute)attrs.FirstOrDefault(a => a is DisplayNameAttribute); if (attr == null) { continue; } object val; // свойство само умеет себя десериализовать? attrs = prop.GetCustomAttributes(typeof(CustomXmlSerializationAttribute), true); if (attrs.Length > 0) { var atrSerializer = (CustomXmlSerializationAttribute)attrs[0]; val = atrSerializer.DeserializeProperty(node); prop.SetValue(indi, val, new object[0]); continue; } // получить атрибут узла var xmlAttr = node.Attributes[prop.Name]; if (xmlAttr == null) { continue; } // получить значение из строки if (prop.PropertyType.IsSubclassOf(typeof(Enum))) { val = Enum.Parse(prop.PropertyType, xmlAttr.Value); } else { //if (prop.Name == "ClLine") continue; if (prop.PropertyType == typeof(Color)) { val = Color.FromArgb(int.Parse(xmlAttr.Value)); } else { val = Converter.GetObjectFromString(xmlAttr.Value, prop.PropertyType); } } prop.SetValue(indi, val, new object[0]); } }
private static void LoadIndicatorProperties(IChartIndicator indi, XmlElement node) { foreach (var prop in indi.GetType().GetProperties()) { var attrs = prop.GetCustomAttributes(typeof(DisplayNameAttribute), true); var attr = (DisplayNameAttribute)attrs.FirstOrDefault(a => a is DisplayNameAttribute); if (attr == null) continue; object val; // свойство само умеет себя десериализовать? attrs = prop.GetCustomAttributes(typeof(CustomXmlSerializationAttribute), true); if (attrs.Length > 0) { var atrSerializer = (CustomXmlSerializationAttribute)attrs[0]; val = atrSerializer.DeserializeProperty(node); prop.SetValue(indi, val, new object[0]); continue; } // получить атрибут узла var xmlAttr = node.Attributes[prop.Name]; if (xmlAttr == null) continue; // получить значение из строки if (prop.PropertyType.IsSubclassOf(typeof(Enum))) val = Enum.Parse(prop.PropertyType, xmlAttr.Value); else { //if (prop.Name == "ClLine") continue; if (prop.PropertyType == typeof(Color)) val = Color.FromArgb(int.Parse(xmlAttr.Value)); else val = Converter.GetObjectFromString(xmlAttr.Value, prop.PropertyType); } prop.SetValue(indi, val, new object[0]); } }
public static void MakeIndicatorXMLNode(IChartIndicator indi, XmlNode node) { var xmlAttr = node.OwnerDocument.CreateAttribute("ClassName"); xmlAttr.Value = indi.GetType().ToString(); node.Attributes.Append(xmlAttr); foreach (var prop in indi.GetType().GetProperties()) { var attrs = prop.GetCustomAttributes(typeof(DisplayNameAttribute), true); var attr = (DisplayNameAttribute)attrs.FirstOrDefault(a => a is DisplayNameAttribute); if (attr == null) continue; var propVal = prop.GetValue(indi, null); // есть свой сериализатор для свойства? attrs = prop.GetCustomAttributes(typeof(CustomXmlSerializationAttribute), true); if (attrs.Length > 0) { var atrSerializer = (CustomXmlSerializationAttribute)attrs[0]; atrSerializer.SerializeProperty(propVal, node); continue; } var attrName = prop.Name; var attrVal = propVal == null ? string.Empty : prop.PropertyType == typeof(string) ? string.IsNullOrEmpty((string)propVal) ? "" : (string)propVal : prop.PropertyType == typeof(Color) ? ((Color)propVal).ToArgb().ToString() : string.Format(CultureProvider.Common, "{0}", propVal ?? "null"); xmlAttr = node.OwnerDocument.CreateAttribute(attrName); xmlAttr.Value = attrVal; node.Attributes.Append(xmlAttr); } }