/// <summary>
        /// Gets the name of the friendly type. Example, Int32 => 'int'
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        protected string GetFriendlyTypeName(Type type)
        {
            var    compiler = new Microsoft.CSharp.CSharpCodeProvider();
            string name;

            if (Nullable.GetUnderlyingType(type) != null)
            {
                name = compiler.GetTypeOutput(new System.CodeDom.CodeTypeReference(Nullable.GetUnderlyingType(type))) + "?";
            }
            else
            {
                name = compiler.GetTypeOutput(new System.CodeDom.CodeTypeReference(type));
            }

            return(name.Split('.').Last());
        }
Esempio n. 2
0
		public static string Friendly(Type type)
		{
			using (var provider = new Microsoft.CSharp.CSharpCodeProvider())
			{
				var @ref = new CodeTypeReference(type);
				return provider.GetTypeOutput(@ref);
			}
		}
Esempio n. 3
0
        private string GetTypeOutput( )
        {
            var type = Type.GetType(FieldTypeName);

            if (type != null)
            {
                using (var code = new Microsoft.CSharp.CSharpCodeProvider( ))
                {
                    return(code.GetTypeOutput(new System.CodeDom.CodeTypeReference(type.FullName)));
                }
            }
            else
            {
                return(FieldTypeName);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the correct type name for the Generic property
        /// </summary>
        /// <returns></returns>
        private string GetReadableTypeName()
        {
            //If it isn't a generic just pass return the class name
            if (!fieldInfo.FieldType.IsGenericType)
            {
                return(fieldInfo.FieldType.Name);
            }

            //Gets primitive names (e.g. Float instead of single)
            var    compiler     = new Microsoft.CSharp.CSharpCodeProvider();
            string readableName = compiler.GetTypeOutput(new System.CodeDom.CodeTypeReference(fieldInfo.FieldType.GetGenericArguments()[0]));

            //Remove Namespace by finding last '.'
            int lastIndex = readableName.LastIndexOf('.');

            if (lastIndex >= 0 && lastIndex != readableName.Length - 1)
            {
                readableName = readableName.Substring(lastIndex + 1);
            }

            //Add variable to make clear it's a generic
            return($"Variable<{readableName}>");
        }