public static unsafe string GetGenericParamName(IMetaDataImport2 mdi2, uint token) { if (mdi2 == null) return null; char[] nameBuf = null; uint chName; int hr = mdi2.GetGenericParamProps(token, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0, new IntPtr(&chName)); if (hr >= 0 && chName != 0) { nameBuf = new char[chName]; fixed (char* p = &nameBuf[0]) hr = mdi2.GetGenericParamProps(token, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, new IntPtr(p), (uint)nameBuf.Length, new IntPtr(&chName)); } if (hr < 0) return null; if (chName <= 1) return string.Empty; return new string(nameBuf, 0, (int)chName - 1); }
public static unsafe bool GetGenericParamNumAndAttrs(IMetaDataImport2 mdi2, uint token, out ushort number, out GenericParamAttributes attrs) { number = ushort.MaxValue; attrs = 0; if (mdi2 == null) return false; uint ulParamSeq, dwParamFlags; int hr = mdi2.GetGenericParamProps(token, new IntPtr(&ulParamSeq), new IntPtr(&dwParamFlags), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0, IntPtr.Zero); if (hr != 0) return false; number = (ushort)ulParamSeq; attrs = (GenericParamAttributes)dwParamFlags; return true; }
public unsafe static uint GetGenericParamOwner(IMetaDataImport2 mdi2, uint token) { if (mdi2 == null) return 0; uint ownerToken; int hr = mdi2.GetGenericParamProps(token, IntPtr.Zero, IntPtr.Zero, new IntPtr(&ownerToken), IntPtr.Zero, IntPtr.Zero, 0, IntPtr.Zero); if (hr != 0) return 0; var ownerMdToken = new MDToken(ownerToken); return ownerMdToken.Table == Table.TypeDef || ownerMdToken.Table == Table.Method ? ownerMdToken.Raw : 0; }