示例#1
0
		public static string FriendlyName(Type type)
		{
			using (var provider = new CSharpCodeProvider())
			{
				var typeRef = new CodeTypeReference(type);
				return provider.GetTypeOutput(typeRef);
			}
		}
示例#2
0
 public static string ToReadableString(this Type type)
 {
     using (var provider = new CSharpCodeProvider())
     {
         var typeRef = new CodeTypeReference(type);
         return provider.GetTypeOutput(typeRef);
     }
 }
示例#3
0
 public static string GetSimpleName(this Type type)
 {
     var compiler = new CSharpCodeProvider();
     var result = compiler.GetTypeOutput(new CodeTypeReference(type));
     result = Regex.Replace(result, @"[_A-Za-z0-9]+\.", "");
     result = Regex.Replace(result, @"Nullable<(.+?)>", @"$1?");
     return result;
 }
示例#4
0
        public static string GetFriendlyTypeName(Type type)
        {
            using (var p = new CSharpCodeProvider())
            {

                var r = new CodeTypeReference(type, CodeTypeReferenceOptions.GenericTypeParameter);

                return p.GetTypeOutput(r);
            }
        }
        /// <summary>
        /// Returns C# alias for specified <paramref name="type"/> for build-in types.
        /// </summary>
        public static string GetCSharpTypeName(Type type)
        {
            Contract.Requires(type != null, "type should not be null.");
            Contract.Ensures(Contract.Result<string>() != null);

            using (var provider = new CSharpCodeProvider())
            {
                var typeRef = new CodeTypeReference(type);
                return provider.GetTypeOutput(typeRef);
            }
        }
        public static string GetCsTypeName(this Type type)
        {
            string result;
            using (var provider = new CSharpCodeProvider())
            {
                var typeRef = new CodeTypeReference(type);
                result = provider.GetTypeOutput(typeRef);
            }

            if (result.StartsWith("System.Nullable<") && result.EndsWith(">"))
                result = result.Substring(16, result.Length - 17) + "?";
            var dotIndex = result.IndexOf('.');
            if (dotIndex > 0)
                result = result.Substring(dotIndex + 1);

            return result;
        }
 private string GetTypeName(Type type)
 {
     string typeName;
     using (var provider = new CSharpCodeProvider())
     {
         var typeRef = new CodeTypeReference(type);
         typeName = provider.GetTypeOutput(typeRef);
     }
     return typeName;
 }
 private static CodeTypeReference ModifyCodeTypeReference(CodeTypeReference typeReference, string modifier)
 {
     using (var provider = new CSharpCodeProvider())
         return new CodeTypeReference(modifier + " " + provider.GetTypeOutput(typeReference));
 }
        private string FormatTypeReference(Type type)
        {
            using (var provider = new CSharpCodeProvider())
            {
                var typeRef = new CodeTypeReference(type);
                var typeName = provider.GetTypeOutput(typeRef);

                typeName = typeName.Substring(typeName.LastIndexOf('.') + 1);
                return typeName;
            }
        }
示例#10
0
 private static string GetSpecialName([NotNull] Type type)
 {
     var compiler = new CSharpCodeProvider();
     var typeRef = new CodeTypeReference(type);
     return compiler.GetTypeOutput(typeRef);
 }