标准property
定义:
ref class DefProperty
{
private:
String^ mData;
public:
property String^ MyData
{
String^ get();
void set(String^);
}
};
实现:
String^ DefProperty::MyData::get()
{
return mData;
}
void DefProperty::MyData::set(String^ value)
{
mData = value;
}
简化的property
ref class EasyProperty
{
public:
property String^ MyData;
};
静态property
定义:
ref class StaticProperty
{
private:
static String^ mData;
public:
static property String^ Data1;
static property String^ Data2
{
String^ get();
void set(String^);
}
};
实现:
String^ StaticProperty:Data2::get()
{
return mData;
}
void StaticProperty:
{
mData = value;
}
虚拟property
定义:
interface class IProperty
{
public:
property String^ Data1;
property String^ Data2
{
String^ get();
void set(String^);
}
};
ref class VirtualProperty : public IProperty
{
protected:
String^ mData2;
String^ mData3;
public:
property String^ Data1;
property String^ Data2
{
String^ get();
void set(String^);
}
property String^ Data3
{
virtual String^ get();
virtual void set(String^);
}
};
ref class VirtualPropertyNew : public VirtualProperty
{
public:
property String^ Data2
{
String^ get();
void set(String^);
}
property String^ Data3
{
virtual String^ get();
virtual void set(String^);
}
};
实现:
String^ VirtualProperty:
{
return mData2->Insert(0,"Base2:");
}
void VirtualProperty:
{
mData2 = value;
}
String^ VirtualProperty:
{
return mData3->Insert(0,"Base3:");
}
void VirtualProperty:
{
mData3 = value;
}
String^ VirtualPropertyNew:
{
return mData2->Insert(0,"New2:");
}
void VirtualPropertyNew:
{
mData2 = value;
}
String^ VirtualPropertyNew:
{
return mData3->Insert(0,"New3:");
}
void VirtualPropertyNew:
{
mData3 = value;
}
索引property
ref class IdxProperty
{
public:
property int default[int]
{
int get(int idx)
{
return 0;
}
void set(int idx, int value)
{
}
}
property int default[String^]
{
int get(String^ idx)
{
return 0;
}
void set(String^ idx, int value)
{
}
}
property int ItemSlot[int]
{
int get(int idx)
{
return 0;
}
void set(int idx, int value)
{
}
}
property int Data3D[int,int,int]
{
int get(int x,int y,int z)
{
return 0;
}
void set(int x,int y,int z, int v)
{
}
}
};