How to access a class Data outside another class
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;
}
It's because your class ResourcePolicyConverter
is inheriting from StringConverter
rather than BaseLVItem
. A typo?
The reason you cannot use the Data
property in your second example is that ResourcePolicyConverter
doesn't inherit from BaseLVItem
and thus, the Data property is not available in the base
.
You can simply instantiate a new BaseLVItem
and then access the Data
property.
BaseLVItem lvItem = new BaseLVItem();
IResourcePolicy data = (IResourcePolicy)lvItem.Data;
精彩评论