public bool TryConvert(object from, Type toType, object conversionHint, out object result) { result = null; if (toType == typeof(string)) { result = from?.ToString(); return(true); } if (toType == typeof(StringOption)) { if (from is string value) { var option = StringOptions.GetAnyByValue(value); return(option != null); } } if (toType == typeof(Enum)) { // compiler doesn't recognize this...? //if (Enum.TryParse(toType, from.ToString(), out var val)) result = Enum.Parse(toType, from.ToString()); return(true); } if (toType == typeof(object)) { result = from?.ToString(); return(true); } return(false); }
/// <summary> /// Creates a slider with discrete string options. Enables use of /// <seealso cref="Items"/> and <seealso cref="SelectedItem"/>. /// </summary> /// <param name="name">Name that appears as the title</param> /// <param name="value">Initial value of the slider</param> /// <param name="options">The <seealso cref="IOption.Name"/>s /// of this are used to set <seealso cref="SelectedItem"/></param> /// <param name="returnValue"></param> public PopSlider(string name, string value, StringOptions options, Action<string> returnValue) { InitializeComponent(); this.BindingContext = options; InitializeDiscreteSteps(name, value, options.ToNames()); WireEvents(returnValue, null); }
internal StringSubType(string start, string end, StringOptions flags, byte index) { Start = start; End = end; Flags = flags; Index = index; }
public void PrintOptions(string indent) { StringOptions options = new StringOptions(null); options.PrintOptions(indent); options.PrintDerivedOptions(indent); }
/// <summary> /// Returns a string that represents the current object with the specified options. /// </summary> /// <param name="options">The options to represent the current object.</param> /// <returns>A string that represents the current object.</returns> public string ToString(StringOptions options) { var assertionProperties = string.Join( options.Separator, GetAssertionProperties().Select(p => $"{p.Description}: {(p.Value as AssertionObject)?.ToString(options.ToNextLevel()) ?? p.Value ?? "<null>"}" ) ); return($"{options.Prefix}{assertionProperties}{options.Suffix}"); }
private static string Format(string input, StringOptions options) { if (options.HasFlag(StringOptions.IgnoreCase)) { input = input.ToUpperInvariant(); } if (options.HasFlag(StringOptions.IgnoreWhitespace)) { input = input.Trim(); } return(input); }
public int IndexStringFlag(string param) { // // Returnerer lengden på flagget som ble funnet, 0 dersom ikke funnet // var best_match = new StringOptions(); int best_length = 0; // Sjekk mot longname først foreach (var item in so) { if (param.StartsWith(item.longname) && item.longname != "") { if (item.longname.Length > best_length) { best_length = item.longname.Length; best_match = item; } } } if (best_length != 0) { return(best_match.longname.Length); } // Ikke funnet som longname, sjekk mot shortname foreach (var item in so) { if (param.StartsWith(item.shortname) && item.shortname != "") { if (item.shortname.Length > best_length) { best_length = item.shortname.Length; best_match = item; } } } if (best_length != 0) { return(best_match.shortname.Length); } return(0); // Default }
public void AddStringOpt(string flags) { // Oppretter ny StringOpions med lange og korte flaggnavn StringOptions stro = new StringOptions(); string[] f = flags.Split(" "); if (f.Length == 1) { stro.shortname = f[0]; stro.longname = ""; } if (f.Length == 2) { stro.shortname = f[0]; stro.longname = f[1]; } so.Add(stro); }
private static void Init(string id_property, StringOptions str, EnumerableOptions enumr) { if (_id == null) { _id = id_property; } if (_stroptions == null) { _stroptions = str; } if (_enumerableoptions == null) { _enumerableoptions = enumr; } if (_tracker == null) { _tracker = new List <int>(); } }
internal void Add(string start, string end, StringOptions flags) { base.Add(new StringSubType(start, end, flags, (byte)this.Count)); }
public void AddPrefix(string prefix, StringOptions flags) { base.AddPrefixFlag(prefix, (short)flags); }
public void AddStartEnd(string startSymbol, string endSymbol, StringOptions stringOptions) { _subtypes.Add(startSymbol, endSymbol, stringOptions); }
public void AddStartEnd(string startEndSymbol, StringOptions stringOptions) { AddStartEnd(startEndSymbol, startEndSymbol, stringOptions); }
public StandardStringMatcher(string start, string end, StringOptions flags) : base(flags) { Start = start; End = end; }
public bool Initialize(ILogOptions logoptions, string[] args) { this.options = new StringOptions(logoptions); this.options.Parse(args); return(!this.options.HasErrors); }
private static bool IsSet(this StringOptions stringOptions, StringOptions flags) { return (stringOptions & flags) == flags; }
public static FingerprintBuilder <T> Add <T>(this FingerprintBuilder <T> builder, Expression <Func <T, string> > getInputExpression, StringOptions options = StringOptions.None) { return(builder.Add(getInputExpression, input => Format(input, options))); }
/// <summary> /// Creates the random string of predefined character types to the specified length. /// </summary> /// <returns></returns> public static string RandomString(int length, StringOptions stringOptions) { var builder = new StringBuilder(length); var actions = new List<Action>(); if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.Space)) { actions.Add(() => builder.Append(' ')); } if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.AlphaLower)) { actions.Add(() => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(26 * Generator.NextDouble() + 97))))); } if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.AlphaUpper)) { actions.Add(() => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(26 * Generator.NextDouble() + 65))))); } if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.Numeric)) { actions.Add(() => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(10 * Generator.NextDouble() + 48))))); } if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.Punctuation)) { actions.Add(() => builder.Append(RandomPunctuation())); } if (StringOptions.All == stringOptions || stringOptions.IsSet(StringOptions.Typography)) { actions.Add(() => builder.Append(RandomTypography())); } if (actions.Count == 0) { throw new ArgumentException("Unknown string options configuration", "stringOptions"); } for (int i = 0; i < length; i++) { actions[Generator.Next(0, actions.Count)](); } return builder.ToString(); }
public RegexStringMatcher(Regex start, string shortcut, string endFormat, StringOptions flags) : base(flags) { Start = start; StartShortcut = shortcut; Format = endFormat; }
public static BnfiTermConversion <string> CreateStringLiteral(string name, string startEndSymbol, StringOptions options) { return(new StringLiteral(name, startEndSymbol, options).IntroStringLiteral()); }
public StringLiteral(string name, string startEndSymbol, StringOptions stringOptions) : this(name) { _subtypes.Add(startEndSymbol, startEndSymbol, stringOptions); }
/// <summary> /// Creates the random string of predefined character types to the specified length /// </summary> /// <returns></returns> public static string RandomString(int length, StringOptions stringOptions) { StringBuilder builder = new StringBuilder(length); Random random = RandomGenerator(); Action spc = () => builder.Append(' '); Action ucc = () => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)))); Action lcc = () => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 97)))); Action nmc = () => builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(10 * random.NextDouble() + 48)))); Action puc = () => builder.Append(RandomPunctuation()); Action tyc = () => builder.Append(RandomTypography()); List<Action> actions = new List<Action>(); if (StringOptions.All == stringOptions) { actions.Add(spc); actions.Add(ucc); actions.Add(lcc); actions.Add(nmc); actions.Add(puc); actions.Add(tyc); } else { if (stringOptions.IsSet(StringOptions.Space)) { actions.Add(spc); } if (stringOptions.IsSet(StringOptions.AlphaLower)) { actions.Add(lcc); } if (stringOptions.IsSet(StringOptions.AlphaUpper)) { actions.Add(ucc); } if (stringOptions.IsSet(StringOptions.Numeric)) { actions.Add(nmc); } if (stringOptions.IsSet(StringOptions.Punctuation)) { actions.Add(puc); } if (stringOptions.IsSet(StringOptions.Typography)) { actions.Add(tyc); } } if (actions.Count == 0) { throw new ArgumentException("Unknown string options configuration", "stringOptions"); } for (int i = 0; i < length; i++) { actions[random.Next(0, actions.Count)](); } return builder.ToString(); }
public StringLiteral(string name, string startEndSymbol, StringOptions options, Type astNodeType) : this(name, startEndSymbol, options) { base.AstNodeType = astNodeType; }
public StringLiteral(string name, string startEndSymbol, StringOptions options, AstNodeCreator astNodeCreator) : this(name, startEndSymbol, options) { base.AstNodeCreator = astNodeCreator; }
public async Task SendQueryAsync() { IsEnabled = false; var path = ProtocolCommand.FormatPath(); var command = $"{path}?"; var result = ""; if (App.Mock) { await Task.Delay(1); result = DefaultResponse; } else { var response = await AppLocator.TelnetService.SendCommandAsync(command, true); // remove line terminator result = response?.TrimEnd(); } if (result.Length == 0) { return; } if (result == "Command error") { throw new InvalidOperationException($"Command error: {command}"); } var propInfo = _propInfo ?? this.GetType().GetProperty(nameof(Value)); if (_propInfo == null) { _propInfo = propInfo; } var type = typeof(T); if (type == typeof(string) || type == typeof(StringOption)) { var value = StringOptions.GetByTerm(ProtocolCommand.Options, result); propInfo.SetValue(this, $"{value}"); } else if (type == typeof(bool)) { propInfo.SetValue(this, result == "1"); } else if (type == typeof(int) || type == typeof(IntegerOption)) { if (int.TryParse(result, out var val)) { propInfo.SetValue(this, val); } } else if (type == typeof(double) || type == typeof(RealOption)) { if (double.TryParse(result, out var val)) { propInfo.SetValue(this, val); } } IsEnabled = true; if (!ProtocolCommand.Name.Contains("Status")) { System.Diagnostics.Debug.WriteLine($"{ProtocolCommand.Name}: {Value}"); } }
public StringMatcher(StringOptions flags) { Flags = flags; }