I have a specific object in C#, call it MyCustomObject. MyCustomObject is of type MyNamespace.CustomObject, and every object of that type contains a method MyCustomMethod. I am trying to get the MethodInfo (System.Reflection.MethodInfo) of MyCustomObject.MyCustomMethod so I can use it to create an expression tree later. However, if I just use typeof(MyCustomObject).GetMethod("MyMethodInfo"), it returns a general method for all objects of type MyNamespace.CustomObject. How can I get the MethodInfo of just MyCustomObject.MyCustomMethod?
Get MethodInfo of a function under a variable in C#
371 Views Asked by 4yl1n At
1
There are 1 best solutions below
Related Questions in C#
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in LAMBDA
- How to convert mathematical expression to lambda function in C++?
- In Rust, how to inspect values captured by a closure?
- Go JSON to Vue front end has issues
- Why non local return from inline function returns from lambda but proceed inline function execution?
- Packages for reading parquets in NodeJS (2024)
- Creation multimap throught lambda-expression
- Clang fails with "function with deduced return type cannot be used before it is defined", while GCC works
- lambda function inside pivot table
- Using lambda function in constexpr constructor with std::tie
- b'./bin/freshclam: error while loading shared libraries: libltdl.so.7: cannot open shared object file: No such file or directory\n'
- Compare two different java collection objects with a common attribute using java streams api
- Deploying .NET 8 aot lambda function to aws from mac
- Set unique identifier for cases with correpsonding previous index / same trace
- wx only execute on mouseover, not during GUI initialization
- OrderBy with lambda?
Related Questions in EXPRESSION
- Evaluating this in Assembly (A % B) % (C % D)
- Creating Array of Arrays in Azure Data Factory
- Nested Expression in Powershell returning part of Expression
- Power BI Dax SUM
- BC30201 Expression expected in Power BI
- How to run a template job only if the previous job failed in Azure DevOps?
- Calculate the count and put in the same matrix table
- Expression tree - how to check if element of a list fulfills specific conditions?
- How to write ADF dynamic expression with SQL statements in multiple levels
- Get FieldExpression value in C#
- gtk4 + python workaround for unsupported functions bind_property_with_closures() and bind_property_full()
- Simple expression evaluation syntax
- Power Automate, get the max/biggest value from an output array
- How can I force a DataGridView to redraw or refresh after any front end changes to the data?
- Is there a runtime cost of assigning variables in Rust?
Related Questions in EXPRESSION-TREES
- Expression tree - how to check if element of a list fulfills specific conditions?
- Expression tree (infix to prefix)
- Expression.Call on array with a custom function
- Create expression trees using generic arguments which involves nested properties
- Accessing x levels of n-ary tree to manipulate a node and add child node with recursion
- Is there no way for Csharp to write a truly static λ expression?
- How to convert Func<T, bool> to Expression<Func<T, bool>>
- Unable to resolve expression constants from variable
- How does .Any() access entity property when built with an expression tree?
- Expression tree to sql, Guid constants are translated to string in database and can't be read as Guid
- CS0834 - A lambda expression with a statement body cannot be converted to an expression tree
- C# merge/combine expressions
- How to NULL check and do a ToLower call along with Contains call dynamically using Expression Tree in C#
- How to combine 2 Func into 1 and pass the resulted Func to an Expression in .NET? The result of the func is dynamic or object
- EFCore 7 reusable expression translation issues on collections
Related Questions in METHODINFO
- Get source file / line from MethodInfo
- Dynamically access methods from other script through string
- C# Creating a Func via reflection
- Reflection Methodinfo - how to use remove for a reflected property (List)
- How do you get DllImportAttribute using System.Reflection?
- How to pass a ValueType arg to a Method in C# reflection?
- MethodInfo.Invoke throws unexpected exception
- How to extract MethodInfo.Invoke parameters from an object maybe implementing IEnumerable<T>
- How to dynamically create a form inside container using reflection?
- Using a lambda inside Linq.Expressions
- Getting MethodInfo from a generated IEnumerator type
- How do I get MethodInfo of a controller action with HttpContext? (NET CORE 2.2)
- Getting the callstack from a method 'A' (MethodBase/MethodInfo) being called from 'B' or 'C' without the stacktrace
- CreateDelegate Error: System.ArgumentException Cannot bind to the target method
- Get RuntimeMethodInfo from generic overloaded methods in non-generic static class
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
When creating your expression tree (per this comment), you presumably want to use the
Callfactory method.In your case, you're trying to create an expression tree representing an instance method call, not a static method call; the difference between them is that an instance method call uses an instance, while a static method call does not.
To create such an expression tree, you'll need some kind of expression tree that represents the instance; it might be a property or field, or the result of another method call. But if you want to apply it to an existing instance, you could pass your instance into the
Constantfactory method.You could pass this node into one of the
Calloverloads which represent an instance method call, such as this one, for an instance method call with no arguments.Something like this:
Addendum
When using the compiler to generate a similar expression tree:
MyCustomObjectisn't represented with aConstantExpression, but rather with aMemberAccessExpression. The C# compiler rewrites closed-over variables (in this case,MyCustomObjectwithin the lambda expression) as a property access on a compiler-generated object. Instead of the call toConstant, the corresponding factory methods to representMyCustomObjectwould look something like this:We can't write something like this in code, because our code doesn't have access to the
<<closure_object>>instance.