如何访问一个类之外的另一个类的数据
我在 BaseLVItem 类中有一个属性 Data,
namespace Spo.Plugins
{
public class BaseLVItem : System.Windows.Forms.ListViewItem
{
public virtual IBaseObject Data
{
get{ return m_data; }
}
private IBaseObject m_data = null;
我们正确地使用了它,如下所示在类 ResourcePolicySystemsLVI 中,
public class ResourcePolicySystemsLVI : BaseLVItem
{
public new IResourcePolicy Data
{
get
{
return (IResourcePolicy)base.Data;
}
}}
收到错误“System.ComponentModel.StringConverter”不包含“Data”的定义
using Spo.Plugins;
public class ResourcePolicyConverter : StringConverter
{
public new IResourcePolicy Data
{
get
{
return (IResourcePolicy)base.Data;
}
}
但是当我在下面的类中使用时,我 无法在这里实现 BaseLVItem 类,任何人都可以在这里指导我
Dixon 我正在这样实现
public class ResourcePolicyConverter : StringConverter
{
BaseLVItem lvItem = new BaseLVItem();
IResourcePolicy data = (IResourcePolicy)lvItem.Data;
--------------------
else if ((value == null) && data.AgentVersion != null )
{
return m_nullPolicy;
}
I have a property Data in a class BaseLVItem
namespace Spo.Plugins
{
public class BaseLVItem : System.Windows.Forms.ListViewItem
{
public virtual IBaseObject Data
{
get{ return m_data; }
}
private IBaseObject m_data = null;
we used it properly like shown below in a class ResourcePolicySystemsLVI
public class ResourcePolicySystemsLVI : BaseLVItem
{
public new IResourcePolicy Data
{
get
{
return (IResourcePolicy)base.Data;
}
}}
but when i used in the following class i am getting error 'System.ComponentModel.StringConverter' does not contain a definition for 'Data'
using Spo.Plugins;
public class ResourcePolicyConverter : StringConverter
{
public new IResourcePolicy Data
{
get
{
return (IResourcePolicy)base.Data;
}
}
i am not able to implement BaseLVItem class here,Can any body guide me here
Dixon i am implementing like this
public class ResourcePolicyConverter : StringConverter
{
BaseLVItem lvItem = new BaseLVItem();
IResourcePolicy data = (IResourcePolicy)lvItem.Data;
--------------------
else if ((value == null) && data.AgentVersion != null )
{
return m_nullPolicy;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为您的类
ResourcePolicyConverter
继承自StringConverter
而不是BaseLVItem
。拼写错误?It's because your class
ResourcePolicyConverter
is inheriting fromStringConverter
rather thanBaseLVItem
. A typo?您无法在第二个示例中使用
Data
属性的原因是ResourcePolicyConverter
不是从BaseLVItem
继承的,因此 Data 属性不是在base
中可用。您只需实例化一个新的
BaseLVItem
,然后访问Data
属性即可。The reason you cannot use the
Data
property in your second example is thatResourcePolicyConverter
doesn't inherit fromBaseLVItem
and thus, the Data property is not available in thebase
.You can simply instantiate a new
BaseLVItem
and then access theData
property.