Пример #1
0
        public SourceFieldSymbol(
            SourceTypeSymbol type, string name, Location location, Accessibility accessibility,
            PHPDocBlock phpdoc, PhpPropertyKind kind,
            BoundExpression initializer = null,
            ImmutableArray <AttributeData> attributes = default)
        {
            Contract.ThrowIfNull(type);
            Contract.ThrowIfNull(name);

            _containingType = type;
            _fieldName      = name;
            _fieldKind      = kind;
            _accessibility  = accessibility;
            _initializer    = initializer;
            _location       = location;
            _attributes     = attributes.IsDefault ? ImmutableArray <AttributeData> .Empty : attributes;
            PHPDocBlock     = phpdoc;

            // implicit attributes from PHPDoc
            var deprecated = phpdoc?.GetElement <PHPDocBlock.DeprecatedTag>();

            if (deprecated != null)
            {
                // [ObsoleteAttribute(message, false)]
                _attributes = _attributes.Add(DeclaringCompilation.CreateObsoleteAttribute(deprecated));
            }
        }
Пример #2
0
        public override ImmutableArray <AttributeData> GetAttributes()
        {
            var attrs = _customAttributes;

            // attributes from syntax node
            if (attrs.IsDefaultOrEmpty)
            {
                attrs = ImmutableArray <AttributeData> .Empty;
            }
            else
            {
                // initialize attribute data if necessary:
                attrs
                .OfType <SourceCustomAttribute>()
                .ForEach(x => x.Bind(this, _containingType.ContainingFile));
            }

            // attributes from PHPDoc
            if (_phpDoc != null)
            {
                var deprecated = _phpDoc.GetElement <PHPDocBlock.DeprecatedTag>();
                if (deprecated != null)
                {
                    // [ObsoleteAttribute(message, false)]
                    attrs = attrs.Add(DeclaringCompilation.CreateObsoleteAttribute(deprecated));
                }

                // ...
            }


            //
            return(attrs);
        }
Пример #3
0
        public override ImmutableArray <AttributeData> GetAttributes()
        {
            // attributes from syntax node
            if (this.Syntax.TryGetCustomAttributes(out var attrs))
            {
                // initialize attribute data if necessary:
                attrs
                .OfType <SourceCustomAttribute>()
                .ForEach(x => x.Bind(this, this.ContainingFile));
            }
            else
            {
                attrs = ImmutableArray <AttributeData> .Empty;
            }

            // attributes from PHPDoc
            var phpdoc = this.PHPDocBlock;

            if (phpdoc != null)
            {
                var deprecated = phpdoc.GetElement <PHPDocBlock.DeprecatedTag>();
                if (deprecated != null)
                {
                    // [ObsoleteAttribute(message, false)]
                    attrs = attrs.Add(DeclaringCompilation.CreateObsoleteAttribute(deprecated));
                }

                // ...
            }

            // [NotNullAttribute]
            // ...

            //
            return(base.GetAttributes().AddRange(attrs));
        }