Let's say I have a simple class like this:
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public readonly Func<object> GuidGen;
public Employee(Func<object> guidGen)
{
GuidGen = guidGen;
var methodInfo = GuidGen.GetMethodInfo();
var returnType = methodInfo.ReturnType;
//ReturnType returns System.Object! not Guid
}
}
When creating an instance I pass an anonymous method that returns a Guid:
var emp = new Employee(() =>
{
return Guid.NewGuid();
}
);
var guid = emp.GuidGen.Invoke();
My question is, is it possible to get the ReturnType
for the anonymous method I'm passing through the Employee
constructor? When I debug I get a ReturnType
of System.Object
instead of Guid
type.
Aucun commentaire:
Enregistrer un commentaire