Пример #1
0
        /// <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);
        }
Пример #2
0
 internal void PopulateMembers(TypeDefinition underlyingType)
 {
     foreach (var member in underlyingType.GetMembers())
     {
         this.AddMember(MemberDataBase.MemberDataFromReflection(member, this));
     }
 }
Пример #3
0
        internal ParameterData(ParameterDefinition underlyingParameter, MemberDataBase declaringMember)
        {
            var modifer         = ParameterModifier.None;
            var parameterType   = underlyingParameter.ParameterType;
            var byReferenceType = parameterType as ByReferenceType;

            if (byReferenceType != null)
            {
                modifer       = underlyingParameter.IsOut ? ParameterModifier.Out : ParameterModifier.Ref;
                parameterType = byReferenceType.ElementType;
            }

            this.DeclaringMemberKind = declaringMember.MetadataItemKind;
            this.Modifer             = modifer;
            this.Name = underlyingParameter.Name;
            this.Type = TypeData.FromType(parameterType);

            if (underlyingParameter.IsOptional)
            {
                _flags           |= InternalFlags.IsOptional;
                this.DefaultValue = Utilities.PreprocessConstantValue(parameterType, underlyingParameter.GetDefualtValue());
            }

            if (underlyingParameter.CustomAttributes.Any(c => c.AttributeType.EqualsType(typeof(ParamArrayAttribute))))
            {
                _flags |= InternalFlags.IsParamsArray;
            }

            if (underlyingParameter.IsDynamicType())
            {
                _flags |= InternalFlags.IsTypeDynamic;
            }
        }
        /// <summary>
        /// Indicates whether the current member can override the specified member from a base type.
        /// </summary>
        /// <param name="baseMember">The member from the base type.</param>
        /// <returns>True if the current member can override the base member; False otherwise.</returns>
#endif
        internal override bool CanOverrideMember(MemberDataBase baseMember)
        {
            if (base.CanOverrideMember(baseMember) == false)
            {
                return(false);
            }

            return(this.Type == ((TypedMemberDataBase)baseMember).Type);
        }
        /// <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 the current member can override the specified member from a base type.
        /// </summary>
        /// <param name="baseMember">The member from the base type.</param>
        /// <returns>True if the current member can override the base member; False otherwise.</returns>
#endif
        internal override bool CanOverrideMember(MemberDataBase baseMember)
        {
            if (base.CanOverrideMember(baseMember) == false)
            {
                return(false);
            }

            var otherMethodBase = (MethodDataBase)baseMember;

            return(this.Parameters.IsEquivalentTo(otherMethodBase.Parameters));
        }
Пример #7
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>
#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));
        }
Пример #8
0
        /// <inheritdoc/>
        internal override bool CanOverrideMember(MemberDataBase baseMember)
        {
            if (base.CanOverrideMember(baseMember) == false)
            {
                return(false);
            }

            var otherMethod = (MethodData)baseMember;

            return(GenericParameters.Count == otherMethod.GenericParameters.Count);
        }
Пример #9
0
        /// <summary>
        /// Indicates whether the current member can override the specified member from a base type.
        /// </summary>
        /// <param name="baseMember">The member from the base type.</param>
        /// <returns>True if the current member can override the base member; False otherwise.</returns>
#endif
        internal override bool CanOverrideMember(MemberDataBase baseMember)
        {
            if (base.CanOverrideMember(baseMember) == false)
            {
                return(false);
            }

            var otherConstructor = (ConstructorData)baseMember;

            return(this.Parameters.IsEquivalentTo(otherConstructor.Parameters));
        }
Пример #10
0
        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));
        }
Пример #11
0
        /// <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);
        }
Пример #12
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>
#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));
        }
Пример #13
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>
#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));
        }
Пример #14
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>
#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);
        }
Пример #15
0
        internal ParameterData(IParameterSymbol parameterSymbol, MemberDataBase declaringMember)
        {
            Context = declaringMember.Context;

            var parameterType = parameterSymbol.Type;

            ParameterModifier modifer;

            switch (parameterSymbol.RefKind)
            {
            case RefKind.None:
                modifer = ParameterModifier.None;
                break;

            case RefKind.Out:
                modifer = ParameterModifier.Out;
                break;

            case RefKind.Ref:
                modifer = ParameterModifier.Ref;
                break;

            default:
                throw new InvalidOperationException($"Unknown RefKind value: {parameterSymbol.RefKind}");
            }

            DeclaringMemberKind = declaringMember.MetadataItemKind;
            Modifer             = modifer;
            Name = parameterSymbol.Name;
            Type = Context.GetTypeData(parameterType);

            if (parameterSymbol.IsOptional)
            {
                _flags      |= InternalFlags.IsOptional;
                DefaultValue = Utilities.PreprocessConstantValue(parameterType, parameterSymbol.ExplicitDefaultValue);
            }

            if (parameterSymbol.IsParams)
            {
                _flags |= InternalFlags.IsParamsArray;
            }

            if (parameterSymbol.Type.TypeKind == TypeKind.Dynamic)
            {
                _flags |= InternalFlags.IsTypeDynamic;
            }
        }
        /// <summary>
        /// Indicates whether the current member can override the specified member from a base type.
        /// </summary>
        /// <param name="baseMember">The member from the base type.</param>
        /// <returns>True if the current member can override the base member; False otherwise.</returns>
#endif
        internal virtual bool CanOverrideMember(MemberDataBase baseMember)
        {
            // Static members cannot be overridden
            if (this.IsStatic || baseMember.IsStatic)
            {
                return(false);
            }

            // Members which are not virtual, abstract, or override cannot be overridden.
            if (this.IsVirtualCallType == false || baseMember.IsVirtualCallType == false)
            {
                return(false);
            }

            return
                (this.Accessibility == baseMember.Accessibility &&
                 this.Name == baseMember.Name);
        }
        /// <summary>
        /// Adds the specified member to the declaring type.
        /// </summary>
        internal void AddMember(MemberDataBase member)
        {
            if (member == null)
            {
                return;
            }

            if (member.Accessibility != Accessibility.Public && IsSealed)
            {
                return;
            }

            if (_membersByName.TryGetValue(member.Name, out List <MemberDataBase> members) == false)
            {
                members = new List <MemberDataBase>();
                _membersByName[member.Name] = members;
            }

            members.Add(member);
        }
Пример #18
0
        internal MethodData(IMethodSymbol methodSymbol, DeclaringTypeData declaringType)
            : base(methodSymbol, declaringType)
        {
            if (methodSymbol.IsGenericMethod)
            {
                // TODO: This seems odd
                MemberDataBase declaringMember = null;
                if (!methodSymbol.ContainingType.IsConstructed())
                {
                    declaringMember = this;
                }

                GenericParameters = Utilities.GetGenericParameters(methodSymbol.TypeParameters, declaringMember);
            }
            else
            {
                GenericParameters = GenericTypeParameterData.EmptyList;
            }

            IsExtensionMethod = methodSymbol.IsExtensionMethod;
        }
Пример #19
0
        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));
        }
Пример #20
0
        private MethodData(MethodDefinition methodDefinition, MemberAccessibility accessibility, DeclaringTypeData declaringType)
            : base(methodDefinition, accessibility, declaringType)
        {
            if (methodDefinition.HasGenericParameters)
            {
                MemberDataBase declaringMember = null;
                if (methodDefinition.DeclaringType.IsGenericInstance == false)
                {
                    declaringMember = this;
                }

                this.GenericParameters = Utilities.GetGenericParameters(methodDefinition.GenericParameters, declaringMember);
            }
            else
            {
                this.GenericParameters = GenericTypeParameterData.EmptyList;
            }

            this.IsExtensionMethod =
                declaringType.IsExtensionsClass &&
                methodDefinition.CustomAttributes.Any(a => a.AttributeType.EqualsType(typeof(ExtensionAttribute)));
        }
Пример #21
0
        /// <summary>
        /// Adds the specified member to the declaring type.
        /// </summary>
#endif
        internal void AddMember(MemberDataBase member)
        {
            if (member == null)
            {
                return;
            }

            if (member.Accessibility == MemberAccessibility.Protected && this.IsSealed)
            {
                return;
            }

            List <MemberDataBase> members;

            if (_membersByName.TryGetValue(member.Name, out members) == false)
            {
                members = new List <MemberDataBase>();
                _membersByName[member.Name] = members;
            }

            members.Add(member);
        }
Пример #22
0
        /// <inheritdoc/>
        internal override bool CanOverrideMember(MemberDataBase baseMember)
        {
            if (base.CanOverrideMember(baseMember) == false)
            {
                return(false);
            }

            var basePropertyData = (PropertyData)baseMember;

            // Overrides cannot add accessors
            if (GetMethodAccessibility != null && basePropertyData.GetMethodAccessibility == null)
            {
                return(false);
            }

            if (SetMethodAccessibility != null && basePropertyData.SetMethodAccessibility == null)
            {
                return(false);
            }

            // Overrides cannot change the accessibility of accessors
            if (GetMethodAccessibility != null &&
                basePropertyData.GetMethodAccessibility != null &&
                GetMethodAccessibility != basePropertyData.GetMethodAccessibility)
            {
                return(false);
            }

            if (SetMethodAccessibility != null &&
                basePropertyData.SetMethodAccessibility != null &&
                SetMethodAccessibility != basePropertyData.SetMethodAccessibility)
            {
                return(false);
            }

            return(true);
        }
        /// <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)
        {
            return(this.IsEquivalentToNewMember((MethodDataBase)newMember, newAssemblyFamily, ignoreNewOptionalParameters: false));
        }
Пример #24
0
 bool IParameterizedItem.IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily, bool ignoreNewOptionalParameters)
 {
     return(this.IsEquivalentToNewTypeHelper((TypeDefinitionData)newMember, newAssemblyFamily, ignoreNewOptionalParameters));
 }
 internal ParameterCollection(IEnumerable <IParameterSymbol> parameterSymbols, MemberDataBase declaringMember)
 {
     foreach (var parameterSymbol in parameterSymbols)
     {
         Add(new ParameterData(parameterSymbol, declaringMember));
     }
 }
Пример #26
0
        /// <summary>
        /// Indicates whether the current member can override the specified member from a base type.
        /// </summary>
        /// <param name="baseMember">The member from the base type.</param>
        /// <returns>True if the current member can override the base member; False otherwise.</returns>
#endif
        internal override bool CanOverrideMember(MemberDataBase baseMember)
        {
            Debug.Fail("Types cannot be overridden.");
            return(false);
        }
 bool IParameterizedItem.IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily, bool ignoreNewOptionalParameters)
 {
     return(this.IsEquivalentToNewMember((MethodDataBase)newMember, newAssemblyFamily, ignoreNewOptionalParameters));
 }
 internal ParameterCollection(IEnumerable <ParameterDefinition> underlyingParameters, MemberDataBase declaringMember)
 {
     _parameters = new List <ParameterData>();
     foreach (var parameter in underlyingParameters)
     {
         this.Add(new ParameterData(parameter, declaringMember));
     }
 }