/// <summary>Uses a standard <see cref="ResourceManager"/> object to obtain translations.</summary> /// <param name="manager">A ResourceManager that provides access to resources (resx embedded in an assembly)</param> /// <param name="culture">A value of <see cref="CultureInfo"/> that /// represents the language to look up in the ResourceManager. If this is /// null, the ResourceManager will use CultureInfo.CurrentUICulture.</param> /// <param name="resxNameCalculator">An optional function that will be /// called when a translation is requested without providing a resource /// key symbol. For example, if someone writes <c>"Save as...".Localized()</c> /// using the <see cref="Localized(string)"/> extension method, this /// function is called on the string "Save as...". This function could /// be used to compute a resource name such as "strSaveAs" automatically, /// according to whatever naming convention is used in your resource file. /// </param> /// <param name="fallbackToPrevious">If a translation was not found in the /// specified ResourceManager and this parameter is true, the previously- /// installed <see cref="Localizer"/> is called instead. Otherwise, the /// dummy translator <see cref="Passthru"/> is used.</param> /// <returns></returns> public static SavedValue <LocalizerDelegate> UseResourceManager(ResourceManager manager, CultureInfo culture = null, Func <string, string> resxNameCalculator = null, bool fallbackToPrevious = true) { CheckParam.IsNotNull("manager", manager); LocalizerDelegate fallback = (fallbackToPrevious ? Localizer : null) ?? Passthru; return(SetLocalizer((Symbol resourceId, string defaultMessage) => { string id; if (resourceId != null) { id = resourceId.Name; } else { id = (resxNameCalculator != null ? resxNameCalculator(defaultMessage) : null) ?? defaultMessage; } var translation = manager.GetString(id, culture); if (translation != null) { return translation; } else { return fallback(resourceId, defaultMessage); } })); }
void IDictionary <Symbol, ValueT> .Add(Symbol key, ValueT value) { if (this.HasTag(key)) { CheckParam.ThrowBadArgument(nameof(key), "The key '{0}' already exists in the IDictionary", key.Name); } this.SetTag(key, value); }
/// <summary>Checks if the sequences of characters <c>what</c> is equal to /// <c>sb.Substring(start, what.Length)</c>, without actually creating a /// substring object.</summary> public static bool SubstringEquals(StringBuilder sb, int start, UString what, bool ignoreCase = false) { CheckParam.IsNotNegative("start", start); if (start > sb.Length - what.Length) { return(false); } return(SubstringEqualHelper(sb, start, what, ignoreCase)); }
public static int ThrowIfStartOrCountAreBelowZeroAndLimitCountIfNecessary(int start, int count, int outerCount) { if (start < 0) { CheckParam.ThrowBadArgument("The start index was below zero."); } if (count < 0) { CheckParam.ThrowBadArgument("The count was below zero."); } return(count <= outerCount - start ? count : System.Math.Max(outerCount - start, 0)); }
void ICollection <KeyValuePair <Symbol, ValueT> > .CopyTo(KeyValuePair <Symbol, ValueT>[] array, int arrayIndex) { if (((IDictionary <Symbol, ValueT>) this).Count > array.Length - arrayIndex) { CheckParam.ThrowBadArgument("Insufficient space in supplied array"); } if (_attrs == null) { ((ICollection <KeyValuePair <Symbol, ValueT> >)_attrs).CopyTo(array, arrayIndex); } if (_cachedAttrKey != null) { array[arrayIndex] = new KeyValuePair <Symbol, ValueT>(_cachedAttrKey, _cachedAttrValue); } }
/// <summary>Initializes this object.</summary> /// <param name="writer">Required. A method that accepts output.</param> /// <param name="isEnabled">Optional. A method that decides whether to /// output based on the message type. If this parameter is provided, /// then <see cref="Write"/>() will not invoke the writer when isEnabled /// returns false. This delegate is also called by <see cref="IsEnabled"/>().</param> public MessageSinkFromDelegate(WriteMessageFn writer, Func <Severity, bool> isEnabled = null) { CheckParam.IsNotNull("writer", writer); _writer = writer; _isEnabled = isEnabled; }
/// <summary>Initializes this object.</summary> /// <param name="writer">Required. A method that accepts output.</param> /// <param name="isEnabled">Optional. A method that decides whether to /// output based on the message type. If this parameter is provided, /// then <see cref="Write"/>() will not invoke the writer when isEnabled /// returns false. This delegate is also called by <see cref="IsEnabled"/>().</param> public MessageSinkFromDelegate(Action <Severity, object, string, object[]> writer, Func <Severity, bool> isEnabled = null) { CheckParam.IsNotNull("writer", writer); _writer = writer; _isEnabled = isEnabled; }
/// <summary>Returns the rightmost <c>length</c> code units of the string, /// or fewer if the string length is less than <c>length</c>.</summary> public UString Right(int length) { CheckParam.IsNotNegative("length", length); length = System.Math.Min(_count, length); return(new UString(_start + _count - length, length, _str)); }