Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoltan Varga <vargaz@gmail.com>2004-03-22 20:45:35 +0300
committerZoltan Varga <vargaz@gmail.com>2004-03-22 20:45:35 +0300
commit4e7119ec6ecbafae4f1ddcf1f0928ed05a2ffc97 (patch)
tree7c7f00a1e4df3737cb2b8bf9c5875897a284227f /mcs/class/corlib/System.Reflection.Emit
parent12bbb8974925d6d2dbbdccc9e0681350cb433acc (diff)
2004-03-22 Zoltan Varga <vargaz@freemail.hu>
* CustomAttributeBuilder.cs (Initialize): Add more argument checking. Fixes #55793. svn path=/trunk/mcs/; revision=24425
Diffstat (limited to 'mcs/class/corlib/System.Reflection.Emit')
-rw-r--r--mcs/class/corlib/System.Reflection.Emit/ChangeLog5
-rwxr-xr-xmcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs43
2 files changed, 48 insertions, 0 deletions
diff --git a/mcs/class/corlib/System.Reflection.Emit/ChangeLog b/mcs/class/corlib/System.Reflection.Emit/ChangeLog
index d18177ecb4b..d6dfd16ec1d 100644
--- a/mcs/class/corlib/System.Reflection.Emit/ChangeLog
+++ b/mcs/class/corlib/System.Reflection.Emit/ChangeLog
@@ -1,3 +1,8 @@
+2004-03-22 Zoltan Varga <vargaz@freemail.hu>
+
+ * CustomAttributeBuilder.cs (Initialize): Add more argument checking.
+ Fixes #55793.
+
2004-03-09 Jackson Harper <jackson@ximian.com>
* CustomAttributeBuilder.cs: Add some argument checking. Handle
diff --git a/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs
index b5d3903ff4c..96bb16e2196 100755
--- a/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs
+++ b/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs
@@ -89,6 +89,49 @@ namespace System.Reflection.Emit {
if ((con.Attributes & MethodAttributes.Static) == MethodAttributes.Static ||
(con.Attributes & MethodAttributes.Private) == MethodAttributes.Private)
throw new ArgumentException ("Cannot have private or static constructor.");
+ Type atype = ctor.DeclaringType;
+ int i;
+ i = 0;
+ foreach (FieldInfo fi in namedFields) {
+ Type t = fi.DeclaringType;
+ if ((atype != t) && (!t.IsSubclassOf (atype)) && (!atype.IsSubclassOf (t)))
+ throw new ArgumentException ("Field '" + fi.Name + "' does not belong to the same class as the constructor");
+ // FIXME: Check enums and TypeBuilders as well
+ if (fieldValues [i] != null)
+ // IsEnum does not seem to work on TypeBuilders
+ if (!(fi.FieldType is TypeBuilder) && !fi.FieldType.IsEnum && !fi.FieldType.IsAssignableFrom (fieldValues [i].GetType ())) {
+ throw new ArgumentException ("Value of field '" + fi.Name + "' does not match field type: " + fi.FieldType);
+ }
+ i ++;
+ }
+
+ i = 0;
+ foreach (PropertyInfo pi in namedProperties) {
+ if (!pi.CanWrite)
+ throw new ArgumentException ("Property '" + pi.Name + "' does not have a setter.");
+ Type t = pi.DeclaringType;
+ if ((atype != t) && (!t.IsSubclassOf (atype)) && (!atype.IsSubclassOf (t)))
+ throw new ArgumentException ("Property '" + pi.Name + "' does not belong to the same class as the constructor");
+ // FIXME: Check enums and TypeBuilders as well
+ if (propertyValues [i] != null) {
+ // IsEnum does not seem to work on TypeBuilders
+ if (!(pi.PropertyType is TypeBuilder) && !pi.PropertyType.IsEnum && !pi.PropertyType.IsAssignableFrom (propertyValues [i].GetType ()))
+ throw new ArgumentException ("Value of property '" + pi.Name + "' does not match property type");
+ }
+ i ++;
+ }
+
+ i = 0;
+ foreach (ParameterInfo pi in con.GetParameters ()) {
+ if (pi != null) {
+ Type paramType = pi.ParameterType;
+ if (constructorArgs [i] != null)
+ // IsEnum does not seem to work on TypeBuilders
+ if (!(paramType is TypeBuilder) && !paramType.IsEnum && !paramType.IsAssignableFrom (constructorArgs [i].GetType ()))
+ throw new ArgumentException ("Value of argument " + i + " does not match parameter type: " + paramType);
+ }
+ i ++;
+ }
data = GetBlob (con, constructorArgs, namedProperties, propertyValues, namedFields, fieldValues);
}