internal virtual CustomAttributesBag <CSharpAttributeData> GetAttributesBag()
        {
            if (_lazyCustomAttributesBag == null || !_lazyCustomAttributesBag.IsSealed)
            {
                bool lazyAttributesStored = false;

                var sourceMethod = this.ContainingSymbol as SourceOrdinaryMethodSymbol;
                if ((object)sourceMethod == null || (object)sourceMethod.SourcePartialDefinition == null)
                {
                    lazyAttributesStored = LoadAndValidateAttributes(
                        OneOrMany.Create(this.MergedAttributeDeclarationSyntaxLists),
                        ref _lazyCustomAttributesBag,
                        binderOpt: (ContainingSymbol as LocalFunctionSymbol)?.SignatureBinder);
                }
                else
                {
                    var typeParameter = (SourceTypeParameterSymbolBase)sourceMethod.SourcePartialDefinition.TypeParameters[_ordinal];
                    CustomAttributesBag <CSharpAttributeData> attributesBag = typeParameter.GetAttributesBag();

                    lazyAttributesStored = Interlocked.CompareExchange(ref _lazyCustomAttributesBag, attributesBag, null) == null;
                }

                if (lazyAttributesStored)
                {
                    _state.NotePartComplete(CompletionPart.Attributes);
                }
            }

            return(_lazyCustomAttributesBag);
        }
Esempio n. 2
0
 internal override OneOrMany <SyntaxList <AttributeListSyntax> > GetReturnTypeAttributeDeclarations()
 {
     // BeginInvoke method doesn't have return type attributes
     // because it doesn't inherit Delegate declaration's return type.
     // It has a special return type: SpecialType.System.IAsyncResult.
     return(OneOrMany.Create(default(SyntaxList <AttributeListSyntax>)));
 }
Esempio n. 3
0
        internal override CustomAttributesBag <CSharpAttributeData> GetAttributesBag()
        {
            if (lazyCustomAttributesBag == null || !lazyCustomAttributesBag.IsSealed)
            {
                bool lazyAttributesStored = false;

                var sourceMethod = this.ContainingSymbol as SourceMemberMethodSymbol;
                if ((object)sourceMethod == null || (object)sourceMethod.SourcePartialDefinition == null)
                {
                    lazyAttributesStored = LoadAndValidateAttributes(OneOrMany.Create(this.MergedAttributeDeclarationSyntaxLists), ref lazyCustomAttributesBag);
                }
                else
                {
                    var typeParameter = (SourceTypeParameterSymbolBase)sourceMethod.SourcePartialDefinition.TypeParameters[this.ordinal];
                    CustomAttributesBag <CSharpAttributeData> attributesBag = typeParameter.GetAttributesBag();

                    lazyAttributesStored = Interlocked.CompareExchange(ref lazyCustomAttributesBag, attributesBag, null) == null;
                }

                if (lazyAttributesStored)
                {
                    state.NotePartComplete(CompletionPart.Attributes);
                }
            }

            return(lazyCustomAttributesBag);
        }
Esempio n. 4
0
 public void SelectWithArg()
 {
     Verify(OneOrMany.Create(1).Select((i, a) => i + a, 1), 2);
     Verify(OneOrMany.Create(ImmutableArray <int> .Empty).Select((i, a) => i + a, 1));
     Verify(OneOrMany.Create(ImmutableArray.Create(1)).Select((i, a) => i + a, 1), 2);
     Verify(OneOrMany.Create(ImmutableArray.Create(1, 2)).Select((i, a) => i + a, 1), 2, 3);
 }
Esempio n. 5
0
 public void Select()
 {
     Verify(OneOrMany.Create(1).Select(i => i + 1), 2);
     Verify(OneOrMany.Create(ImmutableArray <int> .Empty).Select(i => i + 1));
     Verify(OneOrMany.Create(ImmutableArray.Create(1)).Select(i => i + 1), 2);
     Verify(OneOrMany.Create(ImmutableArray.Create(1, 2)).Select(i => i + 1), 2, 3);
 }
Esempio n. 6
0
 > GetAttributeDeclarations()
 {
     // TODO: This implementation looks strange. It might make sense for the Invoke method, but
     //       not for constructor and other methods.
     return OneOrMany.Create(
         ((SourceNamedTypeSymbol)ContainingSymbol).GetAttributeDeclarations()
     );
 }
