-
Hi there, we are currently using PostSharp to add custom attributes at the assembly level. How can i achieve this? Or this not yet supported? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 12 replies
-
Hi, In Metalama, this is done using Fabrics. See https://doc.metalama.net/fabrics/fabrics-aspects . |
Beta Was this translation helpful? Give feedback.
-
The bug is when you are using |
Beta Was this translation helpful? Give feedback.
-
I'm sorry, you are right. I believed this was covered by unit tests but it seems that it does not work in practice. |
Beta Was this translation helpful? Give feedback.
-
We have released Metalama 0.5.37-preview, which fixes one part of this issue. You can now pass Using |
Beta Was this translation helpful? Give feedback.
-
In 0.5.38, you should be able to pass a |
Beta Was this translation helpful? Give feedback.
-
What code exactly fails and what is the exception message? We now have a unit test for this case: using System;
using Metalama.Framework.Aspects;
using Metalama.Framework.Code;
using Metalama.Framework.Code.DeclarationBuilders;
namespace Metalama.Framework.Tests.Integration.Tests.Aspects.Attributes.AddWithParameterOfType;
public class MyAttribute : Attribute
{
public MyAttribute(Type t)
{
}
}
public class MyAspect : MethodAspect
{
public override void BuildAspect(IAspectBuilder<IMethod> builder)
{
builder.Advice.IntroduceAttribute(
builder.Target,
AttributeConstruction.Create(
typeof(MyAttribute),
constructorArguments: new object?[] { typeof(C) }));
}
}
// <target>
internal class C
{
[MyAspect]
private void M() { }
} |
Beta Was this translation helpful? Give feedback.
-
I think this has been solved a few builds ago but we forgot to mention it in this discussion. |
Beta Was this translation helpful? Give feedback.
We have released Metalama 0.5.37-preview, which fixes one part of this issue.
You can now pass
IType
toAttributeConstruction.Create
's parameters.Using
System.Reflection.Type
is not possible at the moment. You have to manually callTypeFactory.GetType
to convert toIType
.