Given the example below, is it possible to use () => MyProperty syntax to infer MyClass?
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace MyNamespace
{
class Program
{
private static void Main(string[] args)
{
// This compiles fine:
var map = new Dictionary<Expression<Func<MyClass, object>>, string>
{
// Lambda Expression has a single argument of "MyClass".
{x => x.MyProperty, "Hello world"}
};
// Is is possible to initialize Dictionary using parameter-less lambda?
var map2 = new Dictionary<Expression<Func<??????>>, string>
{
// Can the Lambda be parameter-less (infer MyClass automagically)?
{() => MyProperty, "Hello world"}
};
}
}
class MyClass
{
public string MyProperty { get; set; }
}
}
Code also on .NET Fiddle: https://dotnetfiddle.net/OVERm3
SomeProperty? what should happen then ?public class Batman { public string SomeProperty {get;set;} }. The author of this 3rd party library you are using just added it to his library. Oh, and you collegue just added such a coolBatmanclass also to the project you both are working on. No problem there, i guess, since the class is concrete ;-)