/// <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); } })); }
/// <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; }