Esempio n. 7
0
 public void Many()
 {
     Verify(OneOrMany.Create(ImmutableArray.Create(1, 2, 3)).Add(4), 1, 2, 3, 4);
     Verify(OneOrMany.Create(ImmutableArray.Create(1, 2, 3, 4)), 1, 2, 3, 4);
     Verify(OneOrMany.Create(ImmutableArray <int> .Empty).Add(1).Add(2).Add(3).Add(4), 1, 2, 3, 4);
     Verify(new OneOrMany <int>(ImmutableArray.Create(1, 2, 3)).Add(4), 1, 2, 3, 4);
     Verify(new OneOrMany <int>(ImmutableArray.Create(1, 2, 3, 4)), 1, 2, 3, 4);
     Verify(new OneOrMany <int>(ImmutableArray <int> .Empty).Add(1).Add(2).Add(3).Add(4), 1, 2, 3, 4);
 }
Esempio n. 8
0
 public void One()
 {
     Verify(OneOrMany.Create(1), 1);
     Verify(OneOrMany.Create(ImmutableArray.Create(2)), 2);
     Verify(OneOrMany.Create(ImmutableArray <int> .Empty).Add(3), 3);
     Verify(new OneOrMany <int>(1), 1);
     Verify(new OneOrMany <int>(ImmutableArray.Create(2)), 2);
     Verify(new OneOrMany <int>(ImmutableArray <int> .Empty).Add(3), 3);
 }
Esempio n. 9
0
        public void Add(AssemblyIdentity identity, TValue value)
        {
            var pair = KeyValuePairUtil.Create(identity, value);

            OneOrMany <KeyValuePair <AssemblyIdentity, TValue> > sameName;

            _map[identity.Name] = _map.TryGetValue(identity.Name, out sameName)
              ? sameName.Add(pair)
              : OneOrMany.Create(pair);
        }
Esempio n. 10
0
 public void FirstOrDefault()
 {
     Assert.Equal(1, OneOrMany.Create(1).FirstOrDefault(i => i < 2));
     Assert.Equal(0, OneOrMany.Create(1).FirstOrDefault(i => i > 2));
     Assert.Equal(0, OneOrMany.Create(ImmutableArray <int> .Empty).FirstOrDefault(i => i > 2));
     Assert.Equal(1, OneOrMany.Create(ImmutableArray.Create(1)).FirstOrDefault(i => i < 2));
     Assert.Equal(0, OneOrMany.Create(ImmutableArray.Create(1)).FirstOrDefault(i => i > 2));
     Assert.Equal(1, OneOrMany.Create(ImmutableArray.Create(1, 3)).FirstOrDefault(i => i < 2));
     Assert.Equal(3, OneOrMany.Create(ImmutableArray.Create(1, 3)).FirstOrDefault(i => i > 2));
 }
Esempio n. 11
0
 internal override OneOrMany <SyntaxList <AttributeListSyntax> > GetAttributeDeclarations()
 {
     if ((object)this.SourcePartialImplementation != null)
     {
         return(OneOrMany.Create(ImmutableArray.Create(AttributeDeclarationSyntaxList, this.SourcePartialImplementation.AttributeDeclarationSyntaxList)));
     }
     else
     {
         return(OneOrMany.Create(AttributeDeclarationSyntaxList));
     }
 }
Esempio n. 12
0
        public void Errors()
        {
            var single = OneOrMany.Create(123);
            var quad   = OneOrMany.Create(ImmutableArray.Create <int>(10, 20, 30, 40));

            Assert.Throws <IndexOutOfRangeException>(() => single[1]);
            Assert.Throws <IndexOutOfRangeException>(() => single[-1]);
            Assert.Throws <IndexOutOfRangeException>(() => quad[5]);
            Assert.Throws <IndexOutOfRangeException>(() => quad[-1]);
            Assert.Throws <ArgumentNullException>(() => OneOrMany.Create(default(ImmutableArray <int>)));
        }
        internal override OneOrMany <SyntaxList <AttributeListSyntax> > GetAttributeDeclarations()
        {
            var syntax = this.SyntaxNode;

            switch (syntax.Kind)
            {
            case SyntaxKind.GetAccessorDeclaration:
            case SyntaxKind.SetAccessorDeclaration:
                return(OneOrMany.Create(((AccessorDeclarationSyntax)syntax).AttributeLists));
            }
            return(base.GetAttributeDeclarations());
        }
