The System.Reflection.Emit namespace contains classes that allow a compiler or tool to emit metadata and Microsoft intermediate language (MSIL) and optionally generate a PE file on disk.
Questions tagged [reflection.emit]
737 questions
0
votes
2 answers
Dynamic extraction optimization of nested properties values
I have small piece of code responsible for dynamic extraction of properties values from objects instances through reflection:
public static object ExtractValue(object source, string property)
{
var props = property.Split('.');
var type =…

jwaliszko
- 16,942
- 22
- 92
- 158
0
votes
1 answer
Use emit to return null
I've been using the FastMember project. It contains this code:
il.Emit(OpCodes.Ldarg, 2);
il.Emit(OpCodes.Newobj, typeof(ArgumentOutOfRangeException).GetConstructor(new[] { typeof(string) }));
il.Emit(OpCodes.Throw);
I would like to change that to…

Brannon
- 5,324
- 4
- 35
- 83
0
votes
0 answers
Set attributes to a runtime type created by reflection in Vb .Net
I've a function than create a type at runtime using reflection and I want to show it in a property grid. So my problem is how set attributes like DisplayNameAttribute or CategoryAttribute when I define this types.
My function is the…

Jorge González
- 1
- 2
0
votes
1 answer
Generate C# assembly from source code text file
I have a C# source code in the file (or in text string). How can I use reflection emit to generate and execute this code?
There are so many examples where people generate one class, then add a method etc, but I need top compile-on-the-fly huge piece…

user3258819
- 231
- 2
- 5
0
votes
0 answers
Is it possible to add attributes to an existing class using .NET reflection?
I have the following class generated by EntityFramework,
public partial class Person
{
public string FirstName { get; set; }
public string Lastname { get; set; }
}
Now I would like to add custom Attributes before using it or modifying the…
user677607
0
votes
1 answer
ILGenerator - implementing clone method in a dynamic type
I wish to implement a clone method in a dynamic type, but the problem is I can't new up said type before I've declared typeBuilder.CreateType() - I get the exception: System.NotSupportedException : The invoked member is not supported before the type…

George R
- 3,784
- 3
- 34
- 38
0
votes
0 answers
Converting fields to properties with non-trivial set method to react to changes
Consider I have a data structure:
class Data
{
[Property]
public int i = 3;
[Property]
public UserDefined test = new UserDefined { prop = something; };
}
I'm looking for a way to convert this in runtime to:
class Data :…

Andriy Tylychko
- 15,967
- 6
- 64
- 112
0
votes
0 answers
WCF - Give Class DataContract during Compile or Runtime
If I have the code:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
How do I convert it to the code below at runtime or compile time?
[DataContract]
public class Person
{
[DataMember]
…

BuddyJoe
- 69,735
- 114
- 291
- 466
0
votes
1 answer
Reflection IL Code
I'm new to reflections. I need to create a class which inherits from a parent class. I need to create a readonly property. This property calls an existing function in the parent class by passing an argument 25.
Everything works fine, except that I…
user240021
0
votes
1 answer
CompileAssemblyFromSource test signs an assembly
I have a windows service written in C#. It dynamically generates C# code and compiles them to assemblies as abc.dll, xyz.dll etc. These assemblies are later loaded for execution. When compiling, I pass /keyfile: mykeyfile.snk" as one of the compiler…

Niraj Srivastava
- 3
- 4
0
votes
1 answer
Invalid Program Exception with "Enable 32-bit Applications" set to false
I am generating my own proxy that wraps objects returned from MongoDB. The proxy implements an interface:
interface IProxy
{
string __ID {get;}
}
The Proxy Generator uses the following code to generate the implementation
PropertyBuilder…

Joe Enzminger
- 11,110
- 3
- 50
- 75
0
votes
1 answer
Access related member with IL Emit
how can I write this C# method
public bool CheckIsLocal()
{
return HttpContext.Current.Request.IsLocal;
}
using C# Reflection.Emit?
this method is just a example, my intention is discover how to write code to access related members using C#…

LuigleDR
- 309
- 1
- 2
- 13
0
votes
1 answer
Infer interface by type at compile time
Is there any way to infer an interface from an object based on its type. For instance if I had the following object:
public class Person
{
public string FirstName
{ get; set; }
public string LastName
{ get; set; }
}
I would like to be…

divinebovine
- 168
- 5
0
votes
1 answer
How to create an instance of the class is created at run time
i write some method for create class and property in run time with Reflection.Emit
my code is:
public class DynamicLibraryProperties
{
public string PropName { get; set; }
public Type PropType { get; set; }
…

Pouya
- 1,908
- 17
- 56
- 78
0
votes
1 answer
Emitting Generic Method using Reflection Throws an Exception at Invoke
I am trying this simple example on creating a generic method using Reflection.Emit but it is causing an exception when calling Invoke and I can't find the problem.
public class Program
{
public static void Main(string[] args)
{
…

randacun
- 562
- 1
- 6
- 18