예제 #1
0
        /// <summary>
        /// Tests if the provided type is nullable
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public static bool IsNullableType(this Type arg)
        {
            if (NullableTypes.TryGetValue(arg, out var cachedResult))
            {
                return(cachedResult);
            }

            var method = GenericGetDefaultValueMethod.MakeGenericMethod(arg);
            var defaultValueForType = method.Invoke(null, new object[] { });
            var result = defaultValueForType == null;

            return(NullableTypes[arg] = result);
        }
예제 #2
0
        private static object DefaultValueForType(Type t)
        {
            var method = GenericGetDefaultValueMethod.MakeGenericMethod(t);

            return(method.Invoke(null, new object[] { }));
        }