247
248
int i = candidates.IndexOf (idx);
248
249
return new PropertyValueReference (ctx, props[i], target, null, values);
252
bool IsCompilerGeneratedType (SoftEvaluationContext cx, TypeMirror tm)
254
return tm.Name.IndexOf (">c__AnonStorey") != -1 || tm.Name.IndexOf (">c__Iterator") != -1;
257
bool InCompilerGeneratedType (EvaluationContext ctx)
259
SoftEvaluationContext cx = (SoftEvaluationContext) ctx;
260
if (cx.Frame.Method.IsStatic)
262
TypeMirror tm = cx.Frame.Method.DeclaringType;
263
return IsCompilerGeneratedType (cx, tm);
251
public override ValueReference GetLocalVariable (EvaluationContext ctx, string name)
266
IEnumerable<ValueReference> GetCompilerGeneratedLocalVariables (SoftEvaluationContext cx, ValueReference vthis)
254
SoftEvaluationContext cx = (SoftEvaluationContext) ctx;
255
LocalVariable local = cx.Frame.GetVisibleVariableByName (name);
257
return new VariableValueReference (ctx, name, local);
269
return new ValueReference [0];
271
object val = vthis.Value;
272
if (IsNull (cx, val))
273
return new ValueReference [0];
275
TypeMirror tm = (TypeMirror) vthis.Type;
276
bool isIterator = tm.Name.IndexOf (">c__Iterator") != -1;
278
var list = new List<ValueReference> ();
279
TypeMirror type = (TypeMirror) vthis.Type;
280
foreach (FieldInfoMirror field in type.GetFields ()) {
281
if (field.Name == "<>f__this")
283
if (field.Name.StartsWith ("<>f__ref")) {
284
list.AddRange (GetCompilerGeneratedLocalVariables (cx, new FieldValueReference (cx, field, val, type)));
287
if (field.Name.StartsWith ("<")) {
289
int i = field.Name.IndexOf ('>');
291
string vname = field.Name.Substring (1, i - 1);
292
list.Add (new FieldValueReference (cx, field, val, type, vname, ObjectValueFlags.Variable));
297
list.Add (new FieldValueReference (cx, field, val, type, field.Name, ObjectValueFlags.Variable));
302
ValueReference GetCompilerGeneratedThisReference (SoftEvaluationContext cx)
305
Value val = cx.Frame.GetThis ();
306
TypeMirror type = (TypeMirror) GetValueType (cx, val);
307
FieldInfoMirror field = type.GetField ("<>f__this");
309
return new FieldValueReference (cx, field, val, type, "this", ObjectValueFlags.Literal);
310
} catch (AbsentInformationException) {
315
protected override ValueReference OnGetLocalVariable (EvaluationContext ctx, string name)
317
SoftEvaluationContext cx = (SoftEvaluationContext) ctx;
318
if (InCompilerGeneratedType (cx))
319
return FindByName (OnGetLocalVariables (cx), v => v.Name, name, ctx.CaseSensitive);
322
LocalVariable local = null;
323
if (!cx.SourceCodeAvailable) {
324
if (name.StartsWith ("loc")) {
326
if (int.TryParse (name.Substring (3), out idx))
327
local = cx.Frame.Method.GetLocals ().FirstOrDefault (loc => loc.Index == idx);
330
local = ctx.CaseSensitive ? cx.Frame.GetVisibleVariableByName (name) : FindByName (cx.Frame.GetVisibleVariables(), v => v.Name, name, false);
333
string vname = !string.IsNullOrEmpty (local.Name) || cx.SourceCodeAvailable ? local.Name : "loc" + local.Index;
334
return new VariableValueReference (ctx, vname, local);
336
return FindByName (OnGetLocalVariables (ctx), v => v.Name, name, ctx.CaseSensitive);;
260
337
} catch (AbsentInformationException) {
265
public override IEnumerable<ValueReference> GetLocalVariables (EvaluationContext ctx)
342
protected override IEnumerable<ValueReference> OnGetLocalVariables (EvaluationContext ctx)
267
344
SoftEvaluationContext cx = (SoftEvaluationContext) ctx;
345
if (InCompilerGeneratedType (cx)) {
346
ValueReference vthis = GetThisReference (cx);
347
return GetCompilerGeneratedLocalVariables (cx, vthis).Union (GetLocalVariables (cx));
350
return GetLocalVariables (cx);
353
IEnumerable<ValueReference> GetLocalVariables (SoftEvaluationContext cx)
268
355
IList<LocalVariable> locals;
270
357
locals = cx.Frame.GetVisibleVariables ();
282
378
TypeMirror type = (TypeMirror) t;
283
379
while (type != null) {
284
FieldInfoMirror field = type.GetField (name);
380
FieldInfoMirror field = FindByName (type.GetFields(), f => f.Name, name, ctx.CaseSensitive);
381
if (field != null && (field.IsStatic || co != null))
286
382
return new FieldValueReference (ctx, field, co, type);
287
PropertyInfoMirror prop = type.GetProperty (name);
383
PropertyInfoMirror prop = FindByName (type.GetProperties(), p => p.Name, name, ctx.CaseSensitive);
384
if (prop != null && (IsStatic (prop) || co != null))
289
385
return new PropertyValueReference (ctx, prop, co, type, null);
290
386
type = type.BaseType;
391
bool IsStatic (PropertyInfoMirror prop)
393
MethodMirror met = prop.GetGetMethod (true) ?? prop.GetSetMethod (true);
397
static T FindByName<T> (IEnumerable<T> elems, Func<T,string> getName, string name, bool caseSensitive)
400
foreach (T t in elems) {
401
string n = getName (t);
404
else if (!caseSensitive && n.Equals (name, StringComparison.CurrentCultureIgnoreCase))
295
410
protected override IEnumerable<ValueReference> GetMembers (EvaluationContext ctx, object t, object co, BindingFlags bindingFlags)
297
412
Dictionary<string, PropertyInfoMirror> subProps = new Dictionary<string, PropertyInfoMirror> ();
385
500
foreach (LocalVariable var in locals) {
387
yield return new VariableValueReference (ctx, var.Name, var);
502
string name = !string.IsNullOrEmpty (var.Name) || cx.SourceCodeAvailable ? var.Name : "arg" + var.Index;
503
yield return new VariableValueReference (ctx, name, var);
391
public override ValueReference GetThisReference (EvaluationContext ctx)
508
protected override ValueReference OnGetThisReference (EvaluationContext ctx)
510
SoftEvaluationContext cx = (SoftEvaluationContext) ctx;
511
if (InCompilerGeneratedType (cx))
512
return GetCompilerGeneratedThisReference (cx);
514
return GetThisReference (cx);
517
ValueReference GetThisReference (SoftEvaluationContext cx)
394
SoftEvaluationContext cx = (SoftEvaluationContext) ctx;
395
520
if (cx.Frame.Method.IsStatic)
397
522
Value val = cx.Frame.GetThis ();
398
return LiteralValueReference.CreateTargetObjectLiteral (ctx, "this", val);
523
return LiteralValueReference.CreateTargetObjectLiteral (cx, "this", val);
399
524
} catch (AbsentInformationException) {
608
733
protected override TypeDisplayData OnGetTypeDisplayData (EvaluationContext gctx, object type)
610
735
SoftEvaluationContext ctx = (SoftEvaluationContext) gctx;
611
TypeDisplayData td = new TypeDisplayData ();
737
bool isCompilerGenerated = false;
738
string nameString = null;
739
string typeString = null;
740
string valueString = null;
741
string proxyType = null;
742
Dictionary<string, DebuggerBrowsableState> memberData = null;
613
745
TypeMirror t = (TypeMirror) type;
614
746
foreach (CustomAttributeDataMirror attr in t.GetCustomAttributes (true)) {
615
747
string attName = attr.Constructor.DeclaringType.FullName;
616
748
if (attName == "System.Diagnostics.DebuggerDisplayAttribute") {
617
749
DebuggerDisplayAttribute at = BuildAttribute<DebuggerDisplayAttribute> (attr);
618
td.NameDisplayString = at.Name;
619
td.TypeDisplayString = at.Type;
620
td.ValueDisplayString = at.Value;
750
nameString = at.Name;
751
typeString = at.Type;
752
valueString = at.Value;
622
754
else if (attName == "System.Diagnostics.DebuggerTypeProxyAttribute") {
623
755
DebuggerTypeProxyAttribute at = BuildAttribute<DebuggerTypeProxyAttribute> (attr);
624
td.ProxyType = at.ProxyTypeName;
625
if (!string.IsNullOrEmpty (td.ProxyType))
626
ForceLoadType (ctx, td.ProxyType);
756
proxyType = at.ProxyTypeName;
757
if (!string.IsNullOrEmpty (proxyType))
758
ForceLoadType (ctx, proxyType);
760
else if (attName == "System.Runtime.CompilerServices.CompilerGeneratedAttribute")
761
isCompilerGenerated = true;
629
763
foreach (FieldInfoMirror fi in t.GetFields ()) {
630
764
CustomAttributeDataMirror[] attrs = fi.GetCustomAttributes (true);
635
769
att = new DebuggerBrowsableAttribute (DebuggerBrowsableState.Never);
637
771
if (att != null) {
638
if (td.MemberData == null)
639
td.MemberData = new Dictionary<string, DebuggerBrowsableState> ();
640
td.MemberData [fi.Name] = att.State;
772
if (memberData == null)
773
memberData = new Dictionary<string, DebuggerBrowsableState> ();
774
memberData [fi.Name] = att.State;
643
777
foreach (PropertyInfoMirror pi in t.GetProperties ()) {
644
778
DebuggerBrowsableAttribute att = GetAttribute <DebuggerBrowsableAttribute> (pi.GetCustomAttributes (true));
645
779
if (att != null) {
646
if (td.MemberData == null)
647
td.MemberData = new Dictionary<string, DebuggerBrowsableState> ();
648
td.MemberData [pi.Name] = att.State;
780
if (memberData == null)
781
memberData = new Dictionary<string, DebuggerBrowsableState> ();
782
memberData [pi.Name] = att.State;
651
785
} catch (Exception ex) {
652
786
ctx.Session.WriteDebuggerOutput (true, ex.ToString ());
788
return new TypeDisplayData (proxyType, valueString, typeString, nameString, isCompilerGenerated, memberData);
657
791
T GetAttribute<T> (CustomAttributeDataMirror[] attrs)
659
793
foreach (CustomAttributeDataMirror attr in attrs) {