2
// NRefactoryExtensions.cs
4
// Author: Jeffrey Stedfast <jeff@xamarin.com>
6
// Copyright (c) 2013 Xamarin Inc.
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to deal
10
// in the Software without restriction, including without limitation the rights
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
// copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
using System.Collections.Generic;
29
using ICSharpCode.NRefactory.CSharp;
31
namespace Mono.Debugging.Evaluation
33
public static class NRefactoryExtensions
37
public static object Resolve (this AstType type, EvaluationContext ctx)
39
var args = new List<object> ();
40
var name = type.Resolve (ctx, args);
42
//if (name.StartsWith ("global::", StringComparison.Ordinal))
43
// name = name.Substring ("global::".Length);
46
return ctx.Adapter.GetType (ctx, name, args.ToArray ());
48
return ctx.Adapter.GetType (ctx, name);
51
static string Resolve (this AstType type, EvaluationContext ctx, List<object> args)
53
if (type is PrimitiveType)
54
return Resolve ((PrimitiveType) type, ctx, args);
55
else if (type is ComposedType)
56
return Resolve ((ComposedType) type, ctx, args);
57
else if (type is MemberType)
58
return Resolve ((MemberType) type, ctx, args);
59
else if (type is SimpleType)
60
return Resolve ((SimpleType) type, ctx, args);
69
static string Resolve (this ComposedType type, EvaluationContext ctx, List<object> args)
73
if (type.HasNullableSpecifier) {
74
args.Insert (0, type.BaseType.Resolve (ctx));
75
name = "System.Nullable`1";
77
name = type.BaseType.Resolve (ctx, args);
80
if (type.PointerRank > 0)
81
name += new string ('*', type.PointerRank);
83
if (type.ArraySpecifiers.Count > 0) {
84
foreach (var spec in type.ArraySpecifiers) {
85
if (spec.Dimensions > 1)
86
name += "[" + new string (',', spec.Dimensions - 1) + "]";
95
#endregion ComposedType
99
static string Resolve (this MemberType type, EvaluationContext ctx, List<object> args)
103
if (!type.IsDoubleColon) {
104
var parent = type.Target.Resolve (ctx, args);
105
name = parent + "." + type.MemberName;
107
name = type.MemberName;
110
if (type.TypeArguments.Count > 0) {
111
name += "`" + type.TypeArguments.Count;
112
foreach (var arg in type.TypeArguments) {
115
if ((resolved = arg.Resolve (ctx)) == null)
125
#endregion MemberType
127
#region PrimitiveType
129
public static string Resolve (this PrimitiveType type)
131
switch (type.Keyword) {
132
case "bool": return "System.Boolean";
133
case "sbyte": return "System.SByte";
134
case "byte": return "System.Byte";
135
case "char": return "System.Char";
136
case "short": return "System.Int16";
137
case "ushort": return "System.UInt16";
138
case "int": return "System.Int32";
139
case "uint": return "System.UInt32";
140
case "long": return "System.Int64";
141
case "ulong": return "System.UInt64";
142
case "float": return "System.Single";
143
case "double": return "System.Double";
144
case "decimal": return "System.Decimal";
145
case "string": return "System.String";
146
case "object": return "System.Object";
147
case "void": return "System.Void";
148
default: return null;
152
static string Resolve (this PrimitiveType type, EvaluationContext ctx, List<object> args)
154
return Resolve (type);
157
#endregion PrimitiveType
161
static string Resolve (this SimpleType type, EvaluationContext ctx, List<object> args)
163
string name = type.Identifier;
165
if (type.TypeArguments.Count > 0) {
166
name += "`" + type.TypeArguments.Count;
167
foreach (var arg in type.TypeArguments) {
170
if ((resolved = arg.Resolve (ctx)) == null)
180
#endregion SimpleType