Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
1 vote
1 answer
42 views

How to add another (object) delegate to existing using reflection?

I don't know how to cast d for using += operator for adding next method to d. Is here simplest way for it ? As explained first delegate lives outside the class and must be changed via reflection (not ...
SimpleCoder's user avatar
1 vote
1 answer
79 views

Extracting Delegates in generic methods

After some benchmarks I noticed most of my methods I created which use reflection are very, very slow, especially when used in iterations. I found a post from C# Corner, which shows how to create ...
Azzarrel's user avatar
  • 573
0 votes
1 answer
61 views

Why below function is not being optimized by using delegate?

I have below function to send the log. And I used to have a reflection approach.(The commented code inside the function). I would like to optimize the reflection, after some investigation online, I ...
wadefanyaoxia's user avatar
1 vote
2 answers
251 views

How can I using OpCodes and Emit set a parameter to an instantiated Property of type T?

I am trying to write a Method that returns that a DynamicMethod which when Invoked sets the first parameter to an object of Type T, This Object is called Value and is set when the class is ...
NannerBannaner23's user avatar
0 votes
1 answer
114 views

How to create a delegate with dynamically generated properties?

I try to create API endpoints dynamically. However the query I use to construct the endpoint can contain variables that need to be set in the API call. The parameters need to be set one by one in ...
jwillmer's user avatar
  • 3,720
0 votes
1 answer
69 views

Getting the concrete class of a method called inside a delegate in C#

My situation is as follows - a delegate of the form () => _instanceOfMyClassWhichImplementsInterfaceIX.MyMethod() is passed as a parameter to a certain method. Inside that method I need to get ...
galmeida's user avatar
  • 239
0 votes
1 answer
196 views

Simplify passing nameof(someObject) and someObject as parameters to a method

I have a method where I'm currently passing in both someObject and nameof(someObject) since I'm using this method many times I'm wanting to simplify my code by finding a way to only pass in the object ...
LorneCash's user avatar
  • 1,574
0 votes
1 answer
374 views

Create a delegate from Methodinfo with generic parameter

Based on this old but very usefull article by the legendary Jon Skeet, I wrote a few methods to genereate Action Delegates from MethodInfos for faster invokations. But I ran into an issue, where I am ...
christoph's user avatar
  • 1,594
0 votes
0 answers
30 views

Improving interface for compiling delegates from MemberInfo

I work a lot with non-public third-party members in performance-critical cases, and to improve performance I made some extension methods to easily obtained compiled delegates from MemberInfo objects. ...
Matheus Leão's user avatar
0 votes
1 answer
383 views

Reflection with Delegates

I'm using reflection to compare two list of objects(of same type) and collecting the list of properties which have different values. I may iterate through lots of object list to compare which ended in ...
Vignesh G's user avatar
1 vote
1 answer
65 views

How to create a compatible delegate from its type?

I'm trying to create a Standard library with common types for WPF/UWP etc. Since many types are not in Standard, sometimes you have to use reflection. In this connection, the task of creating a ...
EldHasp's user avatar
  • 7,328
0 votes
1 answer
517 views

Delegate.CreateDelegate(Type, object, MethodInfo) throws ArgumentException "Cannot bind to the target method..."

I use a serializer "NetStack.BitBuffer". With reflection I get all read methods like Int32 ReadInt, UInt32 ReadUInt etc. To speed up the invoke from the methodinfo I create delegates but ...
MaZy's user avatar
  • 91
0 votes
0 answers
404 views

ParameterExpression of type 'Data' cannot be used for delegate parameter of type 'System.Object'

i'm trying to write a function that checks the methods with a specific attribute and collects info about them. Then, i need to compile them into expression so it's overhead will be minimal. But when i ...
İsmail Furkan GÖKHASAN's user avatar
1 vote
1 answer
421 views

Add and remove async event handlers using reflection in c#

I have the following code sample that actually works: namespace DeviceLib { public interface IInstrument { event Action<InstrumentConnectionStatus> OnConnectionChanged; ...
user1809065's user avatar
0 votes
0 answers
227 views

How to know if Invoke was called in C#

I have an event Action Event in my code. where I put many events there like this: public class TheClass { public static Action Event; public TheClass() { // dummy ...
felipe's user avatar
  • 1,226

15 30 50 per page
1
2 3 4 5
21