string A = "a";foreach(System.Reflection.PropertyInfo property in A.GetType().GetProperties())
{
System.Console.WriteLine(property.GetValue(A,null));
}运行到property.GetValue(A,null)这里会报错,TargetParameterCountException,不知道是为什么。谢谢啦
{
System.Console.WriteLine(property.GetValue(A,null));
}运行到property.GetValue(A,null)这里会报错,TargetParameterCountException,不知道是为什么。谢谢啦
string a = "ABC";
PropertyInfo p = a.GetType().GetProperty( "Length" );
if( p != null )
{
Console.WriteLine( p.GetValue( a,null ) );
}
可以。值为3
{
System.Console.WriteLine(property.GetValue(A,null));
}
else
{
for(int i=0; i < property.GetIndexParameters().Length; i++)
{
System.Console.WriteLine(property.GetValue(A,new object[]{i}));
}
}gao ding le
例如:
public class PropertyTest
{
private int[] nTest;
public int this[int Index]
{
get{return nTest[Index];}
set{nTest[Index] =value;}
}
}
//Get properties
Type typ = typeof( PropertyTest );
foreach( PropertyInfo pi in typ.GetProperties( ) )
{
if( pi.Name == "Item" )
{
Debug.WriteLine( "Index property" );
}
}