/// <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); }
private static void FromDirectoryHelper(List <Assembly> assemblies, string path, bool recursive) { foreach (var file in Directory.GetFiles(path)) { var extension = Path.GetExtension(file).ToLower(); if (extension == ".dll" || extension == ".exe") { try { assemblies.Add(Assembly.LoadFrom(file)); } catch (BadImageFormatException) { // Ignore files that are not .NET assemblies } } } if (recursive) { foreach (var directory in Directory.GetDirectories(path)) { AssemblyFamily.FromDirectoryHelper(assemblies, directory, recursive); } } }
/// <inheritdoc/> internal override bool IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily) { if (base.IsEquivalentToNewMember(newMember, newAssemblyFamily) == false) { return(false); } var other = newMember as ConstructedGenericTypeData; if (other == null) { return(false); } if (GenericTypeDefinition.IsEquivalentToNew(other.GenericTypeDefinition, newAssemblyFamily) == false) { return(false); } if (GenericArguments.Count != other.GenericArguments.Count) { return(false); } for (int i = 0; i < GenericArguments.Count; i++) { if (GenericArguments[i].IsEquivalentToNewMember(other.GenericArguments[i], newAssemblyFamily) == false) { return(false); } } return(true); }
/// <summary> /// Indicates whether a new parameter collection is logically the same as the current parameter collection, just from a newer build. /// </summary> /// <param name="newParameters">The collection of newer parameters.</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 internal bool IsEquivalentToNewParameters(ParameterCollection newParameters, AssemblyFamily newAssemblyFamily, bool ignoreNewOptionalParameters) { if (ignoreNewOptionalParameters) { if (this.Count < newParameters.RequiredArgumentCount || newParameters.Count < this.Count) { return(false); } } else { if (this.Count != newParameters.Count) { return(false); } } for (int i = 0; i < this.Count; i++) { if (this[i].IsEquivalentToNewParameter(newParameters[i], newAssemblyFamily) == false) { return(false); } } return(true); }
/// <summary> /// Creates an <see cref="AssemblyFamily"/> instance from all assemblies in the specified directory. /// </summary> /// <param name="path">The path from which to load the assemblies.</param> /// <param name="recursive">Indicates whether to recursively search for assemblies in descendant directories</param> /// <returns>The created <see cref="AssemblyFamily"/> instance.</returns> public static AssemblyFamily FromDirectory(string path, bool recursive = false) { var assemblies = new List <Assembly>(); AssemblyFamily.FromDirectoryHelper(assemblies, path, recursive); return(AssemblyFamily.FromAssemblies(assemblies)); }
/// <summary> /// Indicates whether a new parameter of the same type and name is logically the same member as the current parameter, just from a newer build. /// </summary> #endif internal bool IsEquivalentToNewParameter(ParameterData newParameter, AssemblyFamily newAssemblyFamily) { return (this.IsTypeDynamic == newParameter.IsTypeDynamic && this.IsParamsArray == newParameter.IsParamsArray && this.Modifer == newParameter.Modifer && this.Type.IsEquivalentToNew(newParameter.Type, newAssemblyFamily)); }
/// <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> #endif internal virtual bool IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily) { if (this.IsNameUsedToVerifyEquivalence && this.Name != newMember.Name) { return(false); } return(this.MetadataItemKind == newMember.MetadataItemKind); }
/// <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="newMember">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 IsEquivalentToNewMember(ConstructorData newMember, AssemblyFamily newAssemblyFamily, bool ignoreNewOptionalParameters) { if (base.IsEquivalentToNewMember(newMember, newAssemblyFamily) == false) { return(false); } return(this.Parameters.IsEquivalentToNewParameters(newMember.Parameters, newAssemblyFamily, ignoreNewOptionalParameters)); }
/// <summary> /// Creates an <see cref="AssemblyFamily"/> instance from a collection of assemblies. /// </summary> /// <param name="assemblies">A collection of assemblies all belonging to the same logical group.</param> /// <returns>The created <see cref="AssemblyFamily"/> instance.</returns> public static AssemblyFamily FromAssemblies(IEnumerable <Assembly> assemblies) { var family = new AssemblyFamily(); foreach (var assembly in assemblies) { family.Add(AssemblyData.FromAssembly(AssemblyDefinition.ReadAssembly(assembly.Location))); } return(family); }
/// <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> #endif internal override bool IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily) { var newConstructor = newMember as ConstructorData; if (newConstructor == null) { return(false); } return(this.IsEquivalentToNewMember(newConstructor, newAssemblyFamily, ignoreNewOptionalParameters: false)); }
/// <summary> /// Indicates whether the specified type is equivalent to the current type (but from another version). /// </summary> /// <param name="otherType">The type to compare to the current type.</param> /// <param name="newAssemblyFamily">The assembly family in which new assemblies reside.</param> /// <param name="isOtherTypeOld">Indicates whether the type on which this method is called is from the older version of assemblies.</param> /// <returns>True if the types are equivalent but from different assembly versions; False otherwise.</returns> #endif internal bool IsEquivalentTo(TypeData otherType, AssemblyFamily newAssemblyFamily, bool isOtherTypeOld) { if (isOtherTypeOld) { return(otherType.IsEquivalentToNewMember(this, newAssemblyFamily)); } else { return(this.IsEquivalentToNewMember(otherType, newAssemblyFamily)); } }
bool IParameterizedItem.IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily, bool ignoreNewOptionalParameters) { var newConstructor = newMember as ConstructorData; if (newConstructor == null) { return(false); } return(this.IsEquivalentToNewMember(newConstructor, newAssemblyFamily, ignoreNewOptionalParameters)); }
/// <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> #endif internal override bool IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily) { var newType = newMember as TypeDefinitionData; if (newType == null) { return(false); } return(this.IsEquivalentToNewTypeHelper(newType, newAssemblyFamily, ignoreNewOptionalParameters: false)); }
/// <inheritdoc/> internal override bool IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily) { if (base.IsEquivalentToNewMember(newMember, newAssemblyFamily) == false) { return(false); } var otherMethod = (MethodData)newMember; return(GenericParameters.Count == otherMethod.GenericParameters.Count); }
/// <summary> /// Gets the type equivalent to this one which is from a newer assembly. /// </summary> /// <param name="newAssemblyFamily">The assembly family in which new assemblies reside.</param> #endif internal override TypeData GetEquivalentNewType(AssemblyFamily newAssemblyFamily) { var newElementType = this.ElementType.GetEquivalentNewType(newAssemblyFamily); if (newElementType == null) { return(null); } return(newElementType.GetPointerType()); }
/// <summary> /// Creates an <see cref="AssemblyFamily"/> instance from a collection of assemblies. /// </summary> /// <param name="assemblies">A collection of assemblies all belonging to the same logical group.</param> /// <returns>The created <see cref="AssemblyFamily"/> instance.</returns> public static AssemblyFamily FromAssemblies(IEnumerable <Assembly> assemblies) { var context = MetadataResolutionContext.CreateFromAssemblies(assemblies); var family = new AssemblyFamily(); foreach (var assembly in assemblies) { family.Add(context.GetAssemblyData(assembly)); } return(family); }
/// <summary> /// Gets the type equivalent to this one which is from a newer assembly. /// </summary> /// <param name="newAssemblyFamily">The assembly family in which new assemblies reside.</param> #endif internal override TypeData GetEquivalentNewType(AssemblyFamily newAssemblyFamily) { var newElementType = this.ElementType.GetEquivalentNewType(newAssemblyFamily); if (newElementType == null) { return(null); } return (newElementType.GetArrayType(this.ArrayRank) ?? new ArrayTypeData(this.Name, this.Accessibility, this.MemberFlags, this.TypeKind, newElementType, this.ArrayRank)); }
/// <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> #endif internal override bool IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily) { if (base.IsEquivalentToNewMember(newMember, newAssemblyFamily) == false) { return(false); } var other = newMember as TypeWithElementData; return (other != null && this.ElementType.IsEquivalentToNew(other.ElementType, newAssemblyFamily)); }
/// <summary> /// Gets the type equivalent to this one which is from a newer assembly. /// </summary> /// <param name="newAssemblyFamily">The assembly family in which new assemblies reside.</param> #endif internal override TypeData GetEquivalentNewType(AssemblyFamily newAssemblyFamily) { var declaringGenericType = this.GenericDeclaringMember as TypeDefinitionData; if (declaringGenericType != null) { Debug.Assert(this == declaringGenericType.GenericParameters[this.GenericParameterPosition], "This type should be the generic parameter at its position in the declaring type."); var newGenericType = (TypeDefinitionData)declaringGenericType.GetEquivalentNewType(newAssemblyFamily); if (newGenericType == null || newGenericType.GenericParameters.Count <= this.GenericParameterPosition) { return(null); } return(newGenericType.GenericParameters[this.GenericParameterPosition]); } var declaringGenericMethod = this.GenericDeclaringMember as MethodData; if (declaringGenericMethod != null) { Debug.Assert(this == declaringGenericMethod.GenericParameters[this.GenericParameterPosition], "This type should be the generic parameter at its position in the declaring method."); var newDeclaringType = (DeclaringTypeData)declaringGenericMethod.DeclaringType.GetEquivalentNewType(newAssemblyFamily); if (newDeclaringType == null) { return(null); } var matchingMethods = newDeclaringType.GetMembers(declaringGenericMethod.Name).OfType <MethodData>().Where(m => declaringGenericMethod.IsEquivalentToNewMember(m, newAssemblyFamily)).ToList(); if (matchingMethods.Count == 0) { return(null); } Debug.Assert(matchingMethods.Count == 1, "There should only be one matching method."); var newGenericMethod = matchingMethods[0]; if (newGenericMethod.GenericParameters.Count <= this.GenericParameterPosition) { return(null); } return(newGenericMethod.GenericParameters[this.GenericParameterPosition]); } Debug.Fail("Unknown owner of the generic parameter"); return(null); }
/// <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> #endif internal override bool IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily) { if (base.IsEquivalentToNewMember(newMember, newAssemblyFamily) == false) { return(false); } var other = newMember as ArrayTypeData; if (other == null) { return(false); } return(this.ArrayRank == other.ArrayRank); }
/// <summary> /// Gets the type equivalent to this one which is from a newer assembly. /// </summary> /// <param name="newAssemblyFamily">The assembly family in which new assemblies reside.</param> #endif internal override TypeData GetEquivalentNewType(AssemblyFamily newAssemblyFamily) { var newAssembly = newAssemblyFamily.GetEquivalentAssembly(this.AssemblyData); if (newAssembly == null) { return(null); } var newType = newAssembly.GetTypeDefinitionData(this.FullName); if (newType != null) { return(newType); } var oldNamespaceName = this.GetNamespaceName(); var newNamespaceName = newAssembly.GetNewNamespaceName(oldNamespaceName); if (newNamespaceName != null) { var newFullName = newNamespaceName + this.FullName.Substring(oldNamespaceName.Length); newType = newAssembly.GetTypeDefinitionData(newFullName); if (newType != null) { return(newType); } } foreach (var otherAssembly in newAssemblyFamily) { if (otherAssembly == newAssembly) { continue; } newType = otherAssembly.GetTypeDefinitionData(this.FullName); if (newType != null && otherAssembly.GetForwardedTypeSources(newType).Any(s => s == newAssembly.FullName)) { return(newType); } } return(null); }
internal override bool IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily) { if (base.IsEquivalentToNewMember(newMember, newAssemblyFamily) == false) { return(false); } var newGenericParameter = (GenericTypeParameterData)newMember; if (GenericParameterPosition != newGenericParameter.GenericParameterPosition) { return(false); } if (GenericDeclaringMember.MetadataItemKind == MetadataItemKinds.Method && newGenericParameter.GenericDeclaringMember.MetadataItemKind == MetadataItemKinds.Method) { // We will get in here recursively for generic methods that take one of their own generic parameters as a parameter // because the method will check to see whether its parameters are equivalent. All other things being equal, we don't // need to recheck that the methods are equal here (and if we do, we will end up with a SOE). If the methods are // otherwise equal, so are these parameters because they came from the same method and had the same position. // If the methods are not, neither are the parameters. if (_isInIsEquivalentToNewMember) { return(true); } try { _isInIsEquivalentToNewMember = true; return(GenericDeclaringMember.IsEquivalentToNewMember(newGenericParameter.GenericDeclaringMember, newAssemblyFamily)); } finally { _isInIsEquivalentToNewMember = false; } } return(GenericDeclaringMember.IsEquivalentToNewMember(newGenericParameter.GenericDeclaringMember, newAssemblyFamily)); }
/// <inheritdoc/> internal override TypeData GetEquivalentNewType(AssemblyFamily newAssemblyFamily) { var newGenericTypeDefinition = (TypeDefinitionData)GenericTypeDefinition.GetEquivalentNewType(newAssemblyFamily); if (newGenericTypeDefinition == null) { return(null); } var newGenericArguments = new TypeData[GenericArguments.Count]; for (int i = 0; i < GenericArguments.Count; i++) { var newGenericArgument = GenericArguments[i].GetEquivalentNewType(newAssemblyFamily); if (newGenericArgument == null) { return(null); } newGenericArguments[i] = newGenericArgument; } return(newGenericTypeDefinition.GetConstructedGenericTypeData(newGenericArguments)); }
bool IParameterizedItem.IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily, bool ignoreNewOptionalParameters) { return(this.IsEquivalentToNewTypeHelper((TypeDefinitionData)newMember, newAssemblyFamily, ignoreNewOptionalParameters)); }
public IsAssignableFromContext(AssemblyFamily newAssemblyFamily, bool isSourceTypeOld, bool onlyReferenceAndIdentityConversions) { this.IsSourceTypeOld = isSourceTypeOld; this.NewAssemblyFamily = newAssemblyFamily; this.OnlyReferenceAndIdentityConversions = onlyReferenceAndIdentityConversions; }
/// <summary> /// Indicates whether an old type is logically the same as the current type, just from an older build. /// </summary> #endif public bool IsEquivalentToOld(TypeData oldType, AssemblyFamily newAssemblyFamily) { return(oldType.IsEquivalentToNewMember(this, newAssemblyFamily)); }
/// <summary> /// Gets the type equivalent to this one which is from a newer assembly. /// </summary> /// <param name="newAssemblyFamily">The assembly family in which new assemblies reside.</param> #endif internal abstract TypeData GetEquivalentNewType(AssemblyFamily newAssemblyFamily);
/// <summary> /// Indicates whether a variable of the current type is assignable from the specified source type, which is from an older build, if they /// had been from the same assembly version. /// </summary> /// <param name="oldSourceType">The older source type from which to test assignability to this type.</param> /// <param name="newAssemblyFamily"> /// The newer family of assemblies from which to obtain equivalents of older types, or null to use a default family containing only the new type's assembly. /// </param> #endif internal bool IsAssignableFromOld(TypeData oldSourceType, AssemblyFamily newAssemblyFamily = null) { newAssemblyFamily = newAssemblyFamily ?? this.GetDefiningAssemblyFamily(); return(this.IsAssignableFrom(oldSourceType, new IsAssignableFromContext(newAssemblyFamily, isSourceTypeOld: true, onlyReferenceAndIdentityConversions: false))); }
/// <inheritdoc/> internal override TypeData GetEquivalentNewType(AssemblyFamily newAssemblyFamily) => ElementType.GetEquivalentNewType(newAssemblyFamily)?.GetPointerType();
/// <summary> /// Indicates whether a new type is logically the same as the current type, just from a newer build. /// </summary> #endif public bool IsEquivalentToNew(TypeData newType, AssemblyFamily newAssemblyFamily) { return(this.IsEquivalentToNewMember(newType, newAssemblyFamily)); }