Starting from C# 6, you should be able to use the nameof
operator:
string propertyName = nameof(BaseRequest<ISomeInterface>.Request);
The generic type parameter used for BaseRequest<T>
is irrelevant (as long as it meets the type constraints), since you are not instantiating any object from the type.
For C# 5 and older, you can use Cameron MacFarland's answer for retrieving property information from lambda expressions. A heavily-simplified adaptation is given below (no error-checking):
public static string GetPropertyName<TSource, TProperty>(
Expression<Func<TSource, TProperty>> propertyLambda)
{
var member = (MemberExpression)propertyLambda.Body;
return member.Member.Name;
}
You can then consume it like so:
string propertyName = GetPropertyName((BaseRequest<ISomeInterface> r) => r.Request);
// or //
string propertyName = GetPropertyName<BaseRequest<ISomeInterface>, ISomeInterface>(r => r.Request);