Questions tagged [system.reflection]

System.Reflection is a namespace of the .NET framework. It contains types that retrieve information about assemblies, modules, members, parameters, and other entities in managed code by examining their metadata.

System.Reflection is a namespace of the .NET framework. It contains types that retrieve information about assemblies, modules, members, parameters, and other entities in managed code by examining their metadata.

References

1116 questions
146
votes
7 answers

Difference between LoadFile and LoadFrom with .NET Assemblies?

I was looking at the msdn documentation and I am still a little confused on what exactly is the difference between using LoadFile and LoadFrom when loading an assembly. Can someone provide an example or an analogy to better describe it. The MSDN…
Xaisoft
  • 45,655
  • 87
  • 279
  • 432
51
votes
2 answers

How to get the name of current function?

Possible Duplicate: Can you use reflection to find the name of the currently executing method? C# how to get the name of the current method from code For example: void foo() { Console.Write(__MYNAME__); } print: foo it's possible do it in…
Jack
  • 16,276
  • 55
  • 159
  • 284
42
votes
4 answers

Explicitly call static constructor

I want to write unit test for below class. If name is other than "MyEntity" then mgr should be blank. Negative Unit test Using Manager private accessor I want to change name to "Test" so that mgr should be null. And then will verify the mgr…
meetjaydeep
  • 1,752
  • 4
  • 25
  • 39
42
votes
8 answers

GetProperty reflection results in "Ambiguous match found" on new property

How can I get my property? Currently an error is occuring of Ambiguous match found, see the comment line in code. public class MyBaseEntity { public MyBaseEntity MyEntity { get; set; } } public class MyDerivedEntity : MyBaseEntity { public…
Valamas
  • 24,169
  • 25
  • 107
  • 177
40
votes
1 answer

How to emit a Type in .NET Core

In C#, how do I emit a new Type at runtime with .NET Core? All of the examples I can find for .NET 6 don't seem to work in .NET core (they all begin with getting the current AppDomain, which doesn't exist in .NET core any more). If possible I would…
ThomYorkkke
  • 2,061
  • 3
  • 18
  • 26
40
votes
9 answers

C# Getting Parent Assembly Name of Calling Assembly

I've got a C# unit test application that I'm working on. There are three assemblies involved - the assembly of the C# app itself, a second assembly that the app uses, and a third assembly that's used by the second one. So the calls go like…
Saroop Trivedi
  • 2,245
  • 6
  • 31
  • 49
34
votes
7 answers

Passing C# parameters which can "fit" an interface, but do not actually implement it

Note: I know this is an awful idea in practice; I'm just curious about what the CLR allow you to do, with the goal of creating some sort of 'modify a class after creating it' preprocessor. Suppose I have the following class, which was defined in…
Aaron Christiansen
  • 11,584
  • 5
  • 52
  • 78
32
votes
3 answers

How to call custom operator with Reflection

In my small project I'm using System.Reflection classes to produce executable code. I need to call the + operator of a custom type. Does anybody know how can I call customized operator of custom class using C# reflection?
user35443
  • 6,309
  • 12
  • 52
  • 75
29
votes
2 answers

Using Reflection to set a static variable value before object's initialization?

Is there anyway to set the value of a static (private) variable on an object that has not been initialized? The SetValue method requires an instance, but I'm hoping there's a way to get around this.
Chance
  • 11,043
  • 8
  • 61
  • 84
27
votes
3 answers

I need an alternative to `Assembly.GetEntryAssembly()` that never returns null

I need to find the assembly in which managed code execution started. // using System.Reflection; Assembly entryAssembly = Assembly.GetEntryAssembly(); This seems like the way to go, but the MSDN reference page for Assembly.GetEntryAssembly states…
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
26
votes
8 answers

Convert List to List, Type is known at runtime
I am implementing some kind of deserialization and struggled with a next problem: I have List and System.Reflection.Field, it's FieldType can be List, List or List, so I need to convert from List to that…
Rustam Ganeyev
  • 894
  • 2
  • 12
  • 29
23
votes
4 answers

Dapper with Attributes mapping

I try to map my Id fields with the Column Attributes but for some reason this doesn't seem to work and I can't figure out why. I set up a test project to demonstrate what I am trying. First, I got my 2 entities: Entity Table1 using…
Cornelis
  • 1,729
  • 5
  • 23
  • 39
22
votes
3 answers

Reflection: How do I find and invoke a local functon in C# 7.0?

I have a private static generic method I want to call using reflection, but really I want to 'bundle' it inside of another method. C# 7.0 supports local functions so this is definitely possible. You would say "why don't you just call it directly?"…
22
votes
1 answer

How can I programmatically do method overload resolution in C#?

When the C# compiler interprets a method invocation it must use (static) argument types to determine which overload is actually being invoked. I want to be able to do this programmatically. If I have the name of a method (a string), the type that…
22
votes
2 answers

What does System.Reflection.Missing.Value do?

I encountered a code given below Object oMissing = System.Reflection.Missing.Value oDataDoc = wrdApp.Documents.Open(ref oName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref…
Murtaza Munshi
  • 1,065
  • 4
  • 13
  • 40
1
2 3
74 75