If I have a Singleton class that looks like this:

public interface ICreate<T>
    {
        T Create();
    }

    public sealed class Singleton<TFactory, T>
        where TFactory : ICreate<T>, new()
    {
        Singleton()
        {
        }

        public static T Instance
        {
            get
            {
                return Nested.instance;
            }
        }

        class Nested
        {
            static Nested()
            {
            }

            internal static readonly T instance = new TFactory().Create
();
        }
    }

How do I actually get a MemberReference to the static Instance
property so I can call the get_Instance method?

This is the code that I have so far:

            var genericSingletonType = module.Import(typeof
(Singleton<,>));
            var singletonType = new GenericInstanceType
(genericSingletonType);
            singletonType.GenericArguments.Add(creatorType);
            singletonType.GenericArguments.Add(itemType);

The problem is that since the singletonType is actually a
GenericInstanceType, I can't seem to access the get_Instance method
(or frankly, I'm not sure where to access it). What makes this even
more confusing is that when I look at the operand of a compiler-
emitted Call instruction to the Singleton<TFactory, T>.Instance
property, it lists the get_Instance method as a MemberReference. So my
question is this: How do I emit a call to the instantiated
Singleton<TFactory, T>.get_Instance method? Thanks in advance for your
help!

--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to