I have the following code snippet:
Expression<Func<TSource, TDest>> expression = model => new TDest{};
// Result: {model => new TestModel(){}}
ReSharper refactors this snippet with RedundantEmptyObjectOrCollectionInitializer
setting:
Expression<Func<TSource, TDest>> expression2 = model => new TDest();
// Result: {model => new TestModel()}
After that, my code doesn't work. What influence do the curly braces have on initializing?
I found What is the Difference Between new object()
and new {}
in C#? on Stack Overflow, but both instances look equal.
expression.GetType().ToString()
is equal to
expression2.GetType().ToString()
What is the difference between these initializations in expression trees?:
var a = model => new TDest{};
var b = model => new TDest();