Given a property of a delegate type (Func, Predicate etc.), I get a warning when storing the value of that property in a local variable.
To my knowledge, and after checking the IL code (which I'm not that familiar with), I don't think an allocation is happening.
As I understand things, a reference to the delegate is returned and stored in the variable, no allocation should happen.
Also I do NOT get a warning when directly invoking the property, only when first storing it in a variable, which also seems odd.
public class Holder
{
public Predicate<int> Checker { get; init; }
}
public class Tester
{
public bool Test()
{
var holder = new Holder {
Checker = x => x > 1
};
return Use(holder, 5);
}
public bool Use(Holder h, int arg)
{
var local = h.Checker;
return local(arg);
}
}
Given a property of a delegate type (
Func
,Predicate
etc.), I get a warning when storing the value of that property in a local variable. To my knowledge, and after checking the IL code (which I'm not that familiar with), I don't think an allocation is happening.As I understand things, a reference to the delegate is returned and stored in the variable, no allocation should happen. Also I do NOT get a warning when directly invoking the property, only when first storing it in a variable, which also seems odd.