Пример #1
0
        /// <summary>
        /// Visits a particular method's recursive generic arguments
        /// and creates a new specialization based on the results.
        /// </summary>
        /// <param name="method">The method to visit.</param>
        /// <returns>A visited method.</returns>
        public IMethod Visit(IMethod method)
        {
            if (method is DirectMethodSpecialization)
            {
                var specialization = (DirectMethodSpecialization)method;
                return(Visit(specialization.Declaration)
                       .MakeGenericMethod(
                           VisitAll(specialization.GenericArguments)));
            }

            var parentType    = method.ParentType;
            var newParentType = Visit(parentType);

            if (!object.Equals(
                    newParentType.GetRecursiveGenericDeclaration(),
                    parentType.GetRecursiveGenericDeclaration()))
            {
                throw new InvalidOperationException(
                          "Cannot replace parent type of method '" + method.FullName.ToString() +
                          "' by unrelated type '" + newParentType.FullName.ToString() + "'.");
            }

            if (newParentType is TypeSpecialization)
            {
                return(IndirectMethodSpecialization.Create(
                           method.GetRecursiveGenericDeclaration(),
                           (TypeSpecialization)newParentType));
            }
            else
            {
                return(method.GetRecursiveGenericDeclaration());
            }
        }
Пример #2
0
        private static IndirectMethodSpecialization InitializeInstance(IndirectMethodSpecialization instance)
        {
            instance.genericParameterCache = new Lazy <IReadOnlyList <IGenericParameter> >(
                instance.CreateGenericParameters);

            MethodSpecialization.InitializeInstance(instance);
            instance.qualName = instance.Declaration.Name.Qualify(
                instance.parentTy.FullName);

            return(instance);
        }