PropertyInfo indexAccessor = A.GetType().GetProperty("Item", BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.SetProperty); if (indexAccessor != null) { // Get the first item. object value = indexAccessor.GetValue(A, new object[] { 0 }); // Set the first item to null. indexAccessor.SetValue(A, null, new object[] { 0 }); }
http://www.cnblogs.com/shenba/archive/2007/11/24/970919.html有方法的。
PropertyInfo indexAccessor = A.GetType().GetProperty("Item",
BindingFlags.Public
| BindingFlags.Instance
| BindingFlags.GetProperty
| BindingFlags.SetProperty);
if (indexAccessor != null)
{
// Get the first item.
object value = indexAccessor.GetValue(A, new object[] { 0 });
// Set the first item to null.
indexAccessor.SetValue(A, null, new object[] { 0 });
}