[sdb] Fix a deadlock in the assembly cache invalidation code.
[mono.git] / mcs / class / Mono.Debugger.Soft / Mono.Debugger.Soft / CustomAttributeTypedArgumentMirror.cs
1 using System;
2 using System.Runtime.InteropServices;
3 using System.Collections.ObjectModel;
4 using System.Reflection;
5
6 namespace Mono.Debugger.Soft {
7
8         public struct CustomAttributeTypedArgumentMirror {
9                 Type type;
10                 object value;
11
12                 internal CustomAttributeTypedArgumentMirror (Type type, object value)
13                 {
14                         this.type = type;
15                         this.value = value;
16
17                         if (value != null)
18                                 this.type = value.GetType ();
19                         else
20                                 this.type = typeof (void);
21
22                         // MS seems to convert arrays into a ReadOnlyCollection
23                         if (value is Array) {
24                                 Array a = (Array)value;
25
26                                 Type etype = a.GetType ().GetElementType ();
27                                 CustomAttributeTypedArgumentMirror[] new_value = new CustomAttributeTypedArgumentMirror [a.GetLength (0)];
28                                 for (int i = 0; i < new_value.Length; ++i)
29                                         new_value [i] = new CustomAttributeTypedArgumentMirror (etype, a.GetValue (i));
30                                 this.value = new ReadOnlyCollection <CustomAttributeTypedArgumentMirror> (new_value);
31                         }
32                 }
33
34                 public Type ArgumentType {
35                         get {
36                                 return type;
37                         }
38                 }
39
40                 public object Value {
41                         get {
42                                 return value;
43                         }
44                 }
45
46                 public override string ToString ()
47                 {
48                         string val = value != null ? value.ToString () : String.Empty;
49                         if (ArgumentType == typeof (string))
50                                 return "\"" + val + "\"";
51                         if (ArgumentType == typeof (Type)) 
52                                 return "typeof (" + val + ")";
53                         if (ArgumentType.IsEnum)
54                                 return "(" + ArgumentType.Name + ")" + val;
55
56                         return val;
57                 }
58         }
59 }