问题
I have defined following code in C++ CLI.
However when I want to call SetColor the first parameter which is supposed to appear as System.Drawing.Color; appears as ValueType.
This also let me to pass any variable into it. No matter if it's Color
or not.
[System::Runtime::CompilerServices::ExtensionAttribute]
public ref class MyExtensions abstract sealed {
public:
[System::Runtime::CompilerServices::ExtensionAttribute]
static System::String^ SetColor(System::String^ in, System::Drawing::Color^ ext) {
return gcnew System::String("{") +
ext->R.ToString("X") + ext->G.ToString("X") + ext->B.ToString("X")
+ gcnew System::String("}") + in;
}
};
回答1:
Color is a struct. Remove the ^
from the parameter System::Drawing::Color^ ext
.
Also, gcnew System::String("{")
is redundant. Just use "{"
directly, it's already a String object.
来源:https://stackoverflow.com/questions/15419974/why-c-sharp-change-my-color-structure-to-valuetype