Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / Mono.Debugger.Soft / Mono.Debugger.Soft / StructMirror.cs
1 using System;
2 using System.Collections.Generic;
3
4 namespace Mono.Debugger.Soft
5 {
6         /*
7          * Represents a valuetype value in the debuggee
8          */
9         public class StructMirror : Value {
10         
11                 TypeMirror type;
12                 Value[] fields;
13
14                 internal StructMirror (VirtualMachine vm, TypeMirror type, Value[] fields) : base (vm, 0) {
15                         this.type = type;
16                         this.fields = fields;
17                 }
18
19                 public TypeMirror Type {
20                         get {
21                                 return type;
22                         }
23                 }
24
25                 public Value[] Fields {
26                         get {
27                                 return fields;
28                         }
29                 }
30
31                 public Value this [String field] {
32                         get {
33                                 FieldInfoMirror[] field_info = Type.GetFields ();
34                                 int nf = 0;
35                                 for (int i = 0; i < field_info.Length; ++i) {
36                                         if (!field_info [i].IsStatic) {
37                                                 if (field_info [i].Name == field)
38                                                         return Fields [nf];
39                                                 nf++;
40                                         }
41                                 }
42                                 throw new ArgumentException ("Unknown struct field '" + field + "'.", "field");
43                         }
44                         set {
45                                 FieldInfoMirror[] field_info = Type.GetFields ();
46                                 int nf = 0;
47                                 for (int i = 0; i < field_info.Length; ++i) {
48                                         if (!field_info [i].IsStatic) {
49                                                 if (field_info [i].Name == field) {
50                                                         fields [nf] = value;
51                                                         return;
52                                                 }
53                                                 nf++;
54                                         }
55                                 }
56                                 throw new ArgumentException ("Unknown struct field '" + field + "'.", "field");
57                         }
58                 }
59
60                 internal void SetField (int index, Value value) {
61                         fields [index] = value;
62                 }
63
64                 public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {
65                         return ObjectMirror.InvokeMethod (vm, thread, method, this, arguments, InvokeOptions.None);
66                 }
67
68                 public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
69                         return ObjectMirror.InvokeMethod (vm, thread, method, this, arguments, options);
70                 }
71
72                 [Obsolete ("Use the overload without the 'vm' argument")]
73                 public IAsyncResult BeginInvokeMethod (VirtualMachine vm, ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
74                         return ObjectMirror.BeginInvokeMethod (vm, thread, method, this, arguments, options, callback, state);
75                 }
76
77                 public IAsyncResult BeginInvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
78                         return ObjectMirror.BeginInvokeMethod (vm, thread, method, this, arguments, options, callback, state);
79                 }
80
81                 public Value EndInvokeMethod (IAsyncResult asyncResult) {
82                         return ObjectMirror.EndInvokeMethodInternal (asyncResult);
83                 }
84         }
85 }