I am looking to be able to replace the reference to a parameter object without using the ref keyword.
The reason I avoid using ref is to keep the collection initializer call looking for the Add(T item) method, and I need the collection class to replace the link with a different version of this interface.
I tried several different ways to do this. At first I tried using the undocumented keywords __makeref , __refvalue and __reftype .
Secondly, I tried to create a DynamicMethod with some IL, which tried to imitate what I observed by looking at a disassembled similar call with the ref parameter.
Here is some code to demonstrate:
using System; using System.Collections.Generic; using System.Collections; using System.Reflection.Emit; using System.Reflection; interface IRecord { string Name { get;} } class ImpA : IRecord { public string Name { get { return "Implementation A"; } } } class ImpB : IRecord { public string Name { get { return "Implementation B"; } } } class RecordList<T> : IEnumerable<T> {
Thanks.
source share