Beispiel #1
0
        /// <summary>
        /// Visits a particular field's recursive generic arguments
        /// and creates a new specialization based on the results.
        /// </summary>
        /// <param name="field">The field to visit.</param>
        /// <returns>A visited field.</returns>
        public IField Visit(IField field)
        {
            var parentType    = field.ParentType;
            var newParentType = Visit(parentType);

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

            if (newParentType is TypeSpecialization)
            {
                return(IndirectFieldSpecialization.Create(
                           field.GetRecursiveGenericDeclaration(),
                           (TypeSpecialization)newParentType));
            }
            else
            {
                return(field.GetRecursiveGenericDeclaration());
            }
        }
 private static IndirectFieldSpecialization InitializeInstance(
     IndirectFieldSpecialization field)
 {
     field.FieldType = field.parentTy.InstantiatingVisitor.Visit(
         field.Declaration.FieldType);
     field.FullName = field.Declaration.Name.Qualify(
         field.parentTy.FullName);
     return(field);
 }
Beispiel #3
0
        private IReadOnlyList <IField> CreateFields()
        {
            var declFields = Declaration.Fields;
            var fields     = new IField[declFields.Count];

            for (int i = 0; i < fields.Length; i++)
            {
                fields[i] = IndirectFieldSpecialization.Create(declFields[i], this);
            }
            return(fields);
        }