public Dictionary <PropertyInfo, PropertyMapping> FindAllowedProperties( TypeInfo objectType, DescriptorActions actions = DescriptorActions.Read, string[] whitelist = null, string[] blacklist = null) { if (objectType == null) { throw new ArgumentNullException(nameof(objectType)); } var actionable = new Dictionary <PropertyInfo, PropertyMapping>(); var ignoreIsWritable = !actions.HasFlag(DescriptorActions.Read); foreach (var pi in objectType.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { var attributes = pi.GetCustomAttributes(true); if ((ignoreIsWritable || pi.CanWrite) && IsActionableProperty(pi, attributes, actions)) { actionable.Add(pi, new PropertyMapping(pi, ResolveAlias(pi, attributes))); } } return(actionable); }
/// <summary> /// Determines whether the specified property is restricted declaratively. /// </summary> /// <param name="propertyInfo">The property information.</param> /// <param name="attributes">The attributes.</param> /// <param name="actions">The actions.</param> /// <returns><c>true</c> if [is allowed by attribute] then [the specified property information]; otherwise, <c>false</c>.</returns> protected virtual bool IsAllowedByAttributes( PropertyInfo propertyInfo, object[] attributes, DescriptorActions actions) { var result = true; if (attributes.Length > 0) { var allowedActions = attributes.OfType <AllowedActionsAttribute>().FirstOrDefault(); result = (allowedActions == null || (allowedActions.Actions & actions) != 0); result = result && !attributes.Any(a => CommandManager.Instance.Bootstrapper.RetrieveIgnoredPropertyAttributes() .Contains(a.GetType())); } return(result); }
public Dictionary<PropertyInfo, PropertyMapping> FindAllowedProperties( Type objectType, DescriptorActions actions = DescriptorActions.Read, string[] whitelist = null, string[] blacklist = null) { if (objectType == null) throw new ArgumentNullException(nameof(objectType)); var actionable = new Dictionary<PropertyInfo, PropertyMapping>(); var ignoreIsWritable = !actions.HasFlag(DescriptorActions.Read); foreach (var pi in objectType.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { var attributes = pi.GetCustomAttributes(true); if ((ignoreIsWritable || pi.CanWrite) && IsActionableProperty(pi, attributes, actions)) actionable.Add(pi, new PropertyMapping(pi, ResolveAlias(pi, attributes))); } return actionable; }
/// <summary> /// Determines whether the specified property is actionable. /// </summary> /// <param name="propertyInfo">The property information.</param> /// <param name="customAttributes">The custom attributes.</param> /// <param name="actions">The actions.</param> /// <param name="whitelist">The whitelist.</param> /// <param name="blacklist">The blacklist.</param> /// <returns><c>true</c> if [is actionable property] [the specified property information]; otherwise, <c>false</c>.</returns> /// <exception cref="System.ArgumentNullException">propertyInfo /// or /// customAttributes</exception> protected virtual bool IsActionableProperty( PropertyInfo propertyInfo, object[] customAttributes, DescriptorActions actions = DescriptorActions.Read, string[] whitelist = null, string[] blacklist = null) { if (propertyInfo == null) { throw new ArgumentNullException(nameof(propertyInfo)); } if (customAttributes == null) { throw new ArgumentNullException(nameof(customAttributes)); } var isActionable = IsWhitelisted(propertyInfo, whitelist) || (!(IsBlacklisted(propertyInfo, blacklist)) && IsAllowedByAttributes(propertyInfo, customAttributes, actions)); return(isActionable); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultResultMapping" /> class. /// </summary> /// <param name="propertyMetadataExtractor">The property metadata extractor.</param> /// <param name="resultType">Type of the result.</param> /// <param name="actions">The actions.</param> public DefaultResultMapping(IPropertyMetadataExtractor propertyMetadataExtractor, Type resultType, DescriptorActions actions = DescriptorActions.Read) { _propertyMetadataExtractor = propertyMetadataExtractor; _resultType = resultType; _actions = actions; }
/// <summary> /// Initializes a new instance of the <see cref="AllowedActionsAttribute" /> class. /// </summary> /// <param name="actions">The actions in which this property is allowed to participate.</param> public AllowedActionsAttribute(DescriptorActions actions) { Actions = actions; }
/// <summary> /// Determines whether the specified property is restricted declaratively. /// </summary> /// <param name="propertyInfo">The property information.</param> /// <param name="attributes">The attributes.</param> /// <param name="actions">The actions.</param> /// <returns><c>true</c> if [is allowed by attribute] then [the specified property information]; otherwise, <c>false</c>.</returns> protected virtual bool IsAllowedByAttributes( PropertyInfo propertyInfo, object[] attributes, DescriptorActions actions) { var result = true; if (attributes.Length > 0) { var allowedActions = attributes.OfType<AllowedActionsAttribute>().FirstOrDefault(); result = (allowedActions == null || (allowedActions.Actions & actions) != 0); result = result && !attributes.Any(a => CommandManager.Instance.Bootstrapper.RetrieveIgnoredPropertyAttributes() .Contains(a.GetType())); } return result; }
/// <summary> /// Determines whether the specified property is actionable. /// </summary> /// <param name="propertyInfo">The property information.</param> /// <param name="customAttributes">The custom attributes.</param> /// <param name="actions">The actions.</param> /// <param name="whitelist">The whitelist.</param> /// <param name="blacklist">The blacklist.</param> /// <returns><c>true</c> if [is actionable property] [the specified property information]; otherwise, <c>false</c>.</returns> /// <exception cref="System.ArgumentNullException">propertyInfo /// or /// customAttributes</exception> protected virtual bool IsActionableProperty( PropertyInfo propertyInfo, object[] customAttributes, DescriptorActions actions = DescriptorActions.Read, string[] whitelist = null, string[] blacklist = null) { if (propertyInfo == null) throw new ArgumentNullException(nameof(propertyInfo)); if (customAttributes == null) throw new ArgumentNullException(nameof(customAttributes)); var isActionable = IsWhitelisted(propertyInfo, whitelist) || (!(IsBlacklisted(propertyInfo, blacklist)) && IsAllowedByAttributes(propertyInfo, customAttributes, actions)); return isActionable; }