Discussion:
Swig: C++ to C#, adding addtional base classes
Praveen Reddy
2012-01-12 05:03:25 UTC
Permalink
Hello All



We are using SWIG to convert C++ code to C#

We need to add additional interfaces (base classes) in the C# code

By default the C# code generated is as follows



MyClass : IDisposable

{

}



Where MyClass is defined in the C++



We need something as shown blow:



MyClass : IDisposable, ICloneable

{

}



So we need the C# classes to have support additional interfaces (e.g.
ICloneable or custom interfaces)



Is it possible? If yes how can it be done?



Thanks and Regards

Praveen Reddy


--------------------------------------------------------------------------
This e-mail, including any attachments, is transmitted for the sole use of the intended recipient and may contain information that may be privileged and confidential. If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution or copying of this e-mail or the information contained herein is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and then delete the original message from your system. Any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of the company.This is your responsibility to ensure this-e-mail and any attachments are virus free. The company accepts no liability for any damage caused by any virus transmitted by this e-mail.
Marouane BEN JELLOUL
2012-01-12 08:56:51 UTC
Permalink
Hi,

In java it is

%typemap(javainterfaces)

You can look at this doc 1.3:

21.9.9 Java code typemaps
http://www.swig.org/Doc1.3/SWIGDocumentation.html#java_code_typemaps


so you can use in C# that is very close

%typemap(csinterfaces) and there is another one look at 18.2 for that
18.2 Differences to the Java module
http://www.swig.org/Doc1.3/SWIGDocumentation.html#csharp_differences_java

Marouane



________________________________
De : Praveen Reddy <***@markem-imaje.com>
À : swig-***@lists.sourceforge.net
Envoyé le : Jeudi 12 Janvier 2012 6h03
Objet : [Swig-user] Swig: C++ to C#, adding addtional base classes



Hello All
 
We are using SWIG to convert C++ code to C#
We need to add additional interfaces (base classes) in the
C# code
By default the C# code generated is as follows
 
MyClass : IDisposable
{
}
 
Where MyClass is defined in the C++
 
We need something as shown blow:
 
MyClass : IDisposable, ICloneable
{
}
 
So we need the C# classes to have support additional interfaces
(e.g. ICloneable or custom interfaces)
 
Is it possible? If yes how can it be done?
 
Thanks and Regards
Praveen Reddy
________________________________
This e-mail, including any attachments, is transmitted for the sole use of the intended recipient and may contain information that may be privileged and confidential. If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution or copying of this e-mail or the information contained herein is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and then delete the original message from your system. Any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of the company.This is your responsibility to ensure this-e-mail and any attachments are virus free. The company accepts no liability for any damage caused by any virus transmitted by this e-mail.
Praveen Reddy
2012-01-12 10:04:14 UTC
Permalink
Hi Marouane



Thanks a lot - the following code in interface file helped me adding ICloneable as base class

%typemap(csbase) Shape "ICloneable"

%typemap(cscode) Shape %{

public object Clone()

{

return null;

}

%}



This raises another question. If the base class type is in other C# assembly - what would be the way to add reference to the SWIG project using the "interface file"?

%typemap(csbase) Shape "IMyInterface"



The definition of IMyInterface is present in other assembly.



Thks and Rgds

Praveen





________________________________

From: Marouane BEN JELLOUL [mailto:***@yahoo.fr]
Sent: Thursday, January 12, 2012 2:27 PM
To: Praveen Reddy
Cc: Swig-users
Subject: Re : [Swig-user] Swig: C++ to C#, adding addtional base classes



Hi,



In java it is

%typemap(javainterfaces)



You can look at this doc 1.3:

21.9.9 Java code typemaps

http://www.swig.org/Doc1.3/SWIGDocumentation.html#java_code_typemaps



so you can use in C# that is very close

%typemap(csinterfaces) and there is another one look at 18.2 for that

18.2 Differences to the Java module

http://www.swig.org/Doc1.3/SWIGDocumentation.html#csharp_differences_java



Marouane



________________________________

De : Praveen Reddy <***@markem-imaje.com>
À : swig-***@lists.sourceforge.net
Envoyé le : Jeudi 12 Janvier 2012 6h03
Objet : [Swig-user] Swig: C++ to C#, adding addtional base classes



Hello All



We are using SWIG to convert C++ code to C#

We need to add additional interfaces (base classes) in the C# code

By default the C# code generated is as follows



MyClass : IDisposable

{

}



Where MyClass is defined in the C++



We need something as shown blow:



MyClass : IDisposable, ICloneable

{

}



So we need the C# classes to have support additional interfaces (e.g. ICloneable or custom interfaces)



Is it possible? If yes how can it be done?



Thanks and Regards

Praveen Reddy

________________________________

This e-mail, including any attachments, is transmitted for the sole use of the intended recipient and may contain information that may be privileged and confidential. If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution or copying of this e-mail or the information contained herein is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and then delete the original message from your system. Any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of the company.This is your responsibility to ensure this-e-mail and any attachments are virus free. The company accepts no liability for any damage caused by any virus transmitted by this e-mail.
AlBor
2012-01-12 16:18:17 UTC
Permalink
Hi.

I suppose it is possible to use something like
%pragma(csharp) moduleimports=
%{
using System;
%}

or

%typemap(csimports) SWIGTYPE "using System;"
Hope that will help.

Regards,
Alex.
--
View this message in context: http://old.nabble.com/Swig%3A-C%2B%2B-to-C-%2C-adding-addtional-base-classes-tp33125850p33128820.html
Sent from the swig-user mailing list archive at Nabble.com.
Loading...