/// <summary> /// Gets the messages that's mapped to the specified type. /// </summary> /// <param name="type">The type to get the message for.</param> /// <returns>string</returns> public string GetMessage(Type type) { if (MessageAccessor != null) { T obj = (T)Activator.CreateInstance(type); return(MessageAccessor(obj)); } return(ResourceProxy.GetString(ResourceKey)); }
/// <summary> /// Gets the messages that's mapped to the specified object. /// </summary> /// <param name="obj">The object to get the message for.</param> /// <exception cref="FormatException">Thrown if the number of data items do not match the number of string formaters.</exception> /// <returns>string</returns> public string GetMessage(object obj) { string message = MessageAccessor != null?MessageAccessor((T)obj) : ResourceProxy.GetString(ResourceKey); // If there are data items (WithValue), then // format the resource string with the given values. if (DataItems.Count > 0) { message = string.Format(message, DataItems.Select(accessor => accessor((T)obj)).ToArray <object>()); } return(message); }