public void Apply(MemberInfo attributeSource) { ArgumentUtility.CheckNotNull("attributeSource", attributeSource); var attributes = TypePipeCustomAttributeData.GetCustomAttributes(attributeSource, inherit: true); Apply(attributeSource, attributes, isCopyTemplate: false); }
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) })); }
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) })); }
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")); }
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) })); }
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)); }
public IEnumerable <ICustomAttributeData> GetCustomAttributeData(bool inherit) { return(TypePipeCustomAttributeData.GetCustomAttributes(this, inherit)); }
public override IEnumerable <ICustomAttributeData> GetCustomAttributeData() { return(TypePipeCustomAttributeData.GetCustomAttributes(GetGenericMethodDefinition())); }
public override IEnumerable <ICustomAttributeData> GetCustomAttributeData() { return(TypePipeCustomAttributeData.GetCustomAttributes(_method)); }
public IEnumerable <Aspect> GetDeclaration(MemberInfo memberInfo) { return(GetDeclaration(TypePipeCustomAttributeData.GetCustomAttributes(memberInfo))); }
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)); }
private ICustomAttributeData GetCustomAttributeData <T> (MethodBase method) { return(TypePipeCustomAttributeData.GetCustomAttributes(method).Single(x => x.Constructor.DeclaringType == typeof(T))); }