Exemplo n.º 1
0
        internal bool AreSame(TypeReference a, TypeReference b)
        {
            if (a == b)
            {
                return(true);
            }
            if (a == null || b == null)
            {
                return(false);
            }
            a = _repack.GetMergedTypeFromTypeRef(a) ?? a;
            b = _repack.GetMergedTypeFromTypeRef(b) ?? b;

            if (a.MetadataType != b.MetadataType)
            {
                return(false);
            }

            if (a.IsGenericParameter)
            {
                return(AreSame((GenericParameter)a, (GenericParameter)b));
            }

            if (a is TypeSpecification)
            {
                return(AreSame((TypeSpecification)a, (TypeSpecification)b));
            }

            return(a.FullName == b.FullName);
        }
Exemplo n.º 2
0
        public TypeReference Import(TypeReference reference, IGenericParameterProvider context)
        {
            TypeDefinition type = _repackContext.GetMergedTypeFromTypeRef(reference);

            if (type != null)
            {
                return(type);
            }

            _repackContext.PlatformFixer.FixPlatformVersion(reference);
            try
            {
                if (context == null)
                {
                    // we come here when importing types used for assembly-level custom attributes
                    return(_repackContext.TargetAssemblyMainModule.ImportReference(reference));
                }
                return(_repackContext.TargetAssemblyMainModule.ImportReference(reference, context));
            }
            catch (ArgumentOutOfRangeException) // working around a bug in Cecil
            {
                _logger.Error("Problem adding reference: " + reference.FullName);
                throw;
            }
        }
Exemplo n.º 3
0
        private TypeReference Fix(TypeReference type)
        {
            if (type == null || type.IsDefinition)
            {
                return(type);
            }

            if (type.IsGenericParameter)
            {
                var genPar = (GenericParameter)type;
                if (!fixedGenericParameters.Contains(genPar))
                {
                    fixedGenericParameters.Add(genPar);
#if !NETSTANDARD
                    FixReferences(genPar.Constraints);
#else
                    FixReferences(genPar);
#endif
                    FixReferences(genPar.CustomAttributes);
                }
                return(type);
            }

            if (type is TypeSpecification)
            {
                return(Fix((TypeSpecification)type));
            }

            type = _repackContext.GetExportedTypeFromTypeRef(type);

            var t2 = _repackContext.GetMergedTypeFromTypeRef(type);
            if (t2 != null)
            {
                return(t2);
            }

            if (type.IsNested)
            {
                type.DeclaringType = Fix(type.DeclaringType);
            }

            if (type.DeclaringType is TypeDefinition)
            {
                return(((TypeDefinition)type.DeclaringType).NestedTypes.FirstOrDefault(x => x.FullName == type.FullName));
            }

            return(type);
        }