'object.GetType()'是一个'方法',在给定的上下文中无效 [英] 'object.GetType()' is a 'method', which is not valid in the given context

查看:247
本文介绍了'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


这篇关于'object.GetType()'是一个'方法',在给定的上下文中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