Esempio n. 14
0
        /// <summary>
        /// Returns a bag of applied custom attributes and data decoded from well-known attributes. Returns null if there are no attributes applied on the symbol.
        /// </summary>
        /// <remarks>
        /// Forces binding and decoding of attributes.
        /// </remarks>
        private CustomAttributesBag <CSharpAttributeData> GetAttributesBag()
        {
            if ((_lazyCustomAttributesBag == null || !_lazyCustomAttributesBag.IsSealed) &&
                LoadAndValidateAttributes(OneOrMany.Create(this.AttributeDeclarationSyntaxList), ref _lazyCustomAttributesBag))
            {
                DeclaringCompilation.SymbolDeclaredEvent(this);
                var wasCompletedThisThread = state.NotePartComplete(CompletionPart.Attributes);
                Debug.Assert(wasCompletedThisThread);
            }

            return(_lazyCustomAttributesBag);
        }
Esempio n. 15
0
        public void Positive()
        {
            var single = OneOrMany.Create(123);
            var quad   = OneOrMany.Create(ImmutableArray.Create <int>(10, 20, 30, 40));

            Assert.Equal(1, single.Count);
            Assert.Equal(123, single[0]);

            Assert.Equal(10, quad[0]);
            Assert.Equal(20, quad[1]);
            Assert.Equal(30, quad[2]);
            Assert.Equal(40, quad[3]);
        }
Esempio n. 16
0
        private CustomAttributesBag <CSharpAttributeData> GetAttributesBag()
        {
            if (_lazyCustomAttributesBag == null || !_lazyCustomAttributesBag.IsSealed)
            {
                var mergedAttributes = ((SourceAssemblySymbol)this.ContainingAssembly).GetAttributeDeclarations();
                if (LoadAndValidateAttributes(OneOrMany.Create(mergedAttributes), ref _lazyCustomAttributesBag))
                {
                    var completed = _state.NotePartComplete(CompletionPart.Attributes);
                    Debug.Assert(completed);
                }
            }

            return(_lazyCustomAttributesBag);
        }
Esempio n. 17
0
        public void Contains()
        {
            Assert.True(OneOrMany.Create(1).Contains(1));
            Assert.False(OneOrMany.Create(1).Contains(0));

            Assert.False(OneOrMany.Create(ImmutableArray <int> .Empty).Contains(0));

            Assert.True(OneOrMany.Create(ImmutableArray.Create(1)).Contains(1));
            Assert.False(OneOrMany.Create(ImmutableArray.Create(1)).Contains(0));

            Assert.True(OneOrMany.Create(ImmutableArray.Create(1, 2)).Contains(1));
            Assert.True(OneOrMany.Create(ImmutableArray.Create(1, 2)).Contains(2));
            Assert.False(OneOrMany.Create(ImmutableArray.Create(1, 2)).Contains(0));
        }
Esempio n. 18
0
        internal override OneOrMany <SyntaxList <AttributeListSyntax> > GetAttributeDeclarations()
        {
            if (this.IsPrimaryCtor)
            {
                if ((object)((SourceNamedTypeSymbol)ContainingType).PrimaryCtor == (object)this)
                {
                    // Main Primary Constructor gets its attributes from attributes on the type.
                    return(OneOrMany.Create(((SourceNamedTypeSymbol)ContainingType).GetAttributeDeclarations()));
                }

                // Non-Main Primary constructor doesn't have attributes.
                return(OneOrMany.Create(default(SyntaxList <AttributeListSyntax>)));
            }

            return(OneOrMany.Create(((ConstructorDeclarationSyntax)this.SyntaxNode).AttributeLists));
        }
