Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Double? #124

Open
kbrung opened this issue Nov 30, 2023 · 2 comments
Open

Support for Double? #124

kbrung opened this issue Nov 30, 2023 · 2 comments

Comments

@kbrung
Copy link

kbrung commented Nov 30, 2023

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
Copy link
Collaborator

Ralf1108 commented Dec 5, 2023

Hi, can you provide a code sample for reproduction?

@kbrung
Copy link
Author

kbrung commented Dec 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants