public static RuntimeMethodHandle GetMethodHandleFromIntPtr(IntPtr ptr) { var temp = new IntPtrAndHandle { ptr = ptr }; return(temp.methodHandle); }
private static RuntimeTypeHandle GetTypeHandleFromIntPtr(IntPtr ptr) { var temp = new IntPtrAndHandle { ptr = ptr }; return(temp.typeHandle); }
//FIXME this probably won't handle generics static string GetCallSignature(IntPtr method_handle) { IntPtrAndHandle tmp = default(IntPtrAndHandle); tmp.ptr = method_handle; var mb = MethodBase.GetMethodFromHandle(tmp.handle); string res = ""; foreach (var p in mb.GetParameters()) { var t = p.ParameterType; switch (Type.GetTypeCode(t)) { case TypeCode.Byte: case TypeCode.SByte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Boolean: res += "i"; break; case TypeCode.Int64: case TypeCode.UInt64: res += "l"; break; case TypeCode.Single: res += "f"; break; case TypeCode.Double: res += "d"; break; case TypeCode.String: res += "s"; break; default: if (t.IsValueType) { throw new Exception("Can't handle VT arguments"); } res += "o"; break; } } return(res); }
static object ObjectToEnum(IntPtr method_handle, int parm, object obj) { IntPtrAndHandle tmp = default(IntPtrAndHandle); tmp.ptr = method_handle; var mb = MethodBase.GetMethodFromHandle(tmp.handle); var parmType = mb.GetParameters()[parm].ParameterType; if (parmType.IsEnum) { return(Runtime.EnumFromExportContract(parmType, obj)); } else { return(null); } }
//FIXME this probably won't handle generics static string GetCallSignature(IntPtr method_handle) { IntPtrAndHandle tmp = default(IntPtrAndHandle); tmp.ptr = method_handle; var mb = MethodBase.GetMethodFromHandle(tmp.handle); string res = ""; foreach (var p in mb.GetParameters()) { var t = p.ParameterType; switch (Type.GetTypeCode(t)) { case TypeCode.Byte: case TypeCode.SByte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Boolean: // Enums types have the same code as their underlying numeric types if (t.IsEnum) { res += "j"; } else { res += "i"; } break; case TypeCode.Int64: case TypeCode.UInt64: // Enums types have the same code as their underlying numeric types if (t.IsEnum) { res += "k"; } else { res += "l"; } break; case TypeCode.Single: res += "f"; break; case TypeCode.Double: res += "d"; break; case TypeCode.String: res += "s"; break; default: if (t == typeof(IntPtr)) { res += "i"; } else if (t == typeof(Uri)) { res += "u"; } else { if (t.IsValueType) { throw new Exception("Can't handle VT arguments"); } res += "o"; } break; } } return(res); }
public static string GetCallSignature(IntPtr methodHandle, object objForRuntimeType) { IntPtrAndHandle tmp = default(IntPtrAndHandle); tmp.ptr = methodHandle; MethodBase?mb = objForRuntimeType == null?MethodBase.GetMethodFromHandle(tmp.handle) : MethodBase.GetMethodFromHandle(tmp.handle, Type.GetTypeHandle(objForRuntimeType)); if (mb == null) { return(string.Empty); } ParameterInfo[] parms = mb.GetParameters(); int parmsLength = parms.Length; if (parmsLength == 0) { return(string.Empty); } char[] res = new char[parmsLength]; for (int c = 0; c < parmsLength; c++) { Type t = parms[c].ParameterType; switch (Type.GetTypeCode(t)) { case TypeCode.Byte: case TypeCode.SByte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Boolean: // Enums types have the same code as their underlying numeric types if (t.IsEnum) { res[c] = 'j'; } else { res[c] = 'i'; } break; case TypeCode.Int64: case TypeCode.UInt64: // Enums types have the same code as their underlying numeric types if (t.IsEnum) { res[c] = 'k'; } else { res[c] = 'l'; } break; case TypeCode.Single: res[c] = 'f'; break; case TypeCode.Double: res[c] = 'd'; break; case TypeCode.String: res[c] = 's'; break; default: if (t == typeof(IntPtr)) { res[c] = 'i'; } else if (t == typeof(Uri)) { res[c] = 'u'; } else if (t == typeof(SafeHandle)) { res[c] = 'h'; } else { if (t.IsValueType) { throw new NotSupportedException(SR.ValueTypeNotSupported); } res[c] = 'o'; } break; } } return(new string(res)); }