Is there anyway to duplicate the intellisense provided by the Color struct in visual studio?
What I want to do is provide some public static fields that will be used as instances of an interface implementation and have intellisense pick them up when the interface is a method argument.
The idea is to have it look like an enum to the developer. I reference Color because basically this is the behavior I want, I just don't know how to replicate it.
Edit
I don开发者_如何转开发't know what was going on. It seems to be working now. Thanks for the quick help on a stupid question.
The Color struct simply has a bunch of public static properties that return the expected objects. Sample:
public struct Color
{
public Color(int r, int g, int b)
{ /* Init */ }
public static Color Black
{
get { return new Color( 0, 0, 0 ); }
}
}
To clarify my answer. You would simply need to replicate this pattern within your own code to achieve the same affect. I'd recommend looking at the T4 code-gen built into Visual Studio if you have a lot of values that need to be created that already exist else-ware. Just don't add too many. That could confuse the developer and slow down the IDE.
You seem to have answered your own question when asking it - use public static fields:
public class MyClass
{
public const string Value1 = "something one";
public static readonly MyType Value2 = new MyType();
public const int Value3 = 3;
}
public class MyOtherClass
{
public MyOtherClass()
{
string str = MyClass.Value1;
// str == "something one"
}
}
精彩评论