Пример #1
0
 private static void GetAssemblyDescriptionAttributes(AssemblySymbol assembly, ArrayBuilder<CSharpAttributeData> list)
 {
     foreach (var attrData in assembly.GetAttributes())
     {
         if (attrData.IsTargetAttribute(assembly, AttributeDescription.AssemblyDescriptionAttribute))
         {
             list.Add(attrData);
         }
     }
 }
Пример #2
0
        private static void TestDuplicateAssemblyAttributesNotEmitted(AssemblySymbol assembly, int expectedSrcAttrCount, int expectedDuplicateAttrCount, string attrTypeName)
        {
            // SOURCE ATTRIBUTES

            var allSrcAttrs = assembly.GetAttributes();
            var srcAttrs = allSrcAttrs.Where((a) => string.Equals(a.AttributeClass.Name, attrTypeName, StringComparison.Ordinal)).AsImmutable();

            Assert.Equal(expectedSrcAttrCount, srcAttrs.Length);


            // EMITTED ATTRIBUTES

            // We should get only unique netmodule/assembly attributes here, duplicate ones should not be emitted.
            int expectedEmittedAttrsCount = expectedSrcAttrCount - expectedDuplicateAttrCount;

            var allEmittedAttrs = assembly.GetCustomAttributesToEmit(emittingAssemblyAttributesInNetModule: false);
            var emittedAttrs = allEmittedAttrs.Where((a) => string.Equals(a.AttributeClass.Name, attrTypeName, StringComparison.Ordinal)).AsImmutable();

            Assert.Equal(expectedEmittedAttrsCount, emittedAttrs.Length);
            var uniqueAttributes = new HashSet<CSharpAttributeData>(comparer: CommonAttributeDataComparer.Instance);
            foreach (var attr in emittedAttrs)
            {
                Assert.True(uniqueAttributes.Add(attr));
            }
        }
Пример #3
0
 private static IEnumerable<CSharpAttributeData> GetAssemblyDescriptionAttributes(AssemblySymbol assembly)
 {
     return assembly.GetAttributes().Where(data => data.IsTargetAttribute(assembly, AttributeDescription.AssemblyDescriptionAttribute));
 }