Example #1
0
 /// <summary>
 /// Create new instance of <see cref="MetaDataType"/>, if <paramref name="tag"/> is known, value from <see cref="PreDefined"/> will be returned.
 /// </summary>
 /// <param name="tag">Tag of metadata.</param>
 /// <returns>New instance of <see cref="MetaDataType"/>, or instance from <see cref="PreDefined"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="tag"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentException"><paramref name="tag"/> contains invalid character.</exception>
 public static MetaDataType Create(string tag)
 {
     tag = checkTag(tag);
     if (PreDefined.TryGetValue(tag, out var r))
     {
         return(r);
     }
     return(new NoValidateMetaDataType(tag));
 }
Example #2
0
 /// <summary>
 /// Create new instance of <see cref="MetaDataType"/>, if <paramref name="tag"/> is known, value from <see cref="PreDefined"/> will be returned.
 /// </summary>
 /// <param name="tag">Tag of metadata.</param>
 /// <param name="parser">Parser for <see cref="Parse(string)"/> method.</param>
 /// <param name="stringifier">Stringifier for <see cref="Stringify(object)"/> method.</param>
 /// <param name="defaultValue">Default value of metadata.</param>
 /// <returns>New instance of <see cref="MetaDataType"/>, or instance from <see cref="PreDefined"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="tag"/> or <paramref name="parser"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentException"><paramref name="tag"/> contains invalid character.</exception>
 /// <remarks>
 /// If instance from <see cref="PreDefined"/> is returned, <paramref name="parser"/> and <paramref name="stringifier"/> will be ignored.
 /// </remarks>
 public static MetaDataType Create <T>(string tag, Func <string, T> parser, Func <T, string> stringifier, T defaultValue)
 {
     if (parser is null)
     {
         throw new ArgumentNullException(nameof(parser));
     }
     tag = checkTag(tag);
     if (PreDefined.TryGetValue(tag, out var r))
     {
         return(r);
     }
     return(new DelegateMetaDataType <T>(tag, parser, stringifier, defaultValue));
 }