/// <summary> /// Gets the properties of the specified type. /// </summary> protected virtual IEnumerable <ViewModelPropertyMap> GetProperties(Type type) { foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p => p.Name)) { if (property.GetCustomAttribute <JsonIgnoreAttribute>() != null) { continue; } var propertyMap = new ViewModelPropertyMap() { PropertyInfo = property, Name = property.Name, ViewModelProtection = ProtectMode.None, Type = property.PropertyType, TransferAfterPostback = property.GetMethod != null && property.GetMethod.IsPublic, TransferFirstRequest = property.GetMethod != null && property.GetMethod.IsPublic, TransferToServer = property.SetMethod != null && property.SetMethod.IsPublic, JsonConverter = GetJsonConverter(property), Populate = ViewModelJsonConverter.IsComplexType(property.PropertyType) && !ViewModelJsonConverter.IsEnumerable(property.PropertyType) && property.GetMethod != null }; foreach (ISerializationInfoAttribute attr in property.GetCustomAttributes().OfType <ISerializationInfoAttribute>()) { attr.SetOptions(propertyMap); } var bindAttribute = property.GetCustomAttribute <BindAttribute>(); if (bindAttribute != null) { propertyMap.Bind(bindAttribute.Direction); if (bindAttribute.Name != null) { propertyMap.Name = bindAttribute.Name; } } var viewModelProtectionAttribute = property.GetCustomAttribute <ProtectAttribute>(); if (viewModelProtectionAttribute != null) { propertyMap.ViewModelProtection = viewModelProtectionAttribute.Settings; } propertyMap.ClientExtenders = property.GetCustomAttributes <ClientExtenderAttribute>() .OrderBy(c => c.Order) .Select(extender => new ClientExtenderInfo() { Name = extender.Name, Parameter = extender.Parameter }) .ToList(); var validationAttributes = validationMetadataProvider.GetAttributesForProperty(property); propertyMap.ValidationRules = validationRuleTranslator.TranslateValidationRules(property, validationAttributes).ToList(); propertyMap.ValidateSettings(); yield return(propertyMap); } }
/// <summary> /// Gets the properties of the specified type. /// </summary> protected virtual IEnumerable <ViewModelPropertyMap> GetProperties(Type type) { foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p => p.Name)) { if (property.GetCustomAttribute <JsonIgnoreAttribute>() != null) { continue; } var propertyMap = new ViewModelPropertyMap() { PropertyInfo = property, Name = property.Name, ViewModelProtection = ProtectMode.None, Type = property.PropertyType, TransferAfterPostback = property.GetMethod != null && property.GetMethod.IsPublic, TransferFirstRequest = property.GetMethod != null && property.GetMethod.IsPublic, TransferToServer = property.SetMethod != null && property.SetMethod.IsPublic, JsonConverter = GetJsonConverter(property), Populate = ViewModelJsonConverter.IsComplexType(property.PropertyType) && !ViewModelJsonConverter.IsEnumerable(property.PropertyType) && property.GetMethod != null }; var bindAttribute = property.GetCustomAttribute <BindAttribute>(); if (bindAttribute != null) { propertyMap.TransferAfterPostback = bindAttribute.Direction.HasFlag(Direction.ServerToClientPostback); propertyMap.TransferFirstRequest = bindAttribute.Direction.HasFlag(Direction.ServerToClientFirstRequest); propertyMap.TransferToServer = bindAttribute.Direction.HasFlag(Direction.ClientToServerNotInPostbackPath) || bindAttribute.Direction.HasFlag(Direction.ClientToServerInPostbackPath); propertyMap.TransferToServerOnlyInPath = !bindAttribute.Direction.HasFlag(Direction.ClientToServerNotInPostbackPath) && propertyMap.TransferToServer; } var viewModelProtectionAttribute = property.GetCustomAttribute <ProtectAttribute>(); if (viewModelProtectionAttribute != null) { propertyMap.ViewModelProtection = viewModelProtectionAttribute.Settings; } var clientExtenderList = property.GetCustomAttributes <ClientExtenderAttribute>(); if (clientExtenderList.Any()) { clientExtenderList .OrderBy(c => c.Order) .ToList() .ForEach(extender => propertyMap.ClientExtenders.Add(new ClientExtenderInfo() { Name = extender.Name, Parameter = extender.Parameter })); } var validationAttributes = validationMetadataProvider.GetAttributesForProperty(property); propertyMap.ValidationRules = validationRuleTranslator.TranslateValidationRules(property, validationAttributes).ToList(); yield return(propertyMap); } }