public void Apply(MemberInfo attributeSource)
        {
            ArgumentUtility.CheckNotNull("attributeSource", attributeSource);

            var attributes = TypePipeCustomAttributeData.GetCustomAttributes(attributeSource, inherit: true);

            Apply(attributeSource, attributes, isCopyTemplate: false);
        }
Ejemplo n.º 2
0
        public void GetCustomAttributes_AttributesOnOriginalMemberAreNotFiltered()
        {
            var member           = NormalizingMemberInfoFromExpressionUtility.GetMember((DomainType obj) => obj.MethodOnDomainType());
            var customAttributes = TypePipeCustomAttributeData.GetCustomAttributes(member, true);

            var customAttributeTypes = customAttributes.Select(a => a.Type).ToArray();

            Assert.That(customAttributeTypes, Is.EquivalentTo(new[] { typeof(InheritableAttribute), typeof(NonInheritableAttribute) }));
        }
Ejemplo n.º 3
0
        public void GetCustomAttributes_WithAllowMultipleFiltering_AttributesOnBaseOnly()
        {
            var member = NormalizingMemberInfoFromExpressionUtility.GetMember((DomainType obj) => obj.AttributesOnBaseOnly());

            var attributes = TypePipeCustomAttributeData.GetCustomAttributes(member, true);

            var attributeTypes = attributes.Select(d => d.Type).ToArray();

            Assert.That(attributeTypes, Is.EquivalentTo(new[] { typeof(InheritableAllowMultipleAttribute), typeof(InheritableNonMultipleAttribute) }));
        }
Ejemplo n.º 4
0
        public void CreateInstance_InternalCtor()
        {
            var customAttributeData = TypePipeCustomAttributeData.GetCustomAttributes(MethodBase.GetCurrentMethod())
                                      .Single(a => a.Type == typeof(AbcAttribute));

            Assert.That(customAttributeData.Constructor.IsAssembly, Is.True);

            var instance = (AbcAttribute)customAttributeData.CreateInstance();

            Assert.That(instance.CtorArg, Is.EqualTo("internal ctor"));
        }
Ejemplo n.º 5
0
        private void CheckSimpleAttributeDataInheritance(MemberInfo member)
        {
            var customAttributesWithoutInheritance = TypePipeCustomAttributeData.GetCustomAttributes(member, false).ToArray();

            Assert.That(customAttributesWithoutInheritance, Is.Empty);

            var customAttributesWithInheritance = TypePipeCustomAttributeData.GetCustomAttributes(member, true).ToArray();

            Assert.That(customAttributesWithInheritance, Is.Not.Empty);

            var customAttributeTypesWithInheritance = customAttributesWithInheritance.Select(d => d.Type).ToArray();

            Assert.That(customAttributeTypesWithInheritance, Is.EqualTo(new[] { typeof(InheritableAttribute) }));
        }
