Exemplo n.º 1
0
        /// <summary>
        /// Unregisters an argument converter for specified type.
        /// </summary>
        /// <typeparam name="T">Type for which to unregister the converter.</typeparam>
        public void UnregisterConverter <T>()
        {
            var t  = typeof(T);
            var ti = t.GetTypeInfo();

            if (ArgumentConverters.ContainsKey(t))
            {
                ArgumentConverters.Remove(t);
            }

            if (UserFriendlyTypeNames.ContainsKey(t))
            {
                UserFriendlyTypeNames.Remove(t);
            }

            if (!ti.IsValueType)
            {
                return;
            }

            var nullableType = typeof(Nullable <>).MakeGenericType(t);

            if (!ArgumentConverters.ContainsKey(nullableType))
            {
                return;
            }

            ArgumentConverters.Remove(nullableType);
            UserFriendlyTypeNames.Remove(nullableType);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts a type into user-friendly type name.
        /// </summary>
        /// <param name="t">Type to convert.</param>
        /// <returns>User-friendly type name.</returns>
        public string GetUserFriendlyTypeName(Type t)
        {
            if (UserFriendlyTypeNames.ContainsKey(t))
            {
                return(UserFriendlyTypeNames[t]);
            }

            var ti = t.GetTypeInfo();

            if (ti.IsGenericTypeDefinition && t.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                var tn = ti.GenericTypeArguments[0];
                if (UserFriendlyTypeNames.ContainsKey(tn))
                {
                    return(UserFriendlyTypeNames[tn]);
                }

                return(tn.Name);
            }

            return(t.Name);
        }