Default Property from a .NET object

K

kevin_g_frey

Hello All,

I have an MC++ class named "Person" which encapsulates access to a
database entity and it contains a number of field properties eg. Code,
Name, Address, Suburb etc.

Each of the field properties is of type "Field", so we have eg.

__property Field* get_Code( );
__property Field* get_Name( );

etc

The Field class itself has a number of properties such as:

__property String* get_Value( );
__property bool get_IsMandatory( );

etc

My question is this:

To store a value into the "Code" field of a "Person" object I have to
write (from eg. C#):

person.Code.Value = "MyValue";

Under COM I believe it was possible to designate one property in an
object as being the "default property" and therefore the need to
reference that property explicitly disappeared. So the above example
becomes:

person.Code = "MyValue"; // NOTE: "Value" is the default property

Can someone tell me if this possible in .NET? Or perhaps more
importantly is whether this is even an accepted idiom in .NET?

I know there is the "DefaultProperty" attribute that can assigned to a
class, but that is only useful for Indexable properties (eg. an Items
container).

Thanks

Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top