/// <summary>
 /// Initializes a new instance of the <see cref="GenericInstSigType"/> class.
 /// </summary>
 /// <param name="baseType">Type of the base.</param>
 /// <param name="genericArguments">The generic args.</param>
 public GenericInstSigType(TypeSigType baseType, SigType[] genericArguments)
     : base(CilElementType.GenericInst)
 {
     this.baseType = baseType;
     this.genericArguments = genericArguments;
     this.containsGenericParameters = CheckContainsOpenGenericParameters();
 }
        /// <summary>
        /// Patches the field.
        /// </summary>
        /// <param name="typeModule">The type module.</param>
        /// <param name="enclosingType">Type of the closed.</param>
        /// <param name="openField">The open field.</param>
        /// <returns></returns>
        RuntimeField IGenericTypePatcher.PatchField(ITypeModule typeModule, CilGenericType enclosingType, RuntimeField openField)
        {
            var openType = openField.DeclaringType as CilGenericType;
            var genericArguments = CloseGenericArguments(enclosingType, openType);
            var patchedType = GetType(openType, genericArguments);

            if (patchedType == null)
            {
                var typeToken = new Token(0xFE000000 | ++typeTokenCounter);
                var signatureToken = new Token(0xFD000000 | ++signatureTokenCounter);
                var sigtype = new TypeSigType(signatureToken, CilElementType.Var);
                var signature = new GenericInstSigType(sigtype, genericArguments);

                // FIXME: There has got to be a better way to do this...
                try
                {
                    patchedType = new CilGenericType(enclosingType.Module, typeToken, openType.BaseGenericType, signature);
                }
                catch (Exception)
                {
                    foreach (var module in typeModule.TypeSystem.TypeModules)
                    {
                        try
                        {
                            patchedType = new CilGenericType(module, typeToken, openType.BaseGenericType, signature);
                            break;
                        }
                        catch (Exception)
                        {
                            ;
                        }
                    }
                }

                AddType(patchedType, genericArguments);
            }

            foreach (var field in patchedType.Fields)
            {
                if (field.Name == openField.Name)
                {
                    return field;
                }
            }

            throw new MissingFieldException();
        }
        /// <summary>
        /// Patches the type.
        /// </summary>
        /// <param name="typeModule">The type module.</param>
        /// <param name="enclosingType">Type of the enclosing.</param>
        /// <param name="openType">Type of the open.</param>
        /// <returns></returns>
        RuntimeType IGenericTypePatcher.PatchType(ITypeModule typeModule, CilGenericType enclosingType, CilGenericType openType)
        {
            var genericArguments = CloseGenericArguments(enclosingType, openType);
            var patchedType = GetType(openType, genericArguments);

            if (patchedType == null)
            {
                var typeToken = new Token(0xFE000000 | ++typeTokenCounter);
                var signatureToken = new Token(0xFD000000 | ++signatureTokenCounter);
                var sigtype = new TypeSigType(signatureToken, CilElementType.Var);
                var signature = new GenericInstSigType(sigtype, genericArguments);

                patchedType = new CilGenericType(enclosingType.InstantiationModule, typeToken, openType.BaseGenericType, signature);
                AddType(patchedType, genericArguments);
            }

            return patchedType;
        }
        /// <summary>
        /// Patches the method.
        /// </summary>
        /// <param name="typeModule">The type module.</param>
        /// <param name="enclosingType">Type of the enclosing.</param>
        /// <param name="openMethod">The open method.</param>
        /// <returns></returns>
        RuntimeMethod IGenericTypePatcher.PatchMethod(ITypeModule typeModule, CilGenericType enclosingType, RuntimeMethod openMethod)
        {
            var openType = openMethod.DeclaringType as CilGenericType;
            var genericArguments = CloseGenericArguments(enclosingType, openType);

            var patchedType = GetType(openType, genericArguments);
            if (patchedType == null)
            {
                var typeToken = new Token(0xFE000000 | ++typeTokenCounter);
                var signatureToken = new Token(0xFD000000 | ++signatureTokenCounter);
                var sigtype = new TypeSigType(signatureToken, CilElementType.Var);
                var signature = new GenericInstSigType(sigtype, genericArguments);

                patchedType = new CilGenericType(enclosingType.InstantiationModule, typeToken, openType.BaseGenericType, signature);
                AddType(patchedType, genericArguments);
            }

            var methodIndex = GetMethodIndex(openMethod);
            return patchedType.Methods[methodIndex];
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericInstSigType"/> class.
 /// </summary>
 /// <param name="baseType">Type of the base.</param>
 /// <param name="genericArguments">The generic args.</param>
 internal GenericInstSigType(TypeSigType baseType, SigType[] genericArguments) :
     base(CilElementType.GenericInst)
 {
     BaseType         = baseType;
     GenericArguments = genericArguments;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericInstSigType"/> class.
 /// </summary>
 /// <param name="baseType">Type of the base.</param>
 /// <param name="genericArguments">The generic args.</param>
 internal GenericInstSigType(TypeSigType baseType, SigType[] genericArguments)
     : base(CilElementType.GenericInst)
 {
     BaseType = baseType;
     GenericArguments = genericArguments;
 }
        /// <summary>
        /// Patches the field.
        /// </summary>
        /// <param name="typeModule">The type module.</param>
        /// <param name="enclosingType">Type of the closed.</param>
        /// <param name="openField">The open field.</param>
        /// <returns></returns>
        RuntimeField IGenericTypePatcher.PatchField(ITypeModule typeModule, CilGenericType enclosingType, RuntimeField openField)
        {
            var openType = openField.DeclaringType as CilGenericType;
            var genericArguments = CloseGenericArguments(enclosingType, openType);

            var patchedType = GetPatchedType(openType, genericArguments);
            if (patchedType == null)
            {
                var typeToken = new Token(0xFE000000 | ++typeTokenCounter);
                var signatureToken = new Token(0xFD000000 | ++signatureTokenCounter);
                var sigtype = new TypeSigType(signatureToken, CilElementType.Var);
                var signature = new GenericInstSigType(sigtype, genericArguments);

                patchedType = new CilGenericType(enclosingType.InstantiationModule, typeToken, openType.BaseGenericType, signature);

                AddPatchedType(openType, genericArguments, patchedType);
            }

            foreach (var field in patchedType.Fields)
            {
                if (field.Name == openField.Name)
                {
                    return field;
                }
            }

            throw new MissingFieldException();
        }