Mercurial > pub > ImplabNet
diff Implab.ServiceHost/Unity/TypeReference.cs @ 268:0be8a6ae8307 v3
Implemented typereference parser
author | cin |
---|---|
date | Sun, 22 Apr 2018 15:29:10 +0300 |
parents | 6b3e5c48131b |
children | 6691aff01de1 |
line wrap: on
line diff
--- a/Implab.ServiceHost/Unity/TypeReference.cs Fri Apr 20 19:05:12 2018 +0300 +++ b/Implab.ServiceHost/Unity/TypeReference.cs Sun Apr 22 15:29:10 2018 +0300 @@ -1,3 +1,7 @@ +using System; +using System.Linq; +using System.Text; + namespace Implab.ServiceHost.Unity { public class TypeReference { public string TypeName { get; set; } @@ -5,5 +9,50 @@ public string Namespace { get; set; } public TypeReference[] GenericParameters { get; set; } + + public bool IsArray { get; set; } + + public bool IsOpenGeneric { + get { + return GenericParameters!=null && GenericParameters.Contains(null); + } + } + + public bool IsGeneric { + get { + return GenericParameters != null && GenericParameters.Length > 0; + } + } + + public override string ToString() { + var builder = new StringBuilder(); + + if (!string.IsNullOrEmpty(Namespace)) { + builder.Append(Namespace); + builder.Append('.'); + } + + if (!string.IsNullOrEmpty(TypeName)) { + builder.Append(TypeName); + } else { + builder.Append("__unnamed__"); + } + + if (GenericParameters != null && GenericParameters.Length > 0) { + builder.Append('{'); + for(var i = 0; i < GenericParameters.Length; i++) { + if (i > 0) + builder.Append(','); + builder.Append(GenericParameters[i]); + } + builder.Append('}'); + } + + return builder.ToString(); + } + public static TypeReference Parse(string text) { + var parser = new TypeReferenceParser(text); + return parser.Parse(); + } } } \ No newline at end of file