public static MethodInfo MakePInvokeStub(string DllPath, string EntryPoint, Type returnType, Type[] parameterTypes) { ModuleBuilder dynamicMod = ScriptDomainManager.CurrentManager.Snippets.Assembly.ModuleBuilder; TypeBuilder tb = dynamicMod.DefineType("pinvoke-" + EntryPoint + Guid.NewGuid(), TypeAttributes.Public); MethodBuilder dynamicMethod = tb.DefineMethod(EntryPoint, MethodAttributes.Static | MethodAttributes.Public | MethodAttributes.PinvokeImpl, CallingConventions.Standard, returnType, parameterTypes); var ci = typeof(DllImportAttribute).GetConstructor(new Type[] { typeof(string) }); dynamicMethod.SetCustomAttribute(new CustomAttributeBuilder(ci, new object[] { DllPath })); var t = tb.CreateType(); MethodInfo mi = t.GetMethod(EntryPoint); try { //Marshal.Prelink(mi); } catch (Exception ex) { Builtins.AssertionViolation("MakePInvokeStub", ex.Message, DllPath, EntryPoint); } return(mi); }
public override long Seek(long offset, SeekOrigin origin) { if (set_pos != null) { set_pos.Call((int)offset); return(offset); } return((long)Builtins.AssertionViolation("set-port-position!", "not supported")); }
public override object this[object key] { get { return(base[key]); } set { Builtins.AssertionViolation("hashtable-set!", "hashtable is readonly", this); } }
public override void Write(byte[] buffer, int offset, int count) { if (HasPosition) { long pos = Position; int written = Convert.ToInt32(write.Call(buffer, offset, count)); if (written != count && written != (Position - pos)) { Builtins.AssertionViolation("write!", "position does not match number of bytes written"); } } else { int written = Convert.ToInt32(write.Call(buffer, offset, count)); if (written != count) { Builtins.AssertionViolation("write!", "could not write all the bytes"); } } }
public override void Write(char[] buffer, int index, int count) { if (HasPosition) { long pos = Position; int written = WriteInternal(buffer, index, count); if (written != count && written != (Position - pos)) { Builtins.AssertionViolation("write!", "position does not match number of characters written"); } } else { int written = WriteInternal(buffer, index, count); if (written != count) { Builtins.AssertionViolation("write!", "could not write all the characters"); } } }
public override void Remove(object key) { Builtins.AssertionViolation("hashtable-remove!", "hashtable is readonly", this); }
public override void Add(object key, object value) { Builtins.AssertionViolation("hashtable-add!", "hashtable is readonly", this); }
public override void Clear() { Builtins.AssertionViolation("hashtable-clear!", "hashtable is readonly", this); }
public override int Read(byte[] buffer, int offset, int count) { Builtins.AssertionViolation("read", "cannot read from output port"); return(0); }
public override void Write(byte[] buffer, int offset, int count) { Builtins.AssertionViolation("write", "cannot write to input port"); }