I have the following class in C++/CLI and an explicit template instantiation for the int primitive..
template<typename T> public ref class Number { T _value; public: static property T MinValue { T get() { return T::MinValue; } } static property T MaxValue { T get() { return T::MaxValue; } } property T Value { T get() { return _value; } void set(T value) { if( value<MinValue || value > MaxValue) throw gcnew System::ArgumentException('Value out of range'); _value = value; } } }; template ref class Number<int>;
On compiling this and inspecting the generated assembly using reflector I am able to see a class called Number<int> but while trying to instantiate this same class in C# the compiler complains about some System::Number class not taking a template argument. What am I doing wrong? Can this be done at all?
I have a work around, declare an additional class inheriting the
Number<int>class. This class is now visible in C# and can be instantiated.