[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-atl
Subject:    Re: Default Procedures VB vs. C++
From:       "Marsh, Drew" <dmarsh () MIMEO ! COM>
Date:       2001-04-26 17:36:05
[Download RAW message or body]


I've been following this thread and some of the remarks about "default
properties/methods" not being in .NET are somewhat misleading.

In .NET, there is support for default members at the language level. In C# a
default member is usually an "indexer"[1] (though it doesn't have to be[2]),
if an class provides an indexer  it would look something like this:

<codeSnippet language="C#">
public class Foo
{
        public object this[int position]
        {
                get { ... impl. here ... }
                set { ... impl. here ... }
        }
}
</codeSnippet>

This will actually emit a get/set accessor pair and a property that maps
them with the default name of "Item".

In VB this is done by using the Default keyword on a property declaraion [3]
and would something like this:

<codeSnippet language="VB.NET">
Public Default Property Item(Integer Position) As Object
        Get
                ... impl. here ...
        End Get

        Set
                ... impl. here ...
        End Set
End Propert
</codeSnippet>

To use a default property from C#, you use Array like notation... like so:

<codeSnippet language="C#">
Foo myFoo = new Foo();
object item;

item = myFoo[0];
</codeSnippet>

To use a default property from VB.NET, you use Array like notation as
well... like so:

<codeSnippet language="C#">
Dim myFoo As Foo = new Foo();
Dim item As Object

item = myFoo(0);
</codeSnippet>

In a language like MC++, there is (just like COM in C++) no special concept
for accessing default properties, you simply use the accesor methods.

<codeSnippet language="MC++">
Foo* myFoo = new Foo();
Object* item;

myFoo->getItem(&item);
</codeSnippet>

For more details, check the .NET SDK and join the DM .NET mailing list at
<http://discuss.develop.com>. Please forgive any coding errors as I whipped
this together rather quickly. ;)

HTH,
Drew

[1] see section 10.8 of the C# language spec. for more details:
<http://msdn.microsoft.com/library/default.asp?URL=/library/dotnet/csspec/vc
lrfcsharpspec_10_8.htm>
[2] see DefaultMemberAttribute in the .NET SDK for more details:
<http://msdn.microsoft.com/library/default.asp?URL=/library/dotnet/cpref/frl
rfSystemReflectionDefaultMemberAttributeClassTopic.htm>
[3] see section 7.6.3 of the VB language spec. for more details (not
available online)

----------------------------------------------------------------
Users Guide http://msdn.microsoft.com/workshop/essentials/mail.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:ATL-signoff-request@DISCUSS.MICROSOFT.COM

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic