コード例 #1
0
        /// <inheritdoc/>
        internal override IEnumerable <TypeData> GetDirectImplicitConversions(bool onlyReferenceAndIdentityConversions)
        {
            if (onlyReferenceAndIdentityConversions && IsValueType)
            {
                yield break;
            }

            if (TypeKind != TypeKind.Enum && BaseType != null)
            {
                yield return(BaseType);
            }

            foreach (var implementedInterface in ImplementedInterfaces)
            {
                yield return(implementedInterface);
            }

            // Any interface type can convert to object
            if (TypeKind == TypeKind.Interface)
            {
                var mscorlibData = AssemblyData.GetReferencedAssembly(Utilities.CommonObjectRuntimeAssemblyName);
                if (mscorlibData != null)
                {
                    yield return(mscorlibData.GetTypeDefinitionData(Utilities.ObjectTypeName));
                }
            }
        }
コード例 #2
0
        internal GenericTypeParameterData(ITypeParameterSymbol typeParameterSymbol, AssemblyData assembly)
            : base(typeParameterSymbol, declaringType: null)
        {
            AssemblyData = assembly;

            // TODO_Refactor: should we expose this info as 4 properties now, like Roslyn?
            switch (typeParameterSymbol.Variance)
            {
            case VarianceKind.In:
                GenericParameterAttributes |= GenericParameterAttributes.Contravariant;
                break;

            case VarianceKind.Out:
                GenericParameterAttributes |= GenericParameterAttributes.Covariant;
                break;
            }

            if (typeParameterSymbol.HasReferenceTypeConstraint)
            {
                GenericParameterAttributes |= GenericParameterAttributes.ReferenceTypeConstraint;
            }
            if (typeParameterSymbol.HasValueTypeConstraint)
            {
                GenericParameterAttributes |= GenericParameterAttributes.NotNullableValueTypeConstraint;
            }
            if (typeParameterSymbol.HasConstructorConstraint)
            {
                GenericParameterAttributes |= GenericParameterAttributes.DefaultConstructorConstraint;
            }

            GenericParameterPosition = typeParameterSymbol.Ordinal;
        }
コード例 #3
0
 internal GenericTypeParameterData(string name, Accessibility accessibility, MemberFlags memberFlags, TypeKind typeKind, AssemblyData assembly, System.Reflection.GenericParameterAttributes genericParameterAttributes, int genericParameterPosition)
     : base(name, accessibility, memberFlags, typeKind)
 {
     AssemblyData = assembly;
     GenericParameterAttributes = genericParameterAttributes;
     GenericParameterPosition   = genericParameterPosition;
 }
コード例 #4
0
 internal TypeDefinitionData(string name, MemberAccessibility accessibility, MemberFlags memberFlags, TypeKind typeKind, AssemblyData assembly, string fullName, TypeDefinitionFlags typeDefinitionFlags, bool delegateReturnTypeIsDynamic)
     : base(name, accessibility, memberFlags, typeKind)
 {
     _assembly = assembly;
     this.DelegateReturnTypeIsDynamic = delegateReturnTypeIsDynamic;
     this.FullName            = fullName;
     this.TypeDefinitionFlags = typeDefinitionFlags;
 }
コード例 #5
0
 internal GenericTypeParameterData(GenericParameter genericTypeParameter, AssemblyData assembly)
     : base(genericTypeParameter, MemberAccessibility.Public, declaringType: null)
 {
     _assembly = assembly;
     this.GenericParameterAttributes = (System.Reflection.GenericParameterAttributes)genericTypeParameter.Attributes;
     this.GenericParameterPosition   = genericTypeParameter.Position;
     this.Constraints = new List <TypeData>();
 }
コード例 #6
0
 internal GenericTypeParameterData(string name, MemberAccessibility accessibility, MemberFlags memberFlags, TypeKind typeKind, AssemblyData assembly, System.Reflection.GenericParameterAttributes genericParameterAttributes, int genericParameterPosition)
     : base(name, accessibility, memberFlags, typeKind)
 {
     _assembly        = assembly;
     this.Constraints = new List <TypeData>();
     this.GenericParameterAttributes = genericParameterAttributes;
     this.GenericParameterPosition   = genericParameterPosition;
 }
コード例 #7
0
        internal TypeDefinitionData(TypeDefinition type, MemberAccessibility accessibility, DeclaringTypeData declaringType, AssemblyData assembly)
            : base(type, accessibility, declaringType)
        {
            _assembly = assembly;

            var typeFlags = TypeDefinitionFlags.None;

            if (this.TypeKind == TypeKind.Class && type.CustomAttributes.Any(a => a.AttributeType.EqualsType(typeof(ExtensionAttribute))))
            {
                typeFlags |= TypeDefinitionFlags.ExtensionsClass;
            }

            if (this.IsSealed == false)
            {
                // A type can only be inherited if it has at least one externally visible constructor and any abstract members are also externally visible.
                var canBeIherited = type.Methods.Where(c => c.IsConstructor && c.GetAccessibility() != null).Any();
                if (this.CanBeInherited)
                {
                    if (type.Methods.Where(m => m.IsSpecialName == false && m.IsConstructor == false && m.GetAccessibility() == null && m.IsAbstract).Any() ||
                        type.Events.Where(e => e.AddMethod.GetAccessibility() == null && e.AddMethod.IsAbstract).Any() ||
                        type.Properties.Where(p => p.GetMethod != null ? p.GetMethod.GetAccessibility() == null && p.GetMethod.IsAbstract : p.SetMethod.GetAccessibility() == null && p.SetMethod.IsAbstract).Any())
                    {
                        canBeIherited = false;
                    }
                }

                if (canBeIherited)
                {
                    typeFlags |= TypeDefinitionFlags.CanBeInherited;
                }
            }

            if (this.TypeKind == TypeKind.Enum)
            {
                var flagsAttributeData = type.CustomAttributes.Where(a => a.AttributeType.EqualsType(typeof(FlagsAttribute))).SingleOrDefault();
                if (flagsAttributeData != null)
                {
                    typeFlags |= TypeDefinitionFlags.FlagsEnum;
                }
            }

            this.TypeDefinitionFlags = typeFlags;
            this.FullName            = type.FullName;

            var renamedAttributeData = type.CustomAttributes.Where(a => a.AttributeType.EqualsType(typeof(TypeRenamedAttribute))).SingleOrDefault();

            if (renamedAttributeData != null)
            {
                this.OldName = renamedAttributeData.ConstructorArguments[0].Value as string;
            }

            var typeForwardedFromAttribute = type.CustomAttributes.Where(a => a.AttributeType.EqualsType(typeof(TypeForwardedFromAttribute))).SingleOrDefault();

            if (typeForwardedFromAttribute != null)
            {
                this.AssemblyData.AddForwardedTypeFromTarget(this, typeForwardedFromAttribute.ConstructorArguments[0].Value.ToString());
            }
        }
コード例 #8
0
        /// <summary>
        /// Gets the derived <see cref="TypeData"/> instance representing the specified type.
        /// </summary>
        /// <param name="t">The type for which to get the <see cref="TypeData"/>.</param>
        /// <returns>The derived <see cref="TypeData"/> instance.</returns>
        public static TypeData FromType(TypeReference t)
        {
            if (t.GetType() == typeof(TypeReference))
            {
                t = t.Resolve();
            }

            // TODO_Public: throw an exception if the type is not externally visible
            return(AssemblyData.FromAssembly(t.GetDeclaringAssembly()).GetTypeData(t));
        }
コード例 #9
0
        /// <summary>
        /// Gets the <see cref="AssemblyData"/> instance containing the metadata for externally visible types and members of the specified <see cref="Assembly"/>.
        /// </summary>
        /// <param name="assembly">The Assembly for which the AssemblyData should be obtained.</param>
        /// <returns>The AssemblyData instance containing the metadata for externally visible types and members of the specified Assembly.</returns>
        public static AssemblyData FromAssembly(AssemblyDefinition assembly)
        {
            lock (_cachedAssemblyDatas)
            {
                AssemblyData assemblyData;
                if (_cachedAssemblyDatas.TryGetValue(assembly.FullName, out assemblyData) == false)
                {
                    assemblyData = new AssemblyData(assembly);
                    _cachedAssemblyDatas[assembly.FullName] = assemblyData;
                    assemblyData.LoadFromMetadata(assembly);
                }

                return(assemblyData);
            }
        }
