Ejemplo n.º 1
0
        public static CustomAttributeValueProjection RemoveProjection(CustomAttribute attribute)
        {
            if (attribute.projection == null)
            {
                return(null);
            }

            CustomAttributeValueProjection projection = attribute.projection;

            attribute.projection = null;

            attribute.ConstructorArguments[0] = new CustomAttributeArgument(attribute.ConstructorArguments[0].Type, projection.Targets);
            attribute.Properties.Clear();

            return(projection);
        }
Ejemplo n.º 2
0
        public static void ApplyProjection(CustomAttribute attribute, CustomAttributeValueProjection projection)
        {
            if (projection == null)
            {
                return;
            }

            bool version_or_deprecated;
            bool multiple;

            switch (projection.Treatment)
            {
            case CustomAttributeValueTreatment.AllowSingle:
                version_or_deprecated = false;
                multiple = false;
                break;

            case CustomAttributeValueTreatment.AllowMultiple:
                version_or_deprecated = false;
                multiple = true;
                break;

            case CustomAttributeValueTreatment.VersionAttribute:
            case CustomAttributeValueTreatment.DeprecatedAttribute:
                version_or_deprecated = true;
                multiple = true;
                break;

            default:
                throw new ArgumentException();
            }

            AttributeTargets attribute_targets = (AttributeTargets)attribute.ConstructorArguments[0].Value;

            if (version_or_deprecated)
            {
                attribute_targets |= AttributeTargets.Constructor | AttributeTargets.Property;
            }

            attribute.ConstructorArguments[0] = new CustomAttributeArgument(attribute.ConstructorArguments[0].Type, attribute_targets);

            attribute.Properties.Add(new CustomAttributeNamedArgument("AllowMultiple", new CustomAttributeArgument(attribute.Module.TypeSystem.Boolean, multiple)));

            attribute.projection = projection;
        }