コード例 #1
0
 internal MethodData(string name, MemberAccessibility accessibility, MemberFlags memberFlags, TypeData type, bool isTypeDynamic, GenericTypeParameterCollection genericParameters, bool isExtensionMethod, ParameterCollection parameters)
     : base(name, accessibility, memberFlags, type, isTypeDynamic, parameters)
 {
     this.GenericParameters = genericParameters;
     this.IsExtensionMethod = isExtensionMethod;
 }
コード例 #2
0
 internal ConstantData(string name, Accessibility accessibility, MemberFlags memberFlags, TypeData type, bool isTypeDynamic, object value)
     : base(name, accessibility, memberFlags, type, isTypeDynamic) =>
コード例 #3
0
 internal IndexerData(string name, Accessibility accessibility, MemberFlags memberFlags, TypeData type, bool isTypeDynamic, ParameterCollection parameters, Accessibility?getMethodAccessibility, Accessibility?setMethodAccessibility)
     : base(name, accessibility, memberFlags, type, isTypeDynamic, getMethodAccessibility, setMethodAccessibility) =>
コード例 #4
0
 internal EventData(string name, MemberAccessibility accessibility, MemberFlags memberFlags, TypeData type)
     : base(name, accessibility, memberFlags, type, isTypeDynamic: false)
 {
 }
コード例 #5
0
 internal PropertyData(string name, Accessibility accessibility, MemberFlags memberFlags, TypeData type, bool isTypeDynamic, Accessibility?getMethodAccessibility, Accessibility?setMethodAccessibility)
     : base(name, accessibility, memberFlags, type, isTypeDynamic)
 {
     GetMethodAccessibility = getMethodAccessibility;
     SetMethodAccessibility = setMethodAccessibility;
 }
コード例 #6
0
 /// <summary>
 /// Gets the <see cref="TypeDefinitionData"/> instance representing the specified type.
 /// </summary>
 /// <returns>The <see cref="TypeDefinitionData"/> instance.</returns>
 public new static TypeDefinitionData FromType(TypeReference t)
 {
     return((TypeDefinitionData)TypeData.FromType(t));
 }
コード例 #7
0
        /// <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));
        }
コード例 #8
0
 internal OperatorData(string name, Accessibility accessibility, MemberFlags memberFlags, TypeData type, bool isTypeDynamic, ParameterCollection parameters)
     : base(name, accessibility, memberFlags, type, isTypeDynamic, parameters)
 {
 }
コード例 #9
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(Type t)
 {
     return(TypeData.FromType(
                t.Assembly.ToAssemblyDefinition().MainModule.GetType(t.FullName, runtimeName: true)));
 }
コード例 #10
0
        /// <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));
        }
コード例 #11
0
 /// <summary>
 /// Gets the derived <see cref="TypeData"/> instance representing the specified type.
 /// </summary>
 /// <typeparam name="T">The type for which to get the <see cref="TypeData"/>.</typeparam>
 /// <returns>The derived <see cref="TypeData"/> instance.</returns>
 public static TypeData FromType <T>()
 {
     return(TypeData.FromType(typeof(T)));
 }
コード例 #12
0
 /// <summary>
 /// Gets the derived <see cref="ConstructedGenericTypeData"/> instance representing the specified type.
 /// </summary>
 /// <returns>The derived <see cref="ConstructedGenericTypeData"/> instance.</returns>
 public new static ConstructedGenericTypeData FromType(Type t)
 {
     // TODO_Public: throw an exception if the type is not a constructed generic
     return((ConstructedGenericTypeData)TypeData.FromType(t));
 }
コード例 #13
0
 internal ArrayTypeData(TypeData elementType, byte arrayRank)
     : base($"{elementType.Name}[{new string(',', arrayRank - 1)}]", Accessibility.Public, MemberFlags.None, TypeKind.Class, elementType) =>
コード例 #14
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()));
        }
コード例 #15
0
 internal virtual bool IsArray(out int rank, out TypeData elementType)
 {
     rank        = 0;
     elementType = null;
     return(false);
 }
コード例 #16
0
        private void LoadFromMetadata(AssemblyDefinition assembly)
        {
            _isLoading = true;

            foreach (var module in assembly.Modules)
            {
                foreach (var type in module.Types)
                {
                    this.RegisterType(type, null);
                }
            }

            // Finalize Definitions
            this.IterateAllTypeDefinitions(assembly,
                                           typeDefinitionAction: type =>
            {
                var typeData = (TypeDefinitionData)this.GetTypeData(type);
                if (typeData == null)
                {
                    return(false);
                }

                typeData.FinalizeDefinition(type);
                return(true);
            },
                                           genericParameterAction: genericParameter =>
            {
                this.GetGenericTypeParameterData(genericParameter).FinalizeDefinition(genericParameter);
            });

            // Populate Members
            this.IterateAllTypeDefinitions(assembly,
                                           typeDefinitionAction: type =>
            {
                var typeData = (TypeDefinitionData)this.GetTypeData(type);
                if (typeData == null)
                {
                    return(false);
                }

                typeData.PopulateMembers(type);
                return(true);
            });

            while (_constructedGenericsToFinalizeAfterLoad.Count != 0)
            {
                var temp = _constructedGenericsToFinalizeAfterLoad.ToArray();
                _constructedGenericsToFinalizeAfterLoad.Clear();
                foreach (var type in temp)
                {
                    type.FinalizeDefiniton();
                }
            }

            foreach (var type in assembly.MainModule.ExportedTypes.Where(e => e.IsForwarder).Select(t => (TypeDefinitionData)TypeData.FromType(t.Resolve())).Where(t => t != null))
            {
                this.AddForwardedType(type);
            }

            foreach (var referenceName in assembly.Modules.SelectMany(m => m.AssemblyReferences))
            {
                AssemblyData reference;
                if (_cachedAssemblyDatas.TryGetValue(referenceName.FullName, out reference))
                {
                    _referencedAssemblies.Add(reference);
                }
            }

            _isLoading = false;
        }
コード例 #17
0
        /// <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)));
        }
コード例 #18
0
 internal TypeWithElementData(string name, MemberAccessibility accessibility, MemberFlags memberFlags, TypeKind typeKind, TypeData elementType)
     : base(name, accessibility, memberFlags, typeKind)
 {
     this.ElementType = elementType;
 }
コード例 #19
0
        /// <summary>
        /// Indicates whether the type is a nullable value type.
        /// </summary>
        /// <param name="underlyingType">[Out] Will be set to the underlying value type if the tpye is nullable; will be null otherwise.</param>
        /// <returns>True if the type is nullable; False otherwise.</returns>
#endif
        internal virtual bool IsNullable(out TypeData underlyingType)
        {
            underlyingType = null;
            return(false);
        }
コード例 #20
0
 internal PointerTypeData(string name, MemberAccessibility accessibility, MemberFlags memberFlags, TypeKind typeKind, TypeData elementType)
     : base(name, accessibility, memberFlags, typeKind, elementType)
 {
 }
コード例 #21
0
 internal override bool IsArray(out int rank, out TypeData elementType)
 {
     rank        = this.ArrayRank;
     elementType = this.ElementType;
     return(true);
 }
コード例 #22
0
 internal TypedMemberDataBase(string name, MemberAccessibility accessibility, MemberFlags memberFlags, TypeData type, bool isTypeDynamic)
     : base(name, accessibility, memberFlags)
 {
     this.Type          = type;
     this.IsTypeDynamic = isTypeDynamic;
 }
コード例 #23
0
 internal ArrayTypeData(string name, MemberAccessibility accessibility, MemberFlags memberFlags, TypeKind typeKind, TypeData elementType, byte arrayRank)
     : base(name, accessibility, memberFlags, typeKind, elementType)
 {
     this.ArrayRank = arrayRank;
 }
コード例 #24
0
 internal FieldData(string name, Accessibility accessibility, MemberFlags memberFlags, TypeData type, bool isTypeDynamic, bool isReadOnly)
     : base(name, accessibility, memberFlags, type, isTypeDynamic) =>
コード例 #25
0
 internal MethodDataBase(string name, MemberAccessibility accessibility, MemberFlags memberFlags, TypeData type, bool isTypeDynamic, ParameterCollection parameters)
     : base(name, accessibility, memberFlags, type, isTypeDynamic)
 {
     this.Parameters = parameters;
 }