Author: mkestner
Date: 2007-10-11 16:47:09 -0400 (Thu, 11 Oct 2007)
New Revision: 87358
Modified:
trunk/gnome-sharp/ChangeLog
trunk/gnome-sharp/gconf/GConf/Value.cs
Log:
2007-10-11 Mike Kestner <[EMAIL PROTECTED]>
* gconf/GConf/Value.cs: Deal with zero length arrays gracefully.
Thanks to Sebastian Dr?\195?\182ge <[EMAIL PROTECTED]> for a
patch this one was derived from. [Fixes #325516]
Modified: trunk/gnome-sharp/ChangeLog
===================================================================
--- trunk/gnome-sharp/ChangeLog 2007-10-11 20:45:31 UTC (rev 87357)
+++ trunk/gnome-sharp/ChangeLog 2007-10-11 20:47:09 UTC (rev 87358)
@@ -1,3 +1,9 @@
+2007-10-11 Mike Kestner <[EMAIL PROTECTED]>
+
+ * gconf/GConf/Value.cs: Deal with zero length arrays gracefully.
+ Thanks to Sebastian Dröge <[EMAIL PROTECTED]> for a
+ patch this one was derived from. [Fixes #325516]
+
2007-09-07 Mike Kestner <[EMAIL PROTECTED]>
* AssembyInfo.cs.in : add [IgnoreClassInitializers]
Modified: trunk/gnome-sharp/gconf/GConf/Value.cs
===================================================================
--- trunk/gnome-sharp/gconf/GConf/Value.cs 2007-10-11 20:45:31 UTC (rev
87357)
+++ trunk/gnome-sharp/gconf/GConf/Value.cs 2007-10-11 20:47:09 UTC (rev
87358)
@@ -58,17 +58,19 @@
[DllImport("gconf-2")]
static extern void gconf_value_set_bool (IntPtr value, bool
data);
- ValueType LookupType (object data)
+ ValueType LookupType (System.Type t)
{
- if (data is string) {
+ if (t.IsArray) {
+ return ValueType.List;
+ } else if (t == typeof (string)) {
return ValueType.String;
- } else if (data is int) {
+ } else if (t == typeof (int)) {
return ValueType.Int;
- } else if (data is double) {
+ } else if (t == typeof (double)) {
return ValueType.Float;
- } else if (data is bool) {
+ } else if (t == typeof (bool)) {
return ValueType.Bool;
- } else if (data is ICollection) {
+ } else if (t == typeof (ICollection)) {
return ValueType.List;
} else {
return ValueType.Invalid;
@@ -80,7 +82,7 @@
if (data == null)
throw new NullReferenceException ();
- ValueType type = LookupType (data);
+ ValueType type = LookupType (data.GetType ());
Set (data, type);
}
@@ -140,8 +142,16 @@
listType = ValueType.Bool;
}
+ if (arr.Length == 0) {
+ if (data is Array)
+ listType = LookupType (data.GetType
().GetElementType ());
+ else
+ throw new InvalidValueTypeException ();
+ return list;
+ }
+
foreach (object o in arr) {
- ValueType type = LookupType (o);
+ ValueType type = LookupType (o.GetType ());
if (listType == ValueType.Invalid)
listType = type;
@@ -265,7 +275,7 @@
*/
public Value (object val)
{
- Initialize (val, LookupType (val));
+ Initialize (val, LookupType (val.GetType ()));
}
public bool Managed
{
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches