Esempio 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);
        }
Esempio 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();
            }

            var 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;
        }
Esempio n. 3
0
        public static void ApplyProjection(CustomAttribute attribute, CustomAttributeValueProjection projection)
        {
            if (projection != null)
            {
                bool flag;
                bool flag2;
                switch (projection.Treatment)
                {
                case CustomAttributeValueTreatment.AllowSingle:
                    flag  = false;
                    flag2 = false;
                    break;

                case CustomAttributeValueTreatment.AllowMultiple:
                    flag  = false;
                    flag2 = true;
                    break;

                case CustomAttributeValueTreatment.VersionAttribute:
                case CustomAttributeValueTreatment.DeprecatedAttribute:
                    flag  = true;
                    flag2 = true;
                    break;

                default:
                    throw new ArgumentException();
                }
                CustomAttributeArgument customAttributeArgument = attribute.ConstructorArguments[0];
                AttributeTargets        attributeTargets        = (AttributeTargets)customAttributeArgument.Value;
                if (flag)
                {
                    attributeTargets |= (AttributeTargets.Constructor | AttributeTargets.Property);
                }
                Collection <CustomAttributeArgument> constructorArguments = attribute.ConstructorArguments;
                customAttributeArgument = attribute.ConstructorArguments[0];
                constructorArguments[0] = new CustomAttributeArgument(customAttributeArgument.Type, attributeTargets);
                attribute.Properties.Add(new CustomAttributeNamedArgument("AllowMultiple", new CustomAttributeArgument(attribute.Module.TypeSystem.Boolean, flag2)));
                attribute.projection = projection;
            }
        }
        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 ();
            }

            var 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;
        }