/// <summary> /// 객체의 모든 속성에 대해 속성명-속성값 형식을 반환합니다. /// </summary> /// <typeparam name="T">대상 객체의 수형</typeparam> /// <param name="accessor">IDynamicAccessor{T} 인스턴스</param> /// <param name="target">대상 객체</param> /// <returns></returns> public static IEnumerable <KeyValuePair <string, object> > GetPropertyNameValueCollection <T>(this IDynamicAccessor <T> accessor, T target) { return (accessor.GetPropertyNames() .Select(name => new KeyValuePair <string, object>(name, accessor.GetPropertyValue(target, name)))); }
private static void GenerateXmlAttributes <T>(XmlWriter writer, IDynamicAccessor accessor, T instance) where T : IChartObject { foreach (var propertyName in accessor.GetPropertyNames()) { var propertyValue = accessor.GetPropertyValue(instance, propertyName); if (propertyValue != null) { Type propertyType = accessor.GetPropertyType(propertyName); if (propertyType.IsSimpleType() || propertyType.IsValueType) { if (IsDebugEnabled) { log.Debug("Property name={0}, type={1}, value={2}", propertyName, propertyType, propertyValue); } // NOTE : Color인 경우는 HexString으로, Enum 값은 HashCode 값으로... if (propertyType == typeof(Color?)) { var color = (Color?)propertyValue; writer.WriteAttributeString(propertyName, color.Value.ToHexString()); } else if (propertyType.IsEnum) { writer.WriteAttributeString(propertyName, propertyValue.GetHashCode().ToString()); } else { writer.WriteAttributeString(propertyName, propertyValue.ToString()); } } else if (propertyType.IsSameOrSubclassOf(typeof(ChartAttributeBase))) { var accessor2 = DynamicAccessorFactory.CreateDynamicAccessor(propertyType, false); GenerateXmlAttributes(writer, accessor2, propertyValue as ChartAttributeBase); } else if (TypeTool.IsSameOrSubclassOrImplementedOf(propertyType, typeof(IEnumerable))) { // Nothing to do. } else { throw new NotSupportedException(string.Format("지원하지 않는 속성입니다. property name={0}, type={1}", propertyName, propertyType.FullName)); } } } }
static IndexableCollection() { Accessor = DynamicAccessorFactory.CreateDynamicAccessor <T>(MapPropertyOptions.Safety); PropertyInfos = Accessor.PropertyMap.Values.ToArray(); PropertyNames = Accessor.GetPropertyNames(); }