コード例 #1
0
        public static T GetSettingValue <T>(this IConfigurationRoot root, AppSettingsSectionEnum appSettingsSection, string key)
        {
            var section    = appSettingsSection.ToJsonString().ToUpperInvariant();
            var keyPattern = $"{StringConstants.CUSTOM_SETTINGS}:{section}:{key?.ToUpperInvariant()}:VALUE";
            var value      = root.GetSection(keyPattern)?.Value;
            var typedValue = ConvertAny.Convert <T>(value);

            return(typedValue);
        }
コード例 #2
0
 /// <summary>
 /// Determines whether this type can convert to the specified type.
 /// </summary>
 /// <param name="t">Type extension reference.</param>
 /// <param name="convertTo">The type to convert to.</param>
 /// <returns><c>true</c> if this instance can convert to the specified type; otherwise, <c>false</c>.</returns>
 public static bool CanConvertTo(this Type t, Type convertTo)
 {
     return(ConvertAny.CanConvert(t, convertTo));
 }
コード例 #3
0
 /// <summary>
 /// Creates a default instance of the type.
 /// </summary>
 /// <param name="t">Type extension reference.</param>
 /// <returns>System.Object.</returns>
 /// <remarks>
 /// If the type is a value type or primitive, it will return a type that is
 /// that primitive or value type initialized to zero.
 ///
 /// If the type is a complex type, and the type contains a default constructor
 /// it will return a default instance of that type. If the type does not have
 /// a default constructor, it will return null.
 /// </remarks>
 public static object CreateDefault(this Type t)
 {
     return(ConvertAny.DefaultByType(t));
 }