Esempio n. 19
0
        /// <summary>
        /// Returns a bag of applied custom attributes and data decoded from well-known attributes. Returns null if there are no attributes applied on the symbol.
        /// </summary>
        /// <remarks>
        /// Forces binding and decoding of attributes.
        /// </remarks>
        private CustomAttributesBag <CSharpAttributeData> GetAttributesBag()
        {
            var bag = this.lazyCustomAttributesBag;

            if (bag != null && bag.IsSealed)
            {
                return(bag);
            }

            if (LoadAndValidateAttributes(OneOrMany.Create(this.AttributeDeclarationSyntaxList), ref lazyCustomAttributesBag))
            {
                var completed = state.NotePartComplete(CompletionPart.Attributes);
                Debug.Assert(completed);
            }

            Debug.Assert(lazyCustomAttributesBag.IsSealed);
            return(this.lazyCustomAttributesBag);
        }
        /// <summary>
        /// Gets the syntax list of custom attributes that declares atributes for this parameter symbol.
        /// </summary>
        internal virtual OneOrMany <SyntaxList <AttributeListSyntax> > GetAttributeDeclarations()
        {
            // C# spec:
            // The attributes on the parameters of the resulting method declaration
            // are the combined attributes of the corresponding parameters of the defining
            // and the implementing partial method declaration in unspecified order.
            // Duplicates are not removed.

            SyntaxList <AttributeListSyntax> attributes = AttributeDeclarationList;

            var sourceMethod = this.ContainingSymbol as SourceMemberMethodSymbol;

            if ((object)sourceMethod == null)
            {
                return(OneOrMany.Create(attributes));
            }

            SyntaxList <AttributeListSyntax> otherAttributes;

            // if this is a definition get the implementation and vice versa
            SourceMemberMethodSymbol otherPart = sourceMethod.OtherPartOfPartial;

            if ((object)otherPart != null)
            {
                otherAttributes = ((SourceParameterSymbol)otherPart.Parameters[this.Ordinal]).AttributeDeclarationList;
            }
            else
            {
                otherAttributes = default(SyntaxList <AttributeListSyntax>);
            }

            if (attributes.Equals(default(SyntaxList <AttributeListSyntax>)))
            {
                return(OneOrMany.Create(otherAttributes));
            }
            else if (otherAttributes.Equals(default(SyntaxList <AttributeListSyntax>)))
            {
                return(OneOrMany.Create(attributes));
            }

            return(OneOrMany.Create(ImmutableArray.Create(attributes, otherAttributes)));
        }
Esempio n. 21
0
 internal override OneOrMany <SyntaxList <AttributeListSyntax> > GetAttributeDeclarations()
 {
     return(OneOrMany.Create(((ConstructorDeclarationSyntax)this.SyntaxNode).AttributeLists));
 }
Esempio n. 22
0
     > GetAttributeDeclarations()
 {
     return(OneOrMany.Create(this.GetSyntax().AttributeLists));
 }
Esempio n. 23
0
 > GetAttributeDeclarations() => OneOrMany.Create(default(SyntaxList <AttributeListSyntax>));
Esempio n. 24
0
 internal override OneOrMany <SyntaxList <AttributeListSyntax> > GetReturnTypeAttributeDeclarations()
 {
     // Constructors don't have return type attributes
     return(OneOrMany.Create(default(SyntaxList <AttributeListSyntax>)));
 }
 internal override OneOrMany <SyntaxList <AttributeListSyntax> > GetAttributeDeclarations()
 {
     return(OneOrMany.Create(this.AssociatedEvent.AttributeDeclarationSyntaxList));
 }
Esempio n. 26
0
 internal sealed override OneOrMany <SyntaxList <AttributeListSyntax> > GetAttributeDeclarations()
 {
     // TODO: This implementation looks strange. It might make sense for the Invoke method, but
     //       not for constructor and other methods.
     return(OneOrMany.Create(((SourceNamedTypeSymbol)ContainingSymbol).GetAttributeDeclarations()));
 }
 internal sealed override OneOrMany <SyntaxList <AttributeListSyntax> > GetAttributeDeclarations() => OneOrMany.Create(default(SyntaxList <AttributeListSyntax>));
Esempio n. 28
0
 internal override OneOrMany <SyntaxList <AttributeListSyntax> > GetAttributeDeclarations()
 {
     return(OneOrMany.Create(Syntax.AttributeLists));
 }
Esempio n. 29
0
 internal override OneOrMany <SyntaxList <AttributeListSyntax> > GetAttributeDeclarations()
 {
     // destructors can't have return type attributes
     return(OneOrMany.Create(((DestructorDeclarationSyntax)this.SyntaxNode).AttributeLists));
 }
 internal sealed override OneOrMany <SyntaxList <AttributeListSyntax> > GetAttributeDeclarations()
 {
     return(OneOrMany.Create(this.GetSyntax().AttributeLists));
 }