Using reflection to access property names from the class in ASP.NET MVC

There are sometimes situations where we want to to find out what is the name of the property of the class when application is running.

To access name of the single property we use reflection:

public static string GetPropertyName<T, TValue>(Expression<Func<T, TValue>> memberAccess)
{
    return ((MemberExpression)memberAccess.Body).Member.Name;
}
We can access all properties without writing static method.

foreach (var item in new T().GetType().GetProperties())
{
    // Get name for single item -  item.Name.ToString()
} 


Comments

  1. Fiction Factory builds customized interiors for B2B global and native manufacturers of various sectors such as retail, hospitality, fairs, pavilions, exhibitions, offices and specials. With constructing customized interiors, Fiction Factory has a wooden waste stream of which 70% comes from digital CNC router manufacturing. This wooden waste is unused materials that shall be burned as recycling corporations classify this waste as low high quality. In the Netherlands, might be} an average of 30% of wooden waste within inside constructing corporations . The present workflow and technologies used within the business lack flexibility and Fingerprint Scanners Door Locks usually are not adapted to highly-customised and one-off initiatives such as those that Fiction Factory offers with every single day. An artist, a expertise supplier and a Manufacturing firm kind this multidisciplinar consortium that may benefit of|benefit from|reap the benefits of} the EU funded RAMP platform to deploy this new solution.

    ReplyDelete

Post a Comment