コード例 #10
0
        internal TypeDefinitionData(INamedTypeSymbol typeSymbol, DeclaringTypeData declaringType, AssemblyData assembly)
            : base(typeSymbol, declaringType)
        {
            AssemblyData = assembly;

            var typeFlags = TypeDefinitionFlags.None;

            // A type can only be inherited if it is unsealed, has at least one externally visible
            // constructor, and any abstract members are also externally visible.
            if (!IsSealed &&
                typeSymbol.Methods().Any(c => c.MethodKind == MethodKind.Constructor && c.DeclaredAccessibility.IsPublicOrProtected()) &&
                !typeSymbol.Members().Any(m => m.IsAbstract && !m.DeclaredAccessibility.IsPublicOrProtected()))
            {
                typeFlags |= TypeDefinitionFlags.CanBeInherited;
            }

            if (TypeKind == TypeKind.Enum)
            {
                var flagsAttributeData = typeSymbol.GetAttributes().Where(a => a.AttributeClass.EqualsType(typeof(FlagsAttribute))).SingleOrDefault();
                if (flagsAttributeData != null)
                {
                    typeFlags |= TypeDefinitionFlags.FlagsEnum;
                }
            }

            TypeDefinitionFlags = typeFlags;
            FullName            = typeSymbol.GetFullName();

            var renamedAttributeData = typeSymbol.GetAttributes().Where(a => a.AttributeClass.GetFullName() == typeof(TypeRenamedAttribute).FullName).SingleOrDefault();

            if (renamedAttributeData != null)
            {
                OldName = renamedAttributeData.ConstructorArguments[0].Value as string;
            }

            var typeForwardedFromAttribute = typeSymbol.GetAttributes().Where(a => a.AttributeClass.EqualsType(typeof(TypeForwardedFromAttribute))).SingleOrDefault();

            if (typeForwardedFromAttribute != null)
            {
                AssemblyData.AddForwardedTypeFromTarget(this, typeForwardedFromAttribute.ConstructorArguments[0].Value.ToString());
            }
        }
コード例 #11
0
        /// <summary>
        /// Adds the <see cref="AssemblyData"/> of a directly assembly reference to the current AssemblyData.
        /// </summary>
        /// <param name="reference">The AssemblyData of the directly referenced assembly.</param>
#endif
        private void AddReference(AssemblyData reference)
        {
            _referencedAssemblies.Add(reference);
        }
コード例 #12
0
        /// <summary>
        /// Indicates whether the current assembly is logically equivalent to the specified assembly, just from a different version.
        /// </summary>
        /// <param name="assemblyData"></param>
#endif
        internal bool IsEquivalentToNewAssembly(AssemblyData assemblyData)
        {
            return(assemblyData != null && this.VersionComparisonName == assemblyData.VersionComparisonName);
        }
コード例 #13
0
 /// <summary>
 /// Gets the <see cref="AssemblyData"/> instance containing the metadata for externally visible types and members of the specified <see cref="Assembly"/>.
 /// </summary>
 /// <param name="assembly">The Assembly for which the AssemblyData should be obtained.</param>
 /// <returns>The AssemblyData instance containing the metadata for externally visible types and members of the specified Assembly.</returns>
 public static AssemblyData FromAssembly(Assembly assembly)
 {
     return(AssemblyData.FromAssembly(assembly.ToAssemblyDefinition()));
 }
コード例 #14
0
 /// <summary>
 /// Gets the derived <see cref="GenericTypeParameterData"/> instance representing the specified type.
 /// </summary>
 /// <returns>The derived <see cref="GenericTypeParameterData"/> instance.</returns>
 internal static GenericTypeParameterData FromType(GenericParameter t)
 {
     return(AssemblyData.FromAssembly(t.GetDeclaringAssembly()).GetGenericTypeParameterData(t));
 }
コード例 #15
0
 /// <summary>
 /// Indicates whether the current assembly is logically equivalent to the specified assembly, just from a different version.
 /// </summary>
 /// <param name="assemblyData"></param>
 internal bool IsEquivalentToNewAssembly(AssemblyData assemblyData) =>
 VersionComparisonName == assemblyData?.VersionComparisonName;
コード例 #16
0
 /// <summary>
 /// The visit implementation for <see cref="AssemblyData"/> instances.
 /// </summary>
 public virtual void VisitAssemblyData(AssemblyData item)
 {
     this.DefaultVisit(item);
 }