reflection.emit Questions

16

Solved

I have a class which looks like this: public class Field { public string FieldName; public string FieldType; } And an object List<Field> with values: {"EmployeeID","int"}, {"EmployeeNam...
Eldon asked 5/10, 2010 at 9:4

1

I need to create a dynamic .NET delegate with specially marshalled parameters (e.g. [MarshalAs(UnamangedType.LPWStr)]) at runtime using System.Reflection.Emit. This requires me to create a type inh...
Brogle asked 29/7, 2020 at 17:27

2

.net Framework 4.7.2... Compiled expressions can access private fields. When I use exactly the same expression and write it to a dynamic assembly, using CompileToMethod, I get a System.FieldAccess...
Santos asked 28/4, 2020 at 17:18

6

I have a UI from where we are adding following values in a table Fields ProductName ProductId ProductCode I have a existing class Product with some existing properties public class Product {...
Aground asked 19/5, 2017 at 10:9

3

Solved

How can I create an asynchronous method using reflection? Basically I need something like this: async public Task asyncmethod() { await something(); } but I need to do it with reflection.
Nabokov asked 15/6, 2012 at 8:17

1

I'm working on an ILGenerator extension to help emit IL fragments using Expression. Everything was fine, until I worked on the integer conversion part. There are something really counter-intuitive ...
Kyoko asked 27/3, 2020 at 7:26

4

Solved

Using the new async/await model it's fairly straightforward to generate a Task that is completed when an event fires; you just need to follow this pattern: public class MyClass { public event Act...
Witchcraft asked 12/10, 2012 at 19:31

6

I'm trying to improve the performance of our application. We have a lot of Activator.CreateInstance calls that are causing some grief. We instantiate a lot of classes based on an interface (ITabDoc...
Alnico asked 5/7, 2011 at 11:56

1

Solved

Using TypeBuilder, I'm building a class that implements an interface that contains a method. After implementing that method with ILGenerator, then I call TypeBuilder.CreateType() and everything goe...
Pistil asked 12/6, 2019 at 14:49

2

Solved

I am trying to create a copy of a method during runtime using reflection. I have the following code. public static R CopyMethod<T, R>(Func<T, R> f, T t) { AppDomain currentDom = Thre...
Cantillate asked 21/1, 2016 at 22:34

1

Solved

Having the class class C { public T Get<T>() { return default; } public void M() { int i = this.Get<Int32>(); } } I want to generate the body of M at runtime using Reflectio...
Outrage asked 21/11, 2018 at 7:46

1

In C# I can easily create an anonymous object like this at the compile time: var items = new { Price = 2000, Description = "", Locations = new List<string> { "", "" } }; My question is...
Ensemble asked 12/11, 2018 at 14:25

3

I am developing a library in C# that generates runtime types using System.Reflection.Emit.TypeBuilder class and i want to generate the following class hierarchy: [XmlInclude(typeof(Derived))] publ...
Growing asked 2/8, 2018 at 8:9

2

Solved

I have this code that emits some IL instructions that calls string.IndexOf on a null object: MethodBuilder methodBuilder = typeBuilder.DefineMethod( "Foo", MethodAttributes.Public, typeof(void)...
Zalucki asked 16/9, 2018 at 0:28

3

I have been using DynamiMethod to generate the IL using method.GetILGenerator(); This works well but is of course very hard to use since you generally don't want to work with low level IL in a ...
Baffle asked 19/8, 2015 at 13:8

3

Solved

I'm wetting my feet with dynamic code generation and System.Reflection.Emit. All seems pretty easy and straightforward, but there's one question which I cannot find answered on the web. When build...
Atrioventricular asked 11/7, 2014 at 10:32

1

I'm making dynamic assemblies with System.Reflection.Emit, and I want to define a module-level field, the kind that can be retrieved with Module.GetField. There are methods in ModuleBuilder to defi...
Incunabulum asked 31/3, 2018 at 23:34

1

Solved

I'm writing a library that requires a later type build. Library uses platform .Net core 2.0 There is issue with some type that I am generating using Reflection.Emit public class GeneratedA : A, I...
Impasse asked 24/2, 2018 at 17:28

2

So I'm emitting some dynamic proxies via DefineDynamicAssembly, and while testing I found that: One type per dynamic assembly: fast, but uses a lot of memory All types in one dynamic assembly: ve...
Dictate asked 14/11, 2017 at 21:48

3

I'm trying to write a DynamicMethod to wrap the cpblk IL opcode. I need to copy chunks of byte arrays and on x64 platforms, this is supposedly the fastest way to do it. Array.Copy and Buffer.BlockC...
Neuroglia asked 9/6, 2014 at 14:56

1

Solved

I'm navigating the ins and outs of ref returns, and am having trouble emitting a dynamic method which returns by ref. Handcrafted lambdas and existing methods work as expected: class Widget { pu...
Prelacy asked 26/7, 2017 at 0:57

2

Solved

Related to How to mutate a boxed struct using IL I am trying to change the value of a boxed value type but in a generic way, so trying to implement the following method: void MutateValueType<T&...
Catercousin asked 23/6, 2017 at 14:35

1

Solved

For performance optimization, I dynamically create new types per user request using the following code: var dynamicAssemblyName = new AssemblyName(assemblyName); AssemblyBuilder dynamicAssembly = ...
Utterance asked 19/6, 2017 at 14:11

4

I am trying to generate a new set of wcf interfaces based on existing interfaces. I am using the Reflection.Emit namespace to accomplish this. My problem is how to copy the old custom attributes fr...
Chalcanthite asked 2/3, 2010 at 18:0

2

Solved

When generating IL using DynamicMethod it's possible to call methods and access fields that would be otherwise un-accessible if you provide 'true' for the restrictedSkipVisibility parameter in the ...
Moschatel asked 29/9, 2009 at 18:20

© 2022 - 2024 — McMap. All rights reserved.