Esempio n. 1
0
 /// <summary>
 /// Returns typed partial data if present.
 /// </summary>
 /// <param name="dataSource">Composite metadata source.</param>
 /// <param name="data">Variable to return metadata.</param>
 /// <returns>
 /// <c>true</c> if metadata of the specified type was present, <c>false</c> otherwise.
 /// </returns>
 public static bool TryGetMetadata <TMetadata>(this ICompositeMetadata dataSource, out TMetadata data) where TMetadata : IMetadata
 {
     RuntimeAssert.ArgumentNotNull(dataSource, nameof(dataSource));
     if (dataSource.TryGetMetadata(typeof(TMetadata), out var obj))
     {
         data = (TMetadata)obj;
         return(true);
     }
     data = default(TMetadata);
     return(false);
 }
Esempio n. 2
0
 /// <summary>
 /// Determines whether unicode flag has been set on the target composite data.
 /// </summary>
 /// <param name="compositeData">Target composite data.</param>
 /// <returns>
 /// <c>true</c> if unicode flag has been set, <c>false</c> otherwise.
 /// </returns>
 public static bool?Unicode(this ICompositeMetadata compositeData)
 => compositeData.TryGetMetadata <Unicode>(out var u) ? (bool?)u.Value : null;
Esempio n. 3
0
 /// <summary>
 /// Returns either value of single key/value partial data defined by <typeparamref name="T" /> or default
 /// value.
 /// </summary>
 /// <param name="data">Composite data source.</param>
 /// <param name="defaultValue">Optional default value.</param>
 /// <returns>
 /// Either value of single key/value partial data defined by <typeparamref name="T" /> or default value.
 /// </returns>
 public static int GetInt32OrDefault <T>(this ICompositeMetadata data, int defaultValue = default(int))
     where T : MetadataValue <int>
 => data.TryGetMetadata <T>(out var value) ? value.Value : defaultValue;
Esempio n. 4
0
 /// <summary>
 /// Returns either value of single key/value partial data defined by <typeparamref name="T" /> or default
 /// value.
 /// </summary>
 /// <param name="data">Composite data source.</param>
 /// <param name="defaultValue">Optional default value.</param>
 /// <returns>
 /// Either value of single key/value partial data defined by <typeparamref name="T" /> or default value.
 /// </returns>
 public static string GetStringOrDefault <T>(this ICompositeMetadata data, string defaultValue = default(string))
     where T : MetadataValue <string>
 => data.TryGetMetadata <T>(out var value) ? value.Value : defaultValue;
Esempio n. 5
0
 /// <summary>
 /// Returns either value of single key/value partial data defined by <typeparamref name="T" /> or default
 /// value.
 /// </summary>
 /// <param name="data">Composite data source.</param>
 /// <param name="defaultValue">Optional default value.</param>
 /// <returns>
 /// Either value of single key/value partial data defined by <typeparamref name="T" /> or default value.
 /// </returns>
 public static bool GetBooleanOrDefault <T>(this ICompositeMetadata data, bool defaultValue = default(bool))
     where T : MetadataValue <bool>
 => data.TryGetMetadata <T>(out var value) ? value.Value : defaultValue;
Esempio n. 6
0
 public static Maybe <IMetadata> TryInitialize(MetadataDescriptor descriptor, IServiceProvider serviceProvider, ICompositeMetadata target)
 => _cache.GetOrAdd(descriptor.MetadataType, mtype => (BoxedMatcher)Activator.CreateInstance(typeof(Impl <>).MakeGenericType(mtype), true))
 .TryInitializeImpl(descriptor, serviceProvider, target);
Esempio n. 7
0
 public abstract Maybe <IMetadata> TryInitializeImpl(MetadataDescriptor descriptor, IServiceProvider serviceProvider, ICompositeMetadata target);
 /// <summary>
 /// Retrieves precision and scale values if set.
 /// </summary>
 /// <param name="compositeData">Composite metadata source.</param>
 /// <returns>Either precision and scale or <c>null</c></returns>
 public static (byte, byte)? Precision(this ICompositeMetadata compositeData)
 => compositeData.TryGetMetadata <Precision>(out var precision) ? ((byte, byte)?)(precision.PrecisionValue, precision.Scale) : null;
Esempio n. 9
0
            public override Maybe <IMetadata> TryInitializeImpl(MetadataDescriptor descriptor, IServiceProvider serviceProvider, ICompositeMetadata target)
            {
                var desc = (MetadataDescriptor <T>)descriptor;

                return(desc.Match(
                           onFactory: factory => ((IMetadata)factory(serviceProvider, target)).AsMaybe(),
                           onValue: _ => Maybe.Empty
                           ));
            }
 internal override IMetadata Initialize(IServiceProvider serviceProvider, ICompositeMetadata metadata)
 => Factory(serviceProvider, metadata);
 internal override IMetadata Initialize(IServiceProvider serviceProvider, ICompositeMetadata metadata) => Value;
 internal abstract IMetadata Initialize(IServiceProvider serviceProvider, ICompositeMetadata metadata);
Esempio n. 13
0
 /// <summary>
 /// Determines whether read-only flag has been set on the target composite data.
 /// </summary>
 /// <param name="compositeData">Target composite data.</param>
 /// <returns>
 /// <c>true</c> if read-only flag has been set, <c>false</c> otherwise.
 /// </returns>
 public static bool ReadOnly(this ICompositeMetadata compositeData)
 => compositeData.TryGetMetadata(out ReadOnlyFlag flag) && flag.Value;
Esempio n. 14
0
 /// <summary>
 /// Retrieves value of maximum string length constraint if any.
 /// </summary>
 /// <param name="compositeData">Composite metadata source.</param>
 /// <returns>Either maximum string length constraint or <c>null</c></returns>
 public static int?MaxLength(this ICompositeMetadata compositeData)
 => compositeData.TryGetMetadata <StringLength>(out var stringLength) ? (int?)stringLength.MaxLength : null;