MethodBoundaryAspect.Fody icon indicating copy to clipboard operation
MethodBoundaryAspect.Fody copied to clipboard

Support for Double?

Open kbrung opened this issue 2 years ago • 2 comments

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?

kbrung avatar Nov 30 '23 14:11 kbrung

Hi, can you provide a code sample for reproduction?

Ralf1108 avatar Dec 05 '23 22:12 Ralf1108

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();
    }
}

kbrung avatar Dec 11 '23 07:12 kbrung