annotate Implab.ServiceHost/Unity/TypeReference.cs @ 274:22629bf26121 v3

Unity xml configuration, alpha2
author cin
date Fri, 27 Apr 2018 04:47:52 +0300
parents 0be8a6ae8307
children 6691aff01de1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
1 using System;
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
2 using System.Linq;
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
3 using System.Text;
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
4
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
5 namespace Implab.ServiceHost.Unity {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
6 public class TypeReference {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
7 public string TypeName { get; set; }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
8
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
9 public string Namespace { get; set; }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
10
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
11 public TypeReference[] GenericParameters { get; set; }
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
12
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
13 public bool IsArray { get; set; }
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
14
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
15 public bool IsOpenGeneric {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
16 get {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
17 return GenericParameters!=null && GenericParameters.Contains(null);
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
18 }
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
19 }
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
20
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
21 public bool IsGeneric {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
22 get {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
23 return GenericParameters != null && GenericParameters.Length > 0;
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
24 }
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
25 }
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
26
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
27 public override string ToString() {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
28 var builder = new StringBuilder();
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
29
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
30 if (!string.IsNullOrEmpty(Namespace)) {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
31 builder.Append(Namespace);
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
32 builder.Append('.');
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
33 }
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
34
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
35 if (!string.IsNullOrEmpty(TypeName)) {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
36 builder.Append(TypeName);
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
37 } else {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
38 builder.Append("__unnamed__");
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
39 }
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
40
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
41 if (GenericParameters != null && GenericParameters.Length > 0) {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
42 builder.Append('{');
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
43 for(var i = 0; i < GenericParameters.Length; i++) {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
44 if (i > 0)
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
45 builder.Append(',');
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
46 builder.Append(GenericParameters[i]);
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
47 }
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
48 builder.Append('}');
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
49 }
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
50
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
51 return builder.ToString();
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
52 }
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
53 public static TypeReference Parse(string text) {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
54 var parser = new TypeReferenceParser(text);
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
55 return parser.Parse();
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
56 }
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
57 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
58 }