Beispiel #1
0
		private void CheckLibrary (MethodBase method, DllImportAttribute attribute, 
				AssemblyCheckInfo report)
		{
			string library = attribute.Value;
			string entrypoint = attribute.EntryPoint;
			string type = method.DeclaringType.FullName;
			string mname = method.Name;

			string found = null;
			string error = null;

			Trace.WriteLine ("Trying to load base library: " + library);

			foreach (string name in GetLibraryNames (method.DeclaringType, library, report)) {
				if (LoadLibrary (type, mname, name, entrypoint, report, out error)) {
					found = name;
					break;
				}
			}

			if (found == null) {
				report.Errors.Add (new MessageInfo (
							type, mname,
							"Could not load library `" + library + "': " + error));
				return;
			}

			// UnixFileInfo f = new UnixFileInfo (soname);
			if (found.EndsWith (".so")) {
				report.Warnings.Add (new MessageInfo (type, mname, 
						string.Format ("Library `{0}' might be a development library",
							found)));
			}
		}
 private void Init(DllImportAttribute dllImport)
 {
     Type type = typeof(DllImportAttribute);
     this.m_ctor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)[0];
     CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[] { new CustomAttributeTypedArgument(dllImport.Value) };
     this.m_typedCtorArgs = Array.AsReadOnly<CustomAttributeTypedArgument>(array);
     CustomAttributeNamedArgument[] argumentArray2 = new CustomAttributeNamedArgument[] { new CustomAttributeNamedArgument(type.GetField("EntryPoint"), dllImport.EntryPoint), new CustomAttributeNamedArgument(type.GetField("CharSet"), dllImport.CharSet), new CustomAttributeNamedArgument(type.GetField("ExactSpelling"), dllImport.ExactSpelling), new CustomAttributeNamedArgument(type.GetField("SetLastError"), dllImport.SetLastError), new CustomAttributeNamedArgument(type.GetField("PreserveSig"), dllImport.PreserveSig), new CustomAttributeNamedArgument(type.GetField("CallingConvention"), dllImport.CallingConvention), new CustomAttributeNamedArgument(type.GetField("BestFitMapping"), dllImport.BestFitMapping), new CustomAttributeNamedArgument(type.GetField("ThrowOnUnmappableChar"), dllImport.ThrowOnUnmappableChar) };
     this.m_namedArgs = Array.AsReadOnly<CustomAttributeNamedArgument>(argumentArray2);
 }
Beispiel #3
0
		private void CheckMember (Type type, MemberInfo mi, AssemblyCheckInfo report)
		{
			DllImportAttribute[] attributes = null;
			MethodBase[] methods = null;
			switch (mi.MemberType) {
				case MemberTypes.Constructor: case MemberTypes.Method: {
					MethodBase mb = (MethodBase) mi;
					attributes = new DllImportAttribute[]{GetDllImportInfo (mb)};
					methods = new MethodBase[]{mb};
					break;
				}
				case MemberTypes.Event: {
					EventInfo ei = (EventInfo) mi;
					MethodBase add = ei.GetAddMethod (true);
					MethodBase remove = ei.GetRemoveMethod (true);
					attributes = new DllImportAttribute[]{
						GetDllImportInfo (add), GetDllImportInfo (remove)};
					methods = new MethodBase[]{add, remove};
					break;
				}
				case MemberTypes.Property: {
					PropertyInfo pi = (PropertyInfo) mi;
					MethodInfo[] accessors = pi.GetAccessors (true);
					if (accessors == null)
						break;
					attributes = new DllImportAttribute[accessors.Length];
					methods = new MethodBase [accessors.Length];
					for (int i = 0; i < accessors.Length; ++i) {
						attributes [i] = GetDllImportInfo (accessors [i]);
						methods [i] = accessors [i];
					}
					break;
				}
			}
			if (attributes == null || methods == null)
				return;

			for (int i = 0; i < attributes.Length; ++i) {
				if (attributes [i] == null)
					continue;
				CheckLibrary (methods [i], attributes [i], report);
			}
		}