Author: joncham
Date: 2006-10-20 13:32:51 -0400 (Fri, 20 Oct 2006)
New Revision: 66839
Modified:
trunk/mcs/class/corlib/System/ChangeLog
trunk/mcs/class/corlib/System/Variant.cs
Log:
2006-10-20 Jonathan Chambers <[EMAIL PROTECTED]>
* Variant.cs: Add support for bool and interfaces.
Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog 2006-10-20 17:26:24 UTC (rev
66838)
+++ trunk/mcs/class/corlib/System/ChangeLog 2006-10-20 17:32:51 UTC (rev
66839)
@@ -1,3 +1,7 @@
+2006-10-20 Jonathan Chambers <[EMAIL PROTECTED]>
+
+ * Variant.cs: Add support for bool and interfaces.
+
2006-10-18 Kornél Pál <[EMAIL PROTECTED]>
* Type.cs: Removed is_subtype_of because IsSubclassOf should be used
Modified: trunk/mcs/class/corlib/System/Variant.cs
===================================================================
--- trunk/mcs/class/corlib/System/Variant.cs 2006-10-20 17:26:24 UTC (rev
66838)
+++ trunk/mcs/class/corlib/System/Variant.cs 2006-10-20 17:32:51 UTC (rev
66839)
@@ -88,6 +88,9 @@
[FieldOffset(8)]
public uint uintVal;
+ [FieldOffset(8)]
+ public IntPtr pdispVal;
+
public void SetValue(object obj) {
vt = (short)VarEnum.VT_EMPTY;
if (obj == null)
@@ -148,11 +151,24 @@
{
vt = (short)VarEnum.VT_BSTR;
bstrVal = Marshal.StringToBSTR((string)obj);
+ }
+ else if (t == typeof(bool))
+ {
+ vt = (short)VarEnum.VT_BOOL;
+ lVal = ((bool)obj) ? -1 : 0;
+ }
+ else
+ {
+ try
+ {
+ vt = (short)VarEnum.VT_DISPATCH;
+ pdispVal = Marshal.GetIUnknownForObject(obj);
+ }
+ catch (Exception ex)
+ {
+ throw new NotImplementedException(string.Format("Variant
couldn't handle object of type {0}", obj.GetType()), ex);
+ }
}
- else
- {
- throw new
NotImplementedException(string.Format("Variant couldn't handle object of type
{0}", obj.GetType()));
- }
}
public object GetValue() {
@@ -189,18 +205,29 @@
case VarEnum.VT_R8:
obj = dblVal;
break;
+ case VarEnum.VT_BOOL:
+ obj = !(lVal == 0);
+ break;
case VarEnum.VT_BSTR:
obj = Marshal.PtrToStringBSTR(bstrVal);
break;
+ case VarEnum.VT_UNKNOWN:
+ case VarEnum.VT_DISPATCH:
+ obj = Marshal.GetObjectForIUnknown(pdispVal);
+ break;
}
return obj;
+ }
+
+ public void Clear ()
+ {
+ if ((VarEnum)vt == VarEnum.VT_BSTR) {
+ Marshal.FreeBSTR (bstrVal);
+ }
+ else if ((VarEnum)vt == VarEnum.VT_DISPATCH ||
(VarEnum)vt == VarEnum.VT_UNKNOWN) {
+ if (pdispVal != IntPtr.Zero)
+ Marshal.Release (pdispVal);
+ }
}
-
- public void Clear() {
- if ((VarEnum)vt == VarEnum.VT_BSTR)
- {
- Marshal.FreeBSTR(bstrVal);
- }
- }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches