Closed sharinganthief closed 11 months ago
Hello @sharinganthief, thank you for submitting this issue. We will try to get back to you as soon as possible. Note to the PostSharp team, this ticket is being tracked in our dashboard under ID TP-34033.
The BuildAspect
method should not have the [Template]
attribute. I think it's the only issue in the code.
Thanks for the reply!
Removed template, no change:
The idea here is to not have to drop
[YamlIgnore] [JsonIgnore] [XmlIgnore]
on all ignored props across the sln, but a single ignore that gets al of them added
It works fine for me:
I was using this code:
using Metalama.Framework.Aspects;
using Metalama.Framework.Code.DeclarationBuilders;
using Metalama.Framework.Code;
using YamlDotNet.Serialization;
public class IgnoreAttribute : FieldOrPropertyAspect
{
public override void BuildAspect( IAspectBuilder<IFieldOrProperty> builder )
{
builder.Advice.IntroduceAttribute(builder.Target,
AttributeConstruction.Create(typeof(YamlIgnoreAttribute)));
base.BuildAspect(builder);
}
}
class Target
{
[Ignore] public bool SomeProperty => SomeOtherProperty != 0;
public int SomeOtherProperty { get; set; }
}
Can you share complete code that reproduces the problem?
Huh. New sln, copied your code, works perfectly. old sln, uninstall all metalama nuget, reinstall latest, works. user error of some kind i guess. thanks for the assist
i have the following aspect:
public class IgnoreAttribute : FieldOrPropertyAspect
{
[Template]
public override void BuildAspect( IAspectBuilder<IFieldOrProperty> builder )
{
builder.Advice.IntroduceAttribute(builder.Target,
AttributeConstruction.Create(typeof(YamlIgnoreAttribute)));
base.BuildAspect(builder);
}
}
assigned like so:
[Ignore] public bool SomeProperty => SomeOtherProperty != 0;
but the property does not get the ignore attribute as seen with reflection at runtime or testing the serialization
I have tried builder.Target.Compilation, every meta.Target option there is i believe but nothing seems to work.
Am i doing this wrong?