Good morning.
i have a problem with my code in c#.
this below is the right code(i can take the var name end so have string varName="E01020003") :
public void writeTest()
{
varName = getVarName(() => E01020003);
...
...
}
public string VarName<T>(Expression<Func<T>> expr)
{
var body = ((MemberExpression)expr.Body);
return body.Member.Name;
}
these two methods are in the same file .cs
i would like to to this:
FILE1:
public void Write()
{
...
...
...
file2.Write(userCred, E01020018, () => E01020003, (int)Type.Info, "test");
}
FILE2:
public bool Write(UserCredentials userCredentials, string ErrorText, Expression<Func<T>> expr, int type, string infoText)
{
bool returnValue = true;
var body = ((MemberExpression)expr.Body);
string varName = body.Member.Name;
...
...
...
}
is it possible? i have problem to pass a lambda like a parameter.
problem 1 in the call
file2.Write(userCred, E01020018, () => E01020003, (int)Type.Info, "test");
and in the method called:
Write(UserCredentials userCredentials, string ErrorText, Expression<Func<T>> expr, int type, string infoText)
Best regards