Skip to content

ParameterBuilder.SetConstant fails when using a default value of null #35

@jonasro

Description

@jonasro

Castle.DynamicProxy.Generators.Emitters.DefineParameters line 162 fails if one of the parameters passed in is a nullable type with a default value of null.

To reproduce change the default value in ClassWithMethodWithParameterWithDefaultValue.Method to null.

public class ClassWithMethodWithParameterWithDefaultValue
{
    public virtual void Method(int? value = null)
    {  }
}

Run test MethodParameterWithDefaultValue_DefaultValueIsSetOnProxiedMethodAsWell.

    [Test]
    public void MethodParameterWithDefaultValue_DefaultValueIsSetOnProxiedMethodAsWell()
    {
        var proxiedType = generator.CreateClassProxy<ClassWithMethodWithParameterWithDefaultValue>().GetType();

        var parameter = proxiedType.GetMethod("Method").GetParameters().Single(paramInfo => paramInfo.Name == "value");

        Assert.True(parameter.HasDefaultValue);
        Assert.AreEqual(3, parameter.DefaultValue);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions