- string attrname = customBuilder.Ctor.ReflectedType.FullName;
- if (attrname == "System.Runtime.CompilerServices.MethodImplAttribute") {
- byte[] data = customBuilder.Data;
- int impla; // the (stupid) ctor takes a short or an int ...
- impla = (int)data [2];
- impla |= ((int)data [3]) << 8;
- SetImplementationFlags ((MethodImplAttributes)impla);
- return;
- }
- if (attrname == "System.Runtime.InteropServices.DllImportAttribute") {
- CustomAttributeBuilder.CustomAttributeInfo attr = CustomAttributeBuilder.decode_cattr (customBuilder);
- bool preserveSig = true;
-
- /*
- * It would be easier to construct a DllImportAttribute from
- * the custom attribute builder, but the DllImportAttribute
- * does not contain all the information required here, ie.
- * - some parameters, like BestFitMapping has three values
- * ("on", "off", "missing"), but DllImportAttribute only
- * contains two (on/off).
- * - PreserveSig is true by default, while it is false by
- * default in DllImportAttribute.
- */
-
- pi_dll = (string)attr.ctorArgs [0];
- native_cc = System.Runtime.InteropServices.CallingConvention.Winapi;
-
- for (int i = 0; i < attr.namedParamNames.Length; ++i) {
- string name = attr.namedParamNames [i];
- object value = attr.namedParamValues [i];
-
- if (name == "CallingConvention")
- native_cc = (CallingConvention)value;
- else if (name == "CharSet")
- charset = (CharSet)value;
- else if (name == "EntryPoint")
- pi_entry = (string)value;
- else if (name == "ExactSpelling")
- ExactSpelling = (bool)value;
- else if (name == "SetLastError")
- SetLastError = (bool)value;
- else if (name == "PreserveSig")
- preserveSig = (bool)value;
+
+ switch (customBuilder.Ctor.ReflectedType.FullName) {
+ case "System.Runtime.CompilerServices.MethodImplAttribute":
+ byte[] data = customBuilder.Data;
+ int impla; // the (stupid) ctor takes a short or an int ...
+ impla = (int)data [2];
+ impla |= ((int)data [3]) << 8;
+ iattrs |= (MethodImplAttributes)impla;
+ return;
+
+ case "System.Runtime.InteropServices.DllImportAttribute":
+ CustomAttributeBuilder.CustomAttributeInfo attr = CustomAttributeBuilder.decode_cattr (customBuilder);
+ bool preserveSig = true;
+
+ /*
+ * It would be easier to construct a DllImportAttribute from
+ * the custom attribute builder, but the DllImportAttribute
+ * does not contain all the information required here, ie.
+ * - some parameters, like BestFitMapping has three values
+ * ("on", "off", "missing"), but DllImportAttribute only
+ * contains two (on/off).
+ * - PreserveSig is true by default, while it is false by
+ * default in DllImportAttribute.
+ */
+
+ pi_dll = (string)attr.ctorArgs[0];
+ if (pi_dll == null || pi_dll.Length == 0)
+ throw new ArgumentException ("DllName cannot be empty");
+
+ native_cc = System.Runtime.InteropServices.CallingConvention.Winapi;
+
+ for (int i = 0; i < attr.namedParamNames.Length; ++i) {
+ string name = attr.namedParamNames [i];
+ object value = attr.namedParamValues [i];
+
+ if (name == "CallingConvention")
+ native_cc = (CallingConvention)value;
+ else if (name == "CharSet")
+ charset = (CharSet)value;
+ else if (name == "EntryPoint")
+ pi_entry = (string)value;
+ else if (name == "ExactSpelling")
+ ExactSpelling = (bool)value;
+ else if (name == "SetLastError")
+ SetLastError = (bool)value;
+ else if (name == "PreserveSig")
+ preserveSig = (bool)value;