C# reflection use variable as object.[var]
问题 I'm trying to generate a table in a razor view using reflection to pull the properties from the model. Here is what I've tried: @if (@Model.Count() > 0) { System.Reflection.PropertyInfo[] properties = Model.First().GetType().GetProperties(); <table> <thead> <tr> @foreach (var property in properties) { if (char.IsLower(property.Name.ToCharArray()[0])) //ignore foreign keys { continue; } <th>@property.Name</th> } </tr> </thead> <tbody> @foreach (PCNWeb.Models.Switch item in Model) { /*System