I have a function like this:
public static int WriteLog(string messageCode, params string[] parameters)
{ ///do some operation here }
Based on the first argument(messageCode) the other arguments names change. Now i prepared this function for developers, and I want to know whether the is any way to load the name of other arguments, when they type messageCode and after that they can see the name of the next arguments.
For example if they type "first" for messageCode and call the function, Visual Studio shows them something like this:
When they type "second" for messageCode and call the function, Visual Studio shows something like this:
You can't do that. There's simply no way of representing that in C# with your current approach.
What you could do is have a bunch of classes each with a WriteLog
method, in a sort sort of pattern which emulates Java enums to some extent. So something like this:
public class LogMessage
{
public static FirstMessage First { get { return FirstMessage.Instance; } }
public static SecondMessage Second { get { return SecondMessage.Instance; } }
// Prevent instantiation outside this class's program text.
private LogMessage() {}
protected void LogImpl(string code, params string[] parameters)
{
...
}
// You may have some common public methods here, potentially...
public sealed class FirstMessage : LogMessage
{
internal readonly static FirstMessage Instance = new FirstMessage();
private FirstMessage() {}
public void WriteLog(string userName, string logSource, int targetLocation)
{
// Call to LogImpl here
}
}
// Ditto for SecondMessage
}
Then the calling code would use:
// Intellisense will prompt here...
LogMessage.First.WriteLog(...);
See more on this question at Stackoverflow