示例#1
0
 /// <summary>
 /// Gets the nullable type that corresponds to the given type.
 /// </summary>
 public static Type GetNullableType(Type type)
 {
     if (!type.GetTypeInfo().IsValueType)
     {
         return(type);
     }
     if (NullableInfoMap.TryGetValue(type, out var result))
     {
         return(result.NullableType);
     }
     else
     {
         return(null);
     }
 }
示例#2
0
        /// <summary>
        /// Gets the default value for a specified type.
        /// </summary>
        public static object GetDefaultValue(Type type)
        {
            if (type == null)
            {
                return(null);
            }

            if (!type.GetTypeInfo().IsValueType)
            {
                return(null);
            }

            if (NullableInfoMap.TryGetValue(type, out var result))
            {
                return(result.DefaultValue);
            }
            else
            {
                return(Activator.CreateInstance(type));
            }
        }