internal object[]? GetPseudoCustomAttributes() { int count = 0; /* MS.NET doesn't report MethodImplAttribute */ MonoMethodInfo info = MonoMethodInfo.GetMethodInfo(mhandle); if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0) { count++; } if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) { count++; } if (count == 0) { return(null); } object[] attrs = new object[count]; count = 0; if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0) { attrs[count++] = new PreserveSigAttribute(); } if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) { attrs[count++] = GetDllImportAttribute(); } return(attrs); }
public void PseudoCustomAttributes() { Type t = typeof(MethodInfoTest); DllImportAttribute attr = (DllImportAttribute)((t.GetMethod("dllImportMethod").GetCustomAttributes(typeof(DllImportAttribute), true)) [0]); Assert.AreEqual(CallingConvention.Winapi, attr.CallingConvention, "#1"); #if MONOTOUCH || FULL_AOT_RUNTIME Assert.AreEqual("readlink", attr.EntryPoint, "#2"); Assert.AreEqual("libc", attr.Value, "#3"); #else Assert.AreEqual("foo", attr.EntryPoint, "#2"); Assert.AreEqual("libfoo", attr.Value, "#3"); #endif Assert.AreEqual(CharSet.Unicode, attr.CharSet, "#4"); Assert.AreEqual(false, attr.ExactSpelling, "#5"); Assert.AreEqual(true, attr.PreserveSig, "#6"); Assert.AreEqual(true, attr.SetLastError, "#7"); Assert.AreEqual(true, attr.BestFitMapping, "#8"); Assert.AreEqual(true, attr.ThrowOnUnmappableChar, "#9"); PreserveSigAttribute attr2 = (PreserveSigAttribute)((t.GetMethod("preserveSigMethod").GetCustomAttributes(true)) [0]); // This doesn't work under MS.NET /* * MethodImplAttribute attr3 = (MethodImplAttribute)((t.GetMethod ("synchronizedMethod").GetCustomAttributes (true)) [0]); */ }
internal object[] GetPseudoCustomAttributes() { int num = 0; MonoMethodInfo methodInfo = MonoMethodInfo.GetMethodInfo(this.mhandle); if ((methodInfo.iattrs & MethodImplAttributes.PreserveSig) != MethodImplAttributes.IL) { num++; } if ((methodInfo.attrs & MethodAttributes.PinvokeImpl) != MethodAttributes.PrivateScope) { num++; } if (num == 0) { return(null); } object[] array = new object[num]; num = 0; if ((methodInfo.iattrs & MethodImplAttributes.PreserveSig) != MethodImplAttributes.IL) { array[num++] = new PreserveSigAttribute(); } if ((methodInfo.attrs & MethodAttributes.PinvokeImpl) != MethodAttributes.PrivateScope) { DllImportAttribute dllImportAttribute = MonoMethod.GetDllImportAttribute(this.mhandle); if ((methodInfo.iattrs & MethodImplAttributes.PreserveSig) != MethodImplAttributes.IL) { dllImportAttribute.PreserveSig = true; } array[num++] = dllImportAttribute; } return(array); }
internal static Attribute[] GetCustomAttributes(RuntimeMethodInfo method, Type caType, bool includeSecCa, out int count) { count = 0; bool flag = (caType == typeof(object)) || (caType == typeof(Attribute)); if ((!flag && (s_pca[caType] == null)) && !IsSecurityAttribute(caType)) { return(new Attribute[0]); } List <Attribute> list = new List <Attribute>(); Attribute item = null; if (flag || (caType == typeof(DllImportAttribute))) { item = DllImportAttribute.GetCustomAttribute(method); if (item != null) { list.Add(item); } } if (flag || (caType == typeof(PreserveSigAttribute))) { item = PreserveSigAttribute.GetCustomAttribute(method); if (item != null) { list.Add(item); } } if (includeSecCa && (flag || IsSecurityAttribute(caType))) { object[] objArray; GetSecurityAttributes(method.Module.ModuleHandle, method.MetadataToken, out objArray); if (objArray != null) { foreach (object obj2 in objArray) { if ((caType == obj2.GetType()) || obj2.GetType().IsSubclassOf(caType)) { list.Add((Attribute)obj2); } } } } count = list.Count; return(list.ToArray()); }
internal static Attribute[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool includeSecCa, out int count) { count = 0; bool flag = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); if (!flag && PseudoCustomAttribute.s_pca.GetValueOrDefault(caType) == null && !PseudoCustomAttribute.IsSecurityAttribute(caType)) { return(new Attribute[0]); } List <Attribute> list = new List <Attribute>(); if (flag || caType == (RuntimeType)typeof(DllImportAttribute)) { Attribute customAttribute = DllImportAttribute.GetCustomAttribute(method); if (customAttribute != null) { list.Add(customAttribute); } } if (flag || caType == (RuntimeType)typeof(PreserveSigAttribute)) { Attribute customAttribute = PreserveSigAttribute.GetCustomAttribute(method); if (customAttribute != null) { list.Add(customAttribute); } } if (includeSecCa && (flag || PseudoCustomAttribute.IsSecurityAttribute(caType))) { object[] array; PseudoCustomAttribute.GetSecurityAttributes(method.Module.ModuleHandle.GetRuntimeModule(), method.MetadataToken, false, out array); if (array != null) { foreach (object obj in array) { if (caType == obj.GetType() || obj.GetType().IsSubclassOf(caType)) { list.Add((Attribute)obj); } } } } count = list.Count; return(list.ToArray()); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Initialize a instance of PreserveSigAttribute class"); try { PreserveSigAttribute myInstance = new PreserveSigAttribute(); if (myInstance == null) { TestLibrary.TestFramework.LogError("001", "the instance of PreserveSigAttribute creating failed"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e); retVal = false; } return retVal; }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Initialize a instance of PreserveSigAttribute class"); try { PreserveSigAttribute myInstance = new PreserveSigAttribute(); if (myInstance == null) { TestLibrary.TestFramework.LogError("001", "the instance of PreserveSigAttribute creating failed"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e); retVal = false; } return(retVal); }
internal object[] GetPseudoCustomAttributes() { int count = 0; /* MS.NET doesn't report MethodImplAttribute */ MonoMethodInfo info = MonoMethodInfo.GetMethodInfo(mhandle); if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0) { count++; } if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) { count++; } if (count == 0) { return(null); } object[] attrs = new object [count]; count = 0; if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0) { attrs [count++] = new PreserveSigAttribute(); } if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) { #if NETCORE throw new NotImplementedException(); #else attrs [count++] = DllImportAttribute.GetCustomAttribute(this); #endif } return(attrs); }
internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType) { bool flag = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); int num; return((flag || !(PseudoCustomAttribute.s_pca.GetValueOrDefault(caType) == null)) && (((flag || caType == (RuntimeType)typeof(DllImportAttribute)) && DllImportAttribute.IsDefined(method)) || ((flag || caType == (RuntimeType)typeof(PreserveSigAttribute)) && PreserveSigAttribute.IsDefined(method)) || ((flag || PseudoCustomAttribute.IsSecurityAttribute(caType)) && PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out num).Length != 0))); }
internal static bool IsDefined(RuntimeMethodInfo method, Type caType) { int num; bool flag = (caType == typeof(object)) || (caType == typeof(Attribute)); if (!flag && (s_pca[caType] == null)) { return(false); } return(((flag || (caType == typeof(DllImportAttribute))) && DllImportAttribute.IsDefined(method)) || (((flag || (caType == typeof(PreserveSigAttribute))) && PreserveSigAttribute.IsDefined(method)) || ((flag || IsSecurityAttribute(caType)) && (GetCustomAttributes(method, caType, true, out num).Length != 0)))); }