DefaultValue and String in Managed C++

  • Thread starter Thread starter Bram Vandendriesschen
  • Start date Start date
B

Bram Vandendriesschen

Hi,
anyone an idea how to get DefaultValue's working for
String properties in managed C++.
I wrote a component in managed C++ which I plan to consume
in C#. Now the IDE keeps inserting null-assignments for
the string properties, while I've specified that NULL is
the default value. Other types work well.

thanks in advance,
Bram.
 
Bram,

microsoft.public.dotnet.languages.vc is a better group for C++
questions.

Now the IDE keeps inserting null-assignments for
the string properties, while I've specified that NULL is
the default value. Other types work well.

Can you post your code?



Mattias
 
Hi,
thanks for looking into my problem.
the code (managed C++) goes like this:

public __gc class SomeClass : public System::ComponentModel::Component
{
public:
SomeClass();
SomeClass(System::ComponentModel::IContainer container);
....
[DefaultValue(NULL)]
__property String* get_Kind();
[DefaultValue(NULL)]
__property String* set_Kind(String* value);
....
// other properties and methods
};

This class gets compiled into a component library. After dropping this
component on
a form (in C Sharp), the designer adds this line to the InitializeComponent
method of the form:

this.someClass1.Kind = null;

while I explicitly stated that that's the default value. BTW, it works as
expected with other types
like int, short, ...

I don't get it.
I am not using VS.NET 2003. It might be solved already (if it's a bug).

regards,
Bram.
 
Bram,
[DefaultValue(NULL)]

Since NULL is defined as 0, that compiles down to [DefaultValue(0)]
using the int constructor. And to managed code, 0 != null.

I tried some other possibilities, but wasn't able to get the same as
[DefaultValue(null)] does in C#. That's partly due to a compiler bug.

I suggest you re-post your problem to the VC newsgroup, where it's
more likely to be seen by people who know this stuff.



Mattias
 
Back
Top