>> In IL, return type is a valid manner of determining an overload, no such
>> functionality exists in C#(or VB or C++ to my knowledge, Eiffel supports
[quoted text clipped - 24 lines]
> wonder what would happen if you ran such a COM interface through tlbimp.
> I'll follow up if I dig into that.
Alot of COM interop code I see doesn't use properties, I'll find just get_
and set_ methods. I would assume that is because of that.
As for a suggestions box...there is an email(mswish@microsoft.com), although
it should be treated as one way and will probably not garner a response.
That is about the only thing I know of. Otherwise writing in the framework
and C# groups is probably your best path. The communication paths to MS
itself aren't as nice as they could be.
> Mike
> I created an assembly using System.Reflection.Emit that had an overloaded
> property, with one 'get' and two 'set's - both properties are of the same
[quoted text clipped - 5 lines]
> language; try directly calling accessor methods 'mysample.get_testprop()' or
> 'mysample.set_testprop(int)'
Turns out I made a mistake when generating the assembly. When I did it
correctly, according to my intention in my previous post, here is the error
message I get:
error CS0121: The call is ambiguous between the following methods or
properties: 'mysample.testprop' and 'mysample.testprop'
I get that regarless of which accessor I try to use (get, or either of the
set's).
I also discovered that System.Reflection.Emit.PropertyBuilder *will* let you
assign multiple 'set' methods to a single property (just call SetSetMethod
more than once!), and ildasm shows them correctly. Here is the text from
ildasm:
.property int32 testprop()
{
.set instance void mysample::set_testprop(int32)
.get instance int32 mysample::get_testprop()
.set instance void mysample::set_testprop(string)
} // end of property mysample::testprop
I am able to load this assembly, and using reflection, create an instance of
the object. This means that it must be JIT-ing correctly, so the CLR is not
enforcing the restriction you quoted from the spec.
Using reflection, I am able to call all three accessors using
Type.GetMethod().Invoke().
I can call the get_ accessor using Type.GetProperty().GetValue(), but
calling Type.GetProperty().SetValue() only works for the set_ accessor that
is declared last in the IL.
However, when trying to use this from C#, I get the error I showed in my
previous post:
error CS1545: Property, indexer, or event 'testprop' is not supported by the
language; try directly calling accessor methods 'mysample.get_testprop()' or
'mysample.set_testprop(string)'
> I seem to remember that this arrangement was possible with IDispatch. I
> wonder what would happen if you ran such a COM interface through tlbimp.
> I'll follow up if I dig into that.
I checked on this also. It turns out that the IDispatch interface itself is
capable of this, and it also seems that the TLB file format can express it,
but MIDL refuses to compile overloads.
So, if you had a completely IDispatch scenario, which is common with ActiveX
scripting or other pure Automation languages, you could do it. But in that
case, there is no need for a TLB. No TLB, no tlbimp.
Mike
Daniel O'Connell [C# MVP] - 22 Feb 2004 08:50 GMT
>> I created an assembly using System.Reflection.Emit that had an overloaded
>> property, with one 'get' and two 'set's - both properties are of the same
[quoted text clipped - 17 lines]
> error CS0121: The call is ambiguous between the following methods or
> properties: 'mysample.testprop' and 'mysample.testprop'
This is expected, property overloading isn't a feature of C#. Due to the
nature of properties, the set method's value param is expected to be the
same type as the return value. A solution could be overloading by return
type, but that has other ramifications.
> I get that regarless of which accessor I try to use (get, or either of the
> set's).
[quoted text clipped - 11 lines]
> .set instance void mysample::set_testprop(string)
> } // end of property mysample::testprop
This seems like something that should fail, as its against the CLI spec.
Interestingly on a round trip ilasm should cut off
mysample::set_testprop(int32), it did in my earlier IL tests.
> I am able to load this assembly, and using reflection, create an instance
> of
[quoted text clipped - 16 lines]
> or
> 'mysample.set_testprop(string)'
Its unfortunate the runtime isn't respecting the spec in that manner, I
guess they left it up to compilers and such to get it right(I didn't read
the spec fully, that may have been a requirement for IL producers, not
nessecerily consumers, I'll have to check on that). I think a solution using
.other methods would be a better one, all in all. However since reflection
and languages will only use the last setter the issue isn't too important.
SetSetMethod should simply set the setter instead of adding a new one, even
the name suggests this. I'm curious if Mono duplicates this or not. I would
assume this may actulaly be a bug, I think due to the nature of the
underlying system more than anything else.
>> I seem to remember that this arrangement was possible with IDispatch. I
>> wonder what would happen if you ran such a COM interface through tlbimp.
[quoted text clipped - 13 lines]
>
> Mike