Ejemplo n.º 1
0
        private void RegisterType(INamedTypeSymbol namedTypeSymbol, TypeDefinitionData declaringType)
        {
            var accessibility = namedTypeSymbol.DeclaredAccessibility;

            if (!accessibility.IsPublicOrProtected())
            {
                return;
            }

            var typeDefinitionData = new TypeDefinitionData(namedTypeSymbol, declaringType, this);

            _typeDefinitions.Add(namedTypeSymbol.GetFullName(), typeDefinitionData);

            foreach (var typeParameterSymbol in namedTypeSymbol.TypeParameters)
            {
                _typeOwnedGenericParameters.Add(Tuple.Create(namedTypeSymbol.GetFullName(), typeParameterSymbol.Ordinal), new GenericTypeParameterData(typeParameterSymbol, this));
            }

            foreach (var method in namedTypeSymbol.Methods().Where(m => !m.TypeParameters.IsEmpty && m.DeclaredAccessibility.IsPublicOrProtected()))
            {
                var signature = new MethodSignature(Context, method);
                foreach (var typeParameterSymbol in method.TypeParameters)
                {
                    _methodOwnedGenericParameters.Add(Tuple.Create(signature, typeParameterSymbol.Ordinal), new GenericTypeParameterData(typeParameterSymbol, this));
                }
            }

            foreach (var nestedTypeSymbol in namedTypeSymbol.GetTypeMembers())
            {
                RegisterType(nestedTypeSymbol, typeDefinitionData);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Indicates whether a new member of the same type and name is logically the same member as the current member, just from a newer build.
        /// </summary>
        /// <param name="newType">The new member to compare.</param>
        /// <param name="newAssemblyFamily">The assembly family in which new assemblies reside.</param>
        /// <param name="ignoreNewOptionalParameters">
        /// Indicates whether to ignore any new parameters at the end of the collection which are optional when comparing.
        /// </param>
#endif
        private bool IsEquivalentToNewTypeHelper(TypeDefinitionData newType, AssemblyFamily newAssemblyFamily, bool ignoreNewOptionalParameters)
        {
            if (base.IsEquivalentToNewMember(newType, newAssemblyFamily) == false)
            {
                return(false);
            }

            var isEquivalent = this.AssemblyData.IsEquivalentToNewAssembly(newType.AssemblyData);

            if (isEquivalent == false)
            {
                foreach (var source in newType.AssemblyData.GetForwardedTypeSources(newType))
                {
                    if (this.AssemblyData.IsEquivalentToNewAssembly(newAssemblyFamily.GetAssembly(source)))
                    {
                        isEquivalent = true;
                        break;
                    }
                }

                if (isEquivalent == false)
                {
                    return(false);
                }
            }

            return
                (this.GenericParameters.Count == newType.GenericParameters.Count &&
                 this.TypeKind == newType.TypeKind &&
                 this.NameForComparison == newType.OldNameResolved);
        }
Ejemplo n.º 3
0
        private void RegisterType(TypeDefinition type, TypeDefinitionData declaringType)
        {
            var accessibility = type.GetAccessibility();

            if (accessibility == null)
            {
                return;
            }

            var typeDefinitionData = new TypeDefinitionData(type, accessibility.Value, declaringType, this);

            _typeDefinitions.Add(type.FullName, typeDefinitionData);

            foreach (var genericParameter in type.GenericParameters)
            {
                _typeOwnedGenericParameters.Add(Tuple.Create(type.FullName, genericParameter.Position), new GenericTypeParameterData(genericParameter, this));
            }

            foreach (var method in type.Methods.Where(m => m.HasGenericParameters && m.GetAccessibility() != null))
            {
                var signature = new MethodSignature(method);
                foreach (var genericParameter in method.GenericParameters)
                {
                    _methodOwnedGenericParameters.Add(Tuple.Create(signature, genericParameter.Position), new GenericTypeParameterData(genericParameter, this));
                }
            }

            foreach (var nestedType in type.NestedTypes)
            {
                this.RegisterType(nestedType, typeDefinitionData);
            }
        }
Ejemplo n.º 4
0
        private void AddForwardedType(TypeDefinitionData type)
        {
            Debug.Assert(this != type.AssemblyData, "A type should not be forwarded to its own assembly.");

            if (type.AssemblyData._forwardedTypeSources.TryGetValue(type, out List <AssemblyData> forwardedTypeSources) == false)
            {
                type.AssemblyData._forwardedTypeSources[type] = forwardedTypeSources = new List <AssemblyData>();
            }

            forwardedTypeSources.Add(this);
        }
Ejemplo n.º 5
0
        internal ConstructedGenericTypeData(TypeDefinitionData genericTypeDefinition, IEnumerable <TypeData> genericArguments)
            : base(genericTypeDefinition.Name, genericTypeDefinition.Accessibility, genericTypeDefinition.MemberFlags, genericTypeDefinition.TypeKind)
        {
            GenericTypeDefinition = genericTypeDefinition;
            ContainingType        = genericTypeDefinition.ContainingType;

            _isNullable = genericTypeDefinition.IsType(typeof(Nullable <>));

            GenericArguments = new GenericTypeArgumentCollection(genericArguments);
            genericTypeDefinition.RegisterConstructedGenericTypeData(this);
            genericTypeDefinition.AssemblyData.RegisterForFinalize(this);
        }
Ejemplo n.º 6
0
        internal IEnumerable <string> GetForwardedTypeSources(TypeDefinitionData type)
        {
            if (_forwardedTypeSources.TryGetValue(type, out List <AssemblyData> sourceAssemblies))
            {
                foreach (var sourceAssembly in sourceAssemblies)
                {
                    yield return(sourceAssembly.FullName);
                }
            }

            if (_forwardedTypeSourcesOnTarget.TryGetValue(type, out string sourceFullName))
            {
                yield return(sourceFullName);
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Gets the <see cref="TypeDefinitionData"/> instance representing the specified type.
 /// </summary>
 /// <typeparam name="T">The type for which to get the <see cref="TypeDefinitionData"/>.</typeparam>
 /// <returns>The <see cref="TypeDefinitionData"/> instance.</returns>
 public new static TypeDefinitionData FromType <T>()
 {
     return(TypeDefinitionData.FromType(typeof(T)));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the <see cref="TypeData"/> instance containing the metadata for externally visible types and members of the specified <see cref="Type"/>.
        /// </summary>
        /// <param name="type">The type for which of corresponding to the TypeData to get.</param>
        /// <returns>The TypeData instance containing the metadata for externally visible types and members of the specified Type.</returns>
#endif
        internal TypeData GetTypeData(TypeReference type)
        {
            Debug.Assert(type.GetType() != typeof(TypeReference), "The type has not been resolved yet, and may be from a different assembly.");
            Debug.Assert(type.GetDeclaringAssembly().FullName == this.FullName, "The type belongs to another assembly.");

            var genericParameter = type as GenericParameter;

            if (genericParameter != null)
            {
                return(this.GetGenericTypeParameterData(genericParameter));
            }

            var accessibility = type.GetAccessibility();

            if (accessibility == null)
            {
                return(null);
            }

            var typeDefinition = type as TypeDefinition;

            if (typeDefinition != null)
            {
                return(this.GetTypeDefinitionData(typeDefinition.FullName));
            }

            DeclaringTypeData declaringType = null;

            if (type.DeclaringType != null)
            {
                declaringType = (DeclaringTypeData)this.GetTypeData(type.DeclaringType.Resolve());
            }

            var genericInstance = type as GenericInstanceType;

            if (genericInstance != null)
            {
                return(TypeDefinitionData.FromType(genericInstance.ElementType).GetConstructedGenericTypeData(genericInstance.GenericArguments.Select(a => TypeData.FromType(a))));
            }

            if (type.IsByReference)
            {
                Debug.Fail("We should never create representations for by-ref types. They can only be parameter types and ref or out parameters store the element type and indicate whether they are ref or out.");
                return(null);
            }

            var arrayType = type as ArrayType;

            if (arrayType != null)
            {
                Debug.Assert(declaringType == null, "Types with elements should not be declared within other types.");
                return(TypeData.FromType(arrayType.ElementType).GetArrayType((byte)arrayType.Rank));
            }

            var pointerType = type as PointerType;

            if (pointerType != null)
            {
                return(TypeData.FromType(pointerType.ElementType).GetPointerType());
            }

            var modifierType = type as IModifierType;

            if (modifierType != null)
            {
                return(TypeData.FromType(modifierType.ElementType));
            }

            Debug.Fail("Unknown kind of type.");
            return(TypeData.FromType(type.Resolve()));
        }
Ejemplo n.º 9
0
 internal void AddForwardedTypeFromTarget(TypeDefinitionData type, string sourceAssembly)
 {
     _forwardedTypeSourcesOnTarget.Add(type, sourceAssembly);
 }
 /// <summary>
 /// The visit implementation for <see cref="TypeDefinitionData"/> instances.
 /// </summary>
 public virtual void VisitTypeDefinitionData(TypeDefinitionData item)
 {
     this.DefaultVisit(item);
 }