public static void WriteChartElement(this IChartElement element, BindingFlags bindingFlags, XmlWriter writer) { if (element == null) { return; } var elementType = element.GetType(); if (IsDebugEnabled) { log.Debug(@"타입[{0}]에서 속성 중에 XmlElement로 빌드할 정보를 생성합니다.", elementType.FullName); } var fields = elementType.Fields().ToList(); var properties = elementType.Properties(bindingFlags).ToList(); var elements = properties.Where( pi => pi.PropertyType.IsSameOrSubclassOf(ChartElementType) || (pi.PropertyType.IsSameOrSubclassOf(typeof(IEnumerable <>)) && pi.PropertyType != typeof(string))).ToArray(); foreach (var pi in elements) { var name = pi.Name; if (IsDebugEnabled) { log.Debug(@"IChartElement 속성 [{0}]을 Xml Element로 생성합니다.", name); } var fieldName = FasterflectTool.GetMemberName(name, MemberNamingRule.CamelCaseUndercore); var fieldValueExists = fields.Any(fi => fi.Name == fieldName) && (element.TryGetFieldValue(fieldName) != null); if (fieldValueExists) { var elem = element.TryGetPropertyValue(name); if (elem != null) { if (elem is IChartElement) { ((IChartElement)elem).WriteXmlElement(writer); } else if (elem is IEnumerable) { foreach (var x in (IEnumerable)elem) { if (x != null && x is IChartElement) { ((IChartElement)x).WriteXmlElement(writer); } } } } } } }
// /// <summary> // /// 지정한 타입의 인스턴스를 동적으로 생성한다. // /// </summary> // /// <param name="type">타입</param> // /// <returns>동적으로 생성된 인스턴스</returns> // public static object CreateInstance(this Type type) // { //#if !SILVERLIGHT // return FasterflectTool.GetConstructorInvoker(type)(); //#else // return Activator.CreateInstance(type); //#endif // } #if !SILVERLIGHT /// <summary> /// 지정한 타입의 인스턴스를 동적으로 생성한다. /// </summary> /// <param name="type">타입</param> /// <returns>동적으로 생성된 인스턴스</returns> /// <param name="bindingFlags">Binding Flags</param> public static object CreateInstance(this Type type, BindingFlags bindingFlags) { if (IsDebugEnabled) { log.Debug("수형[{0}]을 동적으로 생성합니다. bindingFlags=[{1}]", type.FullName, bindingFlags); } return(FasterflectTool.GetConstructorInvoker(type, bindingFlags)()); }
public static void WriteChartAttribute(this IChartAttribute attribute, BindingFlags bindingFlags, XmlWriter writer) { if (attribute == null) { return; } var attributeType = attribute.GetType(); var fields = attributeType.Fields().ToList(); var properties = attributeType.Properties(bindingFlags).ToList(); var attributes = properties.Where(pi => pi.PropertyType.IsSameOrSubclassOf(ChartAttributeType)).ToArray(); var elements = properties.Where( pi => pi.PropertyType.IsSameOrSubclassOf(ChartElementType) || (pi.PropertyType.IsSameOrSubclassOf(typeof(IEnumerable <>)) && pi.PropertyType != typeof(string))).ToArray(); var valueProperties = properties.Except(attributes).Except(elements).ToList(); var writtenPropertyNames = new List <string>(); var prefix = string.Empty; // NOTE: Prefix가 있는 Attribute는 중복이 생길 수 있다!!! if (attributeType.Properties().Any(pi => pi.Name == "Prefix")) { prefix = attribute.GetPropertyValue("Prefix").AsText(); if (IsDebugEnabled) { log.Debug("[{0}]의 Prefix는 [{1}] 입니다.", attributeType.Name, prefix); } } foreach (var pi in valueProperties.Where(pi => pi.GetGetMethod(true) != null)) { var name = pi.Name; if (name == "Prefix") { continue; } if (name == "ElementName") { continue; } if (IsDebugEnabled) { log.Debug(@"속성정보를 XmlAttribute로 빌드하려고 합니다... PropertyName=" + name); } if (writtenPropertyNames.Contains(name) == false) { var value = attribute.GetPropertyValue(name); if (value != null) { if (IsDebugEnabled) { log.Debug(@"속성 값을 Xml Attribute로 빌드합니다., Property Name=[{0}], Value=[{1}]", prefix + name, value.ToFusionXmlString()); } writer.WriteAttributeString(prefix + name, value.ToFusionXmlString()); writtenPropertyNames.Add(name); } } } foreach (var pi in attributes) { var name = pi.Name; var fieldName = FasterflectTool.GetMemberName(name, MemberNamingRule.CamelCaseUndercore); var fieldValueExists = fields.Any(fi => fi.Name == fieldName) && (attribute.TryGetFieldValue(fieldName) != null); if (fieldValueExists) { var attr = attribute.TryGetPropertyValue(name); if (attr != null && attr is IChartAttribute) { WriteChartAttribute((IChartAttribute)attr, bindingFlags, writer); } } } }