using System.Collections.Generic;
using System.Linq.Expressions;
public static void Main()
FindPropertyNames<Student>(x => new object[] { x.Name, x.Age, x.Country }).Dump();
FindPropertyNames<Student>(x => x.Name + x.Age + x.Country).Dump();
public static List<string> FindPropertyNames<T>(Expression<Func<T, object>> expr)
var visitor = new FindPropertiesVisitor(expr.Parameters[0]);
public class FindPropertiesVisitor : ExpressionVisitor
private readonly Expression parameter;
public List<string> Names { get; } = new List<string>();
public FindPropertiesVisitor(Expression parameter) => this.parameter = parameter;
protected override Expression VisitMember(MemberExpression node)
if (node.Expression == parameter)
Names.Add(node.Member.GetCustomAttribute<JsonPropertyAttribute>().PropertyName);
public string Name { get; set; }
public int Age { get; set; }
[JsonProperty("country")]
public string Country { get; set; }
public class JsonPropertyAttribute : Attribute
public string PropertyName { get; set; }
public JsonPropertyAttribute(string name) => PropertyName = name;