From 790b27fda9428009a95b9bea0b942206b22cd37d Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 9 Mar 2004 23:53:27 +0000 Subject: [PATCH] * CustomAttributeBuilder.cs: Add some argument checking. Handle default arguments properly. svn path=/trunk/mcs/; revision=23853 --- .../corlib/System.Reflection.Emit/ChangeLog | 5 ++ .../CustomAttributeBuilder.cs | 53 ++++++++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/mcs/class/corlib/System.Reflection.Emit/ChangeLog b/mcs/class/corlib/System.Reflection.Emit/ChangeLog index 2affcdd6189..d18177ecb4b 100644 --- a/mcs/class/corlib/System.Reflection.Emit/ChangeLog +++ b/mcs/class/corlib/System.Reflection.Emit/ChangeLog @@ -1,3 +1,8 @@ +2004-03-09 Jackson Harper + + * CustomAttributeBuilder.cs: Add some argument checking. Handle + default arguments properly. + 2004-03-09 Sebastien Pouliot * AssemblyBuilder.cs: The strong name key file existance will now be diff --git a/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs index 498b7b515dd..b5d3903ff4c 100755 --- a/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/CustomAttributeBuilder.cs @@ -37,18 +37,59 @@ namespace System.Reflection.Emit { } public CustomAttributeBuilder( ConstructorInfo con, object[] constructorArgs) - : this (con, constructorArgs, null, null, null, null) { + { + Initialize (con, constructorArgs, new PropertyInfo [0], new object [0], + new FieldInfo [0], new object [0]); } - public CustomAttributeBuilder( ConstructorInfo con, object[] constructorArgs, FieldInfo[] namedFields, object[] fieldValues) - : this (con, constructorArgs, null, null, namedFields, fieldValues) { + public CustomAttributeBuilder( ConstructorInfo con, object[] constructorArgs, + FieldInfo[] namedFields, object[] fieldValues) + { + Initialize (con, constructorArgs, new PropertyInfo [0], new object [0], + namedFields, fieldValues); } - public CustomAttributeBuilder( ConstructorInfo con, object[] constructorArgs, PropertyInfo[] namedProperties, object[] propertyValues) - : this (con, constructorArgs, namedProperties, propertyValues, null, null) { + public CustomAttributeBuilder( ConstructorInfo con, object[] constructorArgs, + PropertyInfo[] namedProperties, object[] propertyValues) + { + Initialize (con, constructorArgs, namedProperties, propertyValues, new FieldInfo [0], + new object [0]); } - public CustomAttributeBuilder( ConstructorInfo con, object[] constructorArgs, PropertyInfo[] namedProperties, object[] propertyValues, FieldInfo[] namedFields, object[] fieldValues) { + public CustomAttributeBuilder( ConstructorInfo con, object[] constructorArgs, + PropertyInfo[] namedProperties, object[] propertyValues, + FieldInfo[] namedFields, object[] fieldValues) + { + Initialize (con, constructorArgs, namedProperties, propertyValues, namedFields, fieldValues); + } + + private void Initialize (ConstructorInfo con, object [] constructorArgs, + PropertyInfo [] namedProperties, object [] propertyValues, + FieldInfo [] namedFields, object [] fieldValues) + { ctor = con; + if (con == null) + throw new ArgumentNullException ("con"); if (constructorArgs == null) throw new ArgumentNullException ("constructorArgs"); + if (namedProperties == null) + throw new ArgumentNullException ("namedProperties"); + if (propertyValues == null) + throw new ArgumentNullException ("propertyValues"); + if (namedFields == null) + throw new ArgumentNullException ("namedFields"); + if (fieldValues == null) + throw new ArgumentNullException ("fieldValues"); + if (con.GetParameterCount () != constructorArgs.Length) + throw new ArgumentException ("Parameter count does not match " + + "passed in argument value count."); + if (namedProperties.Length != propertyValues.Length) + throw new ArgumentException ("Array lengths must be the same.", + "namedProperties, propertyValues"); + if (namedFields.Length != fieldValues.Length) + throw new ArgumentException ("Array lengths must be the same.", + "namedFields, fieldValues"); + if ((con.Attributes & MethodAttributes.Static) == MethodAttributes.Static || + (con.Attributes & MethodAttributes.Private) == MethodAttributes.Private) + throw new ArgumentException ("Cannot have private or static constructor."); + data = GetBlob (con, constructorArgs, namedProperties, propertyValues, namedFields, fieldValues); } -- 2.25.1