Переглянути джерело

2009-04-07 Marek Habersack <[email protected]>

	* TemplateControlCompiler.cs: GenerateExpressionFromString doesn't
	assume that the passed member is a property anymore. Fixes bug
	#492252

svn path=/trunk/mcs/; revision=131210
Marek Habersack 16 роки тому
батько
коміт
53b225fc4b

+ 6 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,9 @@
+2009-04-07  Marek Habersack  <[email protected]>
+
+	* TemplateControlCompiler.cs: GenerateExpressionFromString doesn't
+	assume that the passed member is a property anymore. Fixes bug
+	#492252
+
 2009-04-06  Marek Habersack  <[email protected]>
 
 	* BuildManager.cs: make sure that precompiled is not null before

+ 30 - 3
mcs/class/System.Web/System.Web.Compilation/TemplateControlCompiler.cs

@@ -1809,6 +1809,9 @@ namespace System.Web.Compilation
 			}
 #endif
 
+			if (tca == TypeConverterAttribute.Default)
+				tca = null;
+			
 			if (tca == null)
 				return null;
 
@@ -2012,10 +2015,34 @@ namespace System.Web.Compilation
 				}
 			}
 
-			TypeConverter converter = preConverted ? cvt :
-				wasNullable ? TypeDescriptor.GetConverter (type) :
-				TypeDescriptor.GetProperties (member.DeclaringType) [member.Name].Converter;
+			TypeConverter converter = preConverted ? cvt : wasNullable ? TypeDescriptor.GetConverter (type) : null;
+			if (converter == null) {
+				PropertyDescriptor pdesc = TypeDescriptor.GetProperties (member.DeclaringType) [member.Name];
+				if (pdesc != null)
+					converter = pdesc.Converter;
+				else {
+					Type memberType;
+					switch (member.MemberType) {
+						case MemberTypes.Field:
+							memberType = ((FieldInfo)member).FieldType;
+							break;
+
+						case MemberTypes.Property:
+							memberType = ((PropertyInfo)member).PropertyType;
+							break;
+
+						default:
+							memberType = null;
+							break;
+					}
+
+					if (memberType == null)
+						return null;
 
+					converter = TypeDescriptor.GetConverter (memberType);
+				}
+			}
+			
 			if (preConverted || (converter != null && SafeCanConvertFrom (typeof (string), converter))) {
 				object value = preConverted ? convertedFromAttr : converter.ConvertFromInvariantString (str);