コード例 #1
0
        public void ReplicateAttributes(IAttributableDefinition source, IMutableMember destination)
        {
            ArgumentUtility.CheckNotNull("source", source);
            ArgumentUtility.CheckNotNull("destination", destination);

            foreach (var attribute in source.CustomAttributes)
            {
                AddAttribute(destination, attribute.Data);
            }
        }
コード例 #2
0
        public static AttributeDefinition CreateAttributeDefinition(IAttributableDefinition declaringDefinition)
        {
            ArgumentUtility.CheckNotNull("declaringDefinition", declaringDefinition);

            var attributeData = CustomAttributeData.GetCustomAttributes(typeof(BaseType1)).Single(a => a.Constructor.DeclaringType == typeof(BT1Attribute));

            var attributeDefinition = new AttributeDefinition(declaringDefinition, new CustomAttributeDataAdapter(attributeData), true);

            PrivateInvoke.InvokeNonPublicMethod(declaringDefinition.CustomAttributes, "Add", attributeDefinition);
            return(attributeDefinition);
        }
コード例 #3
0
        private static void CheckAttributes(IAttributableDefinition attributableDefinition)
        {
            Assert.That(attributableDefinition.CustomAttributes.ContainsKey(typeof(TagAttribute)), Is.True);
            Assert.That(attributableDefinition.CustomAttributes.GetItemCount(typeof(TagAttribute)), Is.EqualTo(2));

            var attributes  = new List <AttributeDefinition> (attributableDefinition.CustomAttributes);
            var attributes2 = new List <AttributeDefinition> (attributableDefinition.CustomAttributes[typeof(TagAttribute)]);

            foreach (AttributeDefinition attribute in attributes2)
            {
                Assert.That(attributes.Contains(attribute), Is.True);
            }

            AttributeDefinition attribute1 = attributes.Find(
                delegate(AttributeDefinition a)
            {
                Assert.That(a.AttributeType, Is.EqualTo(typeof(TagAttribute)));
                return(a.Data.Constructor.Equals(typeof(TagAttribute).GetConstructor(Type.EmptyTypes)));
            });

            Assert.That(attribute1, Is.Not.Null);
            Assert.That(attribute1.IsCopyTemplate, Is.False);
            Assert.That(attribute1.Data.ConstructorArguments.Count, Is.EqualTo(0));
            Assert.That(attribute1.Data.NamedArguments.Count, Is.EqualTo(0));
            Assert.That(attribute1.DeclaringDefinition, Is.SameAs(attributableDefinition));

            AttributeDefinition attribute2 = attributes.Find(
                delegate(AttributeDefinition a)
            {
                Assert.That(a.AttributeType, Is.EqualTo(typeof(TagAttribute)));
                return(a.Data.Constructor.Equals(typeof(TagAttribute).GetConstructor(new[] { typeof(string) })));
            });

            Assert.That(attribute2, Is.Not.Null);
            Assert.That(attribute2.IsCopyTemplate, Is.False);
            Assert.That(attribute2.Data.ConstructorArguments.Count, Is.EqualTo(1));
            Assert.That(attribute2.Data.ConstructorArguments[0], Is.EqualTo("Class!"));

            var namedArgumentData         = attribute2.Data.NamedArguments.Select(n => new { n.MemberInfo, n.Value }).ToArray();
            var expectedNamedArgumentData =
                new[]
            {
                new { MemberInfo = (MemberInfo)typeof(TagAttribute).GetField("Named"), Value = (object)5 }
            };

            Assert.That(namedArgumentData, Is.EquivalentTo(expectedNamedArgumentData));

            Assert.That(attribute2.DeclaringDefinition, Is.SameAs(attributableDefinition));
            Assert.That(attribute2.Parent, Is.SameAs(attributableDefinition));
        }
コード例 #4
0
 public AttributeDefinitionBuilder(IAttributableDefinition attributableDefinition)
 {
     ArgumentUtility.CheckNotNull("attributableDefinition", attributableDefinition);
     _attributableDefinition = attributableDefinition;
 }
コード例 #5
0
 public AttributeDefinition(IAttributableDefinition declaringDefinition, ICustomAttributeData data, bool isCopyTemplate)
 {
     _declaringDefinition = declaringDefinition;
     _data           = data;
     _isCopyTemplate = isCopyTemplate;
 }