I am aware there are a couple of questions that ask about exactly the same thing as this, however, they don't do what I want. I want something like JavaScript's .call()
. The closest analog to that is Delegate.DynamicInvoke()
but I don't know how I can convert the MethodInfo
object I have to a delegate because I don't have a delegate type to use in MethodInfo.CreateDelegate()
. I see there is a _MethodInfo.Invoke()
but it seems very complicated.
Essentially I want something like this, but in C#:
// lets just assume this is an actual class or something
someclass.prototype.something = function(otherName) {
console.log(this.name, otherName);
}
let obj = {
name: 'words'
};
something.call(obj, 'more words');