Merge branch 'master' of github.com:mono/mono
[mono.git] / mcs / class / Mono.Debugger.Soft / Mono.Debugger.Soft / EnumMirror.cs
index 973eb72e6af749c2c263e17e1c486a62b2d7ea05..5131b2a43494554efb4421c52ad9822178c815ec 100644 (file)
@@ -11,6 +11,18 @@ namespace Mono.Debugger.Soft
                internal EnumMirror (VirtualMachine vm, TypeMirror type, Value[] fields) : base (vm, type, fields) {
                }
 
+               internal EnumMirror (VirtualMachine vm, TypeMirror type, PrimitiveValue value) : base (vm, type, new Value[] { value }) {
+                       if (type == null)
+                               throw new ArgumentNullException ("type");
+                       if (value == null)
+                               throw new ArgumentNullException ("value");
+                       if (!type.IsEnum)
+                               throw new ArgumentException ("type must be an enum type", "type");
+                       TypeMirror t = type.EnumUnderlyingType;
+                       if (value.Value == null || !value.Value.GetType ().IsPrimitive || t != vm.RootDomain.GetCorrespondingType (value.Value.GetType ()))
+                               throw new ArgumentException ("Value '" + value.Value + "' does not match the type of the enum.");
+               }
+
                public object Value {
                        get {
                                return ((PrimitiveValue)Fields [0]).Value;