'object.GetType()'是一个'方法',在给定的上下文中无效

'object.GetType()'是一个'方法',在给定的上下文中无效

问题描述:

下面的代码在标有粗体的行给我错误.它说''object.GetType()是一种"方法,在给定的上下文中无效",请大家帮忙.


System.Reflection.PropertyInfo Imageproperty =默认值(System.Reflection.PropertyInfo);
Imageproperty = flowLayoutPanel1.GetType.GetProperty("Image", typeof(Image));
如果(Imageproperty == null)
{
位图imgNew =新位图(flowLayoutPanel1.Width,flowLayoutPanel1.Height);
flowLayoutPanel1.DrawToBitmap(imgNew,flowLayoutPanel1.ClientRectangle);
返回imgNew;
}
其他
{
return(Image)Imageproperty.GetValue(flowLayoutPanel1,null);
}

below code gives me error at the line marked bold.it says "''object.GetType()'' is a ''method'', which is not valid in the given context" plz any one can help me out.


System.Reflection.PropertyInfo Imageproperty = default(System.Reflection.PropertyInfo);
Imageproperty = flowLayoutPanel1.GetType.GetProperty("Image", typeof(Image));
if (Imageproperty == null)
{
Bitmap imgNew = new Bitmap(flowLayoutPanel1.Width, flowLayoutPanel1.Height);
flowLayoutPanel1.DrawToBitmap(imgNew, flowLayoutPanel1.ClientRectangle);
return imgNew;
}
else
{
return (Image)Imageproperty.GetValue(flowLayoutPanel1, null);
}

将圆括号添加到GetType.

第一行完全没有意义,将其与第二行合并.获得财产的想法很糟糕,不利于维护.你拼错了什么?编译器不会检测到该错误.所有这一切的目的尚不清楚.我严重怀疑这没有道理.

—SA
Add round brackets to GetType.

First line it totally pointless, merge it with second one. The idea of getting a property is bad, not good for maintenance. What is you misspell it? Compiler won''t detect the bug. The purpose of all this is not clear. I seriously suspect it does not make sense.

—SA