public SerializableObjectInfo(Type type) { foreach (var propInfo in type.GetProperties()) { var serializerAttributes = propInfo.GetCustomAttributes(typeof(PropertySerializerAttribute), false); var nameAttributes = propInfo.GetCustomAttributes(typeof(PropertyNameAttribute), false); var descAttributes = propInfo.GetCustomAttributes(typeof(PropertyDescriptionAttribute), false); if (serializerAttributes.Length > 0 && nameAttributes.Length > 0) { var info = new SerializablePropertyInfo { PropertyInfo = propInfo, Serializer = ((PropertySerializerAttribute)serializerAttributes[0]).Serializer, Name = ((PropertyNameAttribute)nameAttributes[0]).Name, }; if (descAttributes.Length > 0) { info.Description = ((PropertyDescriptionAttribute)descAttributes[0]).Description; } if (string.IsNullOrEmpty(info.Name) == true || info.Serializer == null) { throw new InvalidOperationException(); } this.Properties.Add(info.Name, info); } } }
public SerializableObjectInfo(Type type) { foreach (var propInfo in type.GetProperties()) { var serializerAttributes = propInfo.GetCustomAttributes(typeof(PropertySerializerAttribute), false); var nameAttributes = propInfo.GetCustomAttributes(typeof(PropertyNameAttribute), false); var descAttributes = propInfo.GetCustomAttributes(typeof(PropertyDescriptionAttribute), false); if (serializerAttributes.Length > 0 && nameAttributes.Length > 0) { var info = new SerializablePropertyInfo(); info.PropertyInfo = propInfo; info.Serializer = ((PropertySerializerAttribute)serializerAttributes[0]).Serializer; info.Name = ((PropertyNameAttribute)nameAttributes[0]).Name; if (descAttributes.Length > 0) { info.Description = ((PropertyDescriptionAttribute)descAttributes[0]).Description; } if (String.IsNullOrEmpty(info.Name) == true || info.Serializer == null) { throw new InvalidOperationException(); } this.Properties.Add(info.Name, info); } } }