   [.net] Wrap C++ template class in C#
  Hello.I'm fairly new to C# and since a few weeks i'm trying to evaluate the dificulty of wrapping a C++ system in C#.Actually everything goes fine, i would say that it's pretty easy with VisualStudio 2005 and .NET 2.0.There is still one problem left for me:How can i wrap my C++ template class ( for exemple: simple Array class ) in C#.I have read the the mecanism used by .NET and C# to handle genericity is very diferent than the one used by C++.Do you have any links or info to a simple solution to this problem ??Thanks a lot..Clément   
  What specifically are you trying to do/wrap, and how are you doing it (p/invoke? C++/CLI wrapper? what?). C# provides a perfectly serviceable dynamic array (List<T>) so there is precious little need for you to wrap your own hand-rolled implementation. When interoperating, it's preferable to wrap on a high level (calls that cross the managed/unmanaged boundaries should be as infrequent as possible and perform as much work as possible) rather than a low level.If you feel you need to wrap your custom C++ dynamic array, you're probably thinking too low level. Expose the unmanaged API in a different fashion that allows you to use the standard List<T>, if you even need to use an array at all.   ;  Actually i'm using C++/CLI to wrap my c++ code into a managed Dll that i import within my C# project.Suppose i want to wrap a very specific template class that i whant to use in my C# project.. how can i do that ?? :)thanks   ;Quote:Original post by ClementLuminyActually i'm using C++/CLI to wrap my c++ code into a managed Dll that i import within my C# project.Suppose i want to wrap a very specific template class that i whant to use in my C# project.. how can i do that ?? :)thanksIn standard C++, template classes are resolved at compile time, basically "class generators" for the compiler. The compiler will generate a copy of the class definition for each type that is used for the template parameter. So, for "vector<int>" and "vector<float>", you'll end up with two seperate classes, one each for the types int and float.In .NET 2.0+ (not just C#), generic classes are resolved at runtime. They are special constructs that maintain their type information. There is only ever one copy of the class definition, and that class definition keeps track of the type of objects being used with it. So, "List<int>" and "List<float>" use the same class definition.Because of this, you can created a templated class of managed types because the runtime type information is unimportant to the template class, but you cannot create a generic class of unmanaged types, as the type information for unmanaged types isn't availabe at runtime.More information