Skip to content

Incorrect code generated for Convert with conversion method #20

@MaceWindu

Description

@MaceWindu

Hello, thank you for this great tool!

I started to use it and found following issue:

            var from = typeof(string);
            var to = typeof(int);

            var p = Expression.Parameter(from, "p");

            var body = Expression.Condition(
                Expression.NotEqual(p, Expression.Constant(null, from)),
                Expression.Convert(p, to, to.GetMethod(nameof(int.Parse), new[] { from })),
                Expression.Constant(0));

            var expr = Expression.Lambda<Func<string, int>>(body, p);

produces following C# code:

p => (p != null) ? (int)p : 0

when it should be

p => (p != null) ? int.Parse(p) : 0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions