Exemplo n.º 1
0
        private CountAttribute GetCountAttribute(ParameterDefinition parameter)
        {
            var attribute = parameter.GetCustomAttribute(AttributeNames.Count, throwIfNoneFound: false);

            if (attribute is null)
            {
                return(null);
            }

            return(new CountAttribute
            {
                Count = GetAttributeField <int>(attribute, nameof(CountAttribute.Count)),
                Parameter = GetAttributeField <string>(attribute, nameof(CountAttribute.Parameter)),
                Computed = GetAttributeField <string>(attribute, nameof(CountAttribute.Computed))
            });
        }
        /// <summary>
        /// Walk from the parameter up to the containing type, looking for an instance
        /// of the specified attribute type, returning it if found.
        /// </summary>
        /// <param name="parameter">The parameter to check.</param>
        /// <param name="attributeType">The attribute type to look for.</param>
        private static CustomAttribute GetHierarchicalAttributeOrNull(ParameterDefinition parameter, Type attributeType)
        {
            if (parameter == null)
            {
                return(null);
            }

            var attribute = parameter.GetCustomAttribute(attributeType);

            if (attribute != null)
            {
                return(attribute);
            }

            var method = parameter.Method as MethodDefinition;

            if (method == null)
            {
                return(null);
            }
            return(GetHierarchicalAttributeOrNull(method, attributeType));
        }