private static KeyValuePair <string, string> ParseArgument(string argument, int startIndex, out int endIndex, char namePrefix, bool treatTailAsValue) { if (argument[startIndex] == namePrefix) { int delimiterIndex = -1; char c = '\0'; startIndex++; for ( endIndex = startIndex + 1; endIndex < argument.Length && (CommandHelpers.IsValidNameCharacter(c = argument[endIndex])); endIndex++ ) { ; } if (c == ':') { delimiterIndex = endIndex; } if (argument[startIndex] == '-') { startIndex++; if (delimiterIndex != -1) { throw new InvalidOperationException(); } return(new KeyValuePair <string, string>( argument.Substring(startIndex, endIndex - startIndex), bool.FalseString )); } if (delimiterIndex == -1) { return(new KeyValuePair <string, string>( argument.Substring(startIndex, endIndex - startIndex), bool.TrueString )); } else { return(new KeyValuePair <string, string>( argument.Substring(startIndex, delimiterIndex - startIndex), ReadValue(argument, delimiterIndex + 1, out endIndex, treatTailAsValue) )); } } return(new KeyValuePair <string, string>( string.Empty, ReadValue(argument, startIndex, out endIndex, treatTailAsValue) )); }
private static string GetDefaultContextName() { string entryAssemblyName = Assembly .GetEntryAssembly() .GetName() .Name; char[] defaultContextName = null; for (int i = 0; i < entryAssemblyName.Length; i++) { char ch = entryAssemblyName[i]; if (CommandHelpers.IsValidNameCharacter(ch)) { if (defaultContextName != null) { defaultContextName[i] = ch; } continue; } if (defaultContextName == null) { defaultContextName = new char[entryAssemblyName.Length]; entryAssemblyName.CopyTo(0, defaultContextName, 0, i); } defaultContextName[i] = '_'; } return((defaultContextName != null) ? new string(defaultContextName) : entryAssemblyName); }