Ejemplo n.º 6
0
        public void GetCustomAttributes_WithAllowMultipleFiltering_AttributesOnBaseAndDerived()
        {
            var member = NormalizingMemberInfoFromExpressionUtility.GetMember((DomainType obj) => obj.AttributesOnBaseAndDerived());

            var attributes = TypePipeCustomAttributeData.GetCustomAttributes(member, true);

            var attributeTypesAndCtorArgs         = attributes.Select(d => new { d.Type, Arg = (string)d.ConstructorArguments.Single() }).ToArray();
            var expectedAttributeTypesAndCtorArgs =
                new[]
            {
                new { Type = typeof(InheritableNonMultipleAttribute), Arg = "derived" },
                new { Type = typeof(InheritableAllowMultipleAttribute), Arg = "base" },
                new { Type = typeof(InheritableAllowMultipleAttribute), Arg = "derived" }
            };

            Assert.That(attributeTypesAndCtorArgs, Is.EquivalentTo(expectedAttributeTypesAndCtorArgs));
        }
        public void MutableReflection()
        {
            var mutableType     = MutableTypeObjectMother.Create(typeof(DomainType));
            var typeInitializer = mutableType.AddTypeInitializer(ctx => Expression.Empty());
            var field           = mutableType.AddField("_field", FieldAttributes.Private, typeof(int));
            var ctor            = mutableType.AddedConstructors.Single();
            var method          = mutableType.AddMethod(
                "Method", MethodAttributes.Public, typeof(int), new[] { new ParameterDeclaration(typeof(int)) }, ctx => Expression.Constant(7));
            var returnParameter = method.MutableReturnParameter;
            var parameter       = method.MutableParameters.Single();
            var property        = mutableType.AddProperty(
                "Property", typeof(int), new[] { new ParameterDeclaration(typeof(int)) }, MethodAttributes.Public, ctx => Expression.Default(typeof(int)), ctx => Expression.Empty());
            var event_ = mutableType.AddEvent("Event", typeof(Action), MethodAttributes.Public, ctx => Expression.Empty(), ctx => Expression.Empty());

            // TODO 4791
            // var genericParmaeter = proxyType.MutableGenericParameter.Single();
            //var nestedType = MutableType.GetNestedTypes().Single();

            AddAbcAttribute(mutableType, "class");
            AddAbcAttribute(typeInitializer, "type initializer");
            AddAbcAttribute(field, "field");
            AddAbcAttribute(ctor, "constructor");
            AddAbcAttribute(method, "method");
            AddAbcAttribute(returnParameter, "return value");
            AddAbcAttribute(parameter, "parameter");
            AddAbcAttribute(property, "property");
            AddAbcAttribute(event_, "event");

            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(mutableType), CustomAttributeData.GetCustomAttributes(_type));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(field), CustomAttributeData.GetCustomAttributes(_field));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(ctor), CustomAttributeData.GetCustomAttributes(_ctor));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(method), CustomAttributeData.GetCustomAttributes(_method));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(returnParameter), CustomAttributeData.GetCustomAttributes(_returnParameter));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(parameter), CustomAttributeData.GetCustomAttributes(_parameter));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(property), CustomAttributeData.GetCustomAttributes(_property));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(event_), CustomAttributeData.GetCustomAttributes(_event));
            //CheckAbcAttribute (TypePipeCustomAttributeData.GetCustomAttributes (nestedType), "nested type");
            // Generic Parameters
        }
 private IEnumerable <ICustomAttributeData> GetCopiedAttributesData(
     MemberInfo copiedAttributesSource,
     CopyCustomAttributesAttribute copyAttribute,
     bool includeCopyAttributes,
     bool includeInheritableAttributes)
 {
     foreach (var attributeData in TypePipeCustomAttributeData.GetCustomAttributes(copiedAttributesSource, inherit: true))
     {
         Type attributeType = attributeData.Constructor.DeclaringType;
         if (typeof(CopyCustomAttributesAttribute).IsAssignableFrom(attributeType))
         {
             if (includeCopyAttributes)
             {
                 yield return(attributeData);
             }
         }
         else if (copyAttribute.IsCopiedAttributeType(attributeType) &&
                  (includeInheritableAttributes || !AttributeUtility.IsAttributeInherited(attributeType)))
         {
             yield return(attributeData);
         }
     }
 }
 public void StandardReflection_BehavesEqually()
 {
     CheckAbcAttributeOnly(TypePipeCustomAttributeData.GetCustomAttributes(_assembly), CustomAttributeData.GetCustomAttributes(_assembly));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_module), CustomAttributeData.GetCustomAttributes(_module));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_type), CustomAttributeData.GetCustomAttributes(_type));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_typeInitializer), CustomAttributeData.GetCustomAttributes(_typeInitializer));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_field), CustomAttributeData.GetCustomAttributes(_field));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_ctor), CustomAttributeData.GetCustomAttributes(_ctor));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_method), CustomAttributeData.GetCustomAttributes(_method));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_returnParameter), CustomAttributeData.GetCustomAttributes(_returnParameter));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_parameter), CustomAttributeData.GetCustomAttributes(_parameter));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_property), CustomAttributeData.GetCustomAttributes(_property));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_getter), CustomAttributeData.GetCustomAttributes(_getter));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_getterReturnParameter), CustomAttributeData.GetCustomAttributes(_getterReturnParameter));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_setterValueParameter), CustomAttributeData.GetCustomAttributes(_setterValueParameter));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_setter), CustomAttributeData.GetCustomAttributes(_setter));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_event), CustomAttributeData.GetCustomAttributes(_event));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_eventAdder), CustomAttributeData.GetCustomAttributes(_eventAdder));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_eventAdderParameter), CustomAttributeData.GetCustomAttributes(_eventAdderParameter));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_eventRemover), CustomAttributeData.GetCustomAttributes(_eventRemover));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_eventRemoveParameter), CustomAttributeData.GetCustomAttributes(_eventRemoveParameter));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_nestedType), CustomAttributeData.GetCustomAttributes(_nestedType));
     CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(_genericType), CustomAttributeData.GetCustomAttributes(_genericType));
 }
Ejemplo n.º 10
0
 public IEnumerable <ICustomAttributeData> GetCustomAttributeData(bool inherit)
 {
     return(TypePipeCustomAttributeData.GetCustomAttributes(this, inherit));
 }
Ejemplo n.º 11
0
 public override IEnumerable <ICustomAttributeData> GetCustomAttributeData()
 {
     return(TypePipeCustomAttributeData.GetCustomAttributes(GetGenericMethodDefinition()));
 }
Ejemplo n.º 12
0
 public override IEnumerable <ICustomAttributeData> GetCustomAttributeData()
 {
     return(TypePipeCustomAttributeData.GetCustomAttributes(_method));
 }
Ejemplo n.º 13
0
 public IEnumerable <Aspect> GetDeclaration(MemberInfo memberInfo)
 {
     return(GetDeclaration(TypePipeCustomAttributeData.GetCustomAttributes(memberInfo)));
 }
Ejemplo n.º 14
0
 public IEnumerable <Aspect> GetDeclaration(System.Reflection.Assembly assembly)
 {
     return(GetDeclaration(TypePipeCustomAttributeData.GetCustomAttributes(assembly)));
 }
        public void InheritedMethod_FromObject()
        {
            var method = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.ToString());

            Assert.That(() => TypePipeCustomAttributeData.GetCustomAttributes(method, true), Throws.Nothing);
        }
 private IEnumerable <ICustomAttributeData> GetCustomAttributeData(MemberInfo member)
 {
     return(TypePipeCustomAttributeData.GetCustomAttributes(member).Where(a => a.Type != typeof(TestAttribute)));
 }
 public override IEnumerable <ICustomAttributeData> GetCustomAttributeData()
 {
     return(TypePipeCustomAttributeData.GetCustomAttributes(_constructor));
 }
Ejemplo n.º 18
0
 private ICustomAttributeData GetCustomAttributeData <T> (MethodBase method)
 {
     return(TypePipeCustomAttributeData.GetCustomAttributes(method).Single(x => x.Constructor.DeclaringType == typeof(T)));
 }