vescon / MethodBoundaryAspect.Fody

A Fody weaver which allows to decorate methods and hook into method start, method end and method exceptions.
MIT License
243 stars 75 forks source link

Support for Double? #124

Open kbrung opened 9 months ago

kbrung commented 9 months ago

I get a "Not a supported primitve parameter type: Double" exception in the LoadPrimitiveConstOnStack(MetadataType type, object value) of the InstructionBlockCreator when using doubles in my attributes.

Is it possible to get the double type supported?

Ralf1108 commented 9 months ago

Hi, can you provide a code sample for reproduction?

kbrung commented 9 months ago

Sorry for the late reply. It is the season of pandemics.

I get a compile time error when compiling this:

namespace MethodBoundaryAspectLimit;

using System;
using MethodBoundaryAspect.Fody.Attributes;

[AttributeUsage(AttributeTargets.Method)]
public sealed class RequiresDoubleGreaterThanAttribute : OnMethodBoundaryAspect
{
    public double CriteriaValue { get; }

    public RequiresDoubleGreaterThanAttribute(double criteriaValue)
    {
        CriteriaValue = criteriaValue;
    }

    public override void OnEntry(MethodExecutionArgs arg)
    {
        ArgumentNullException.ThrowIfNull(arg);

        arg.FlowBehavior = FlowBehavior.RethrowException;
        var claimValue = 4.9d;
        if (claimValue <= CriteriaValue)
        {
            throw new InvalidOperationException("Claim value not met.");
        }
    }
}

public class MyService
{
    [RequiresDoubleGreaterThan(5)]
    public void DoSomething() => Console.WriteLine("Hello world");
}

public static class Program
{
    public static void Main(string[] args)
    {
        var service = new MyService();
        service.DoSomething();
    }
}