Mark Elston | 4 Dec 02:40

%csmethodmodifiers not working

I have a class that inherits from a base class.  Both
classes have a "getType" method (defined as virtual in the
base class).  I have added the following line to my SWIG
interface file:

  %csmethodmodifiers Derived::getType() "override";

where "Derived" is the name of the derived class.

However, the generated C#code doesn't apply the "override" to
the getType method of the derived class.  Whether the above line
is present or not the results are identical.

Is there some way to get the override to work for C#?

Mark

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
David Piepgrass | 4 Dec 17:42

Re: %csmethodmodifiers not working

> I have a class that inherits from a base class.  Both
> classes have a "getType" method (defined as virtual in the
> base class).  I have added the following line to my SWIG
> interface file:
> 
>   %csmethodmodifiers Derived::getType() "override";
> 
> where "Derived" is the name of the derived class.
> 
> However, the generated C#code doesn't apply the "override" to
> the getType method of the derived class.  Whether the above line
> is present or not the results are identical.

%csmethodmodifiers works for me.

Just guessing: try

%csmethodmodifiers Derived::getType "override";

or maybe

%csmethodmodifiers Derived::getType() const "override";

if it's a const function.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
(Continue reading)

Mark Elston | 4 Dec 20:34

Re: %csmethodmodifiers not working

Thanks David.  It turns out that neither of those options
solved the problem but it helped me track it down.  I wound
up taking a closer look at the generated code for *both* the
base and derived classes and found that the return type for
this function was *different* in the two classes.  The reason
was that the header file defining the return type was %include'd
*after* the base class header was %include'd but *before* the
header for the derived class was %include'd.  Once I moved the
header file for the return type earlier in the %include list then
I got what I expected.  In fact, I can remove the %csmethodmodifiers
line entirely and it still provides the "override" modifier
automatically (as expected).

Mark

* David Piepgrass wrote (on 12/4/2008 8:42 AM):
>> I have a class that inherits from a base class.  Both
>> classes have a "getType" method (defined as virtual in the
>> base class).  I have added the following line to my SWIG
>> interface file:
>>
>>   %csmethodmodifiers Derived::getType() "override";
>>
>> where "Derived" is the name of the derived class.
>>
>> However, the generated C#code doesn't apply the "override" to
>> the getType method of the derived class.  Whether the above line
>> is present or not the results are identical.
> 
> %csmethodmodifiers works for me.
(Continue reading)

William S Fulton | 4 Dec 23:15
Favicon

Re: %csmethodmodifiers not working

Mark Elston wrote:
> I have a class that inherits from a base class.  Both
> classes have a "getType" method (defined as virtual in the
> base class).  I have added the following line to my SWIG
> interface file:
> 
>   %csmethodmodifiers Derived::getType() "override";
> 
> where "Derived" is the name of the derived class.
> 
> However, the generated C#code doesn't apply the "override" to
> the getType method of the derived class.  Whether the above line
> is present or not the results are identical.
> 
> Is there some way to get the override to work for C#?
You shouldn't need to put in override manually but should you need to, 
%csmethodmodifiers needs to come before the class declaration. I think 
you need to post a cut down version to display your problem because it 
should just work unless you've done something unusual.

William

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/

Gmane