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
12
votes
3 answers

Why does the CLR allow mutating boxed immutable value types?

I have a situation where I have a simple, immutable value type: public struct ImmutableStruct { private readonly string _name; public ImmutableStruct( string name ) { _name = name; } public string Name { get…
Johannes Rudolph
  • 35,298
  • 14
  • 114
  • 172
12
votes
1 answer

What is the purpose of MethodInfo.MetadataToken

What is the token normally used for? More importantly, if I have a MetadataToken, can I get back the MethodInfo object?
Arun Satyarth
  • 434
  • 1
  • 4
  • 12
12
votes
2 answers

Exception Info: System.Reflection.TargetInvocationException

I am working on a WPF application an I receive this error only at run time on single device. Exception Info: System.Reflection.TargetInvocationException My question: Any clue of what could be cause this error? Any idea how to debug the…
GibboK
  • 71,848
  • 143
  • 435
  • 658
11
votes
3 answers

print all System.Environment information using System.Reflection

We have a little task to print in a console window all the variables of the Environment class using reflection, but how to do so I don't even have a clue. I am sorry if I've written anything wrong here, I'm new to C#. Of course I could use this kind…
10
votes
2 answers

How to use incompleted types in reflection?

I want to dynamically generate the assembly, which can have functions with different structures. To be more accurate, these functions can be recursive, they can call other functions within the same assembly etc. I found the System.Reflection module…
Alex Aparin
  • 4,393
  • 5
  • 25
  • 51
10
votes
3 answers

Using reflection to get method name and parameters

I am trying to workout a way to programatically create a key for Memcached, based on the method name and parameters. So if I have a method, string GetName(int param1, int param2); it would return: string key = "GetName(1,2)"; I know you can get…
Ash
  • 24,276
  • 34
  • 107
  • 152
10
votes
3 answers

Instantiate Type with internal Constructor with reflection

I have a factory class that needs to instantiate an unknown class. It does it as so: public class Factory { public void SetFoo(Type f) { Activator.CreateInstance(f); } } Problem is I'd like that constructor to be internal, but…
10
votes
2 answers

Test if a method is an override?

Possible Duplicate: Detect if a method was overridden using Reflection (C#) Is there a way to tell if a method is an override? For e.g. public class Foo { public virtual void DoSomething() {} public virtual int GimmeIntPleez() { return 0;…
Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336
10
votes
5 answers

Why would Assembly.GetExecutingAssembly() return null?

I am using a xml file as an embedded resource to load an XDocument. We are using the following code to get the appropriate file from the Assembly: XDocument xd = new XDocument(); Assembly assembly = null; try { assembly =…
Nathan
  • 160
  • 1
  • 1
  • 7
10
votes
1 answer

Why do I need an AssemblyResolve handler for an assembly which is already loaded?

I have two assemblies: App and AddOn. App references AddOn, but CopyLocal is set to false, since AddOn will be loaded dynamically by App. Here is the code in AddOn: namespace AddOn { public class AddOnClass { public static void…
RobSiklos
  • 8,348
  • 5
  • 47
  • 77
10
votes
2 answers

Is it possible to enumerate all methods and properties that are available via Invoke() of an [ADSI] object?

I am curious if someone can describe how to enumerate ADSI methods available via a bound instance as [ADSI]$instance.psbase.Invoke()? Research has turned up "refer to the docs for the ADSI interface". but I am not particularly happy with that…
brandeded
  • 2,080
  • 6
  • 25
  • 52
10
votes
3 answers

How do I look up the internal properties of a C# class? protected? protected internal?

If I have a C# class MyClass as below: using System.Diagnostics; namespace ConsoleApplication1 { class MyClass { public int pPublic {get;set;} private int pPrivate {get;set;} internal int pInternal {get;set;} } …
ryantm
  • 8,217
  • 6
  • 45
  • 57
10
votes
2 answers

Custom Class Attributes in Metro Style App

I am trying to define and retrieve custom attributes on a class in a Metro Style App portable library. Something like [AttributeUsage(AttributeTargets.Class)] public class FooAttribute : Attribute { } [Foo] public class Bar { } class Program { …
9
votes
4 answers

How to get methods in a type

Given: System.Type instance. The aim is to get the newly-introduced methods (i don't know the right word) in the type, which are - not inherited - not overridden I want to use .NET Reflection and I tried the Type.GetMethods() method. But, it…
pnvn
  • 488
  • 1
  • 5
  • 11
9
votes
1 answer

Does calling MakeGenericType(...) multiple times create a new type every time?

I have an Entity Framework Code First model for which I made a static generic class which has a search method which is called for every item in a list. Admitting that this is over my head, I thought making the class static would improve code clarity…
Tom
  • 503
  • 2
  • 13
1 2
3
74 75