コード例 #1
0
ファイル: MetadataResolver.cs プロジェクト: xyz91/EasyAop
 private static bool AreSame(TypeReference a, TypeReference b)
 {
     if (a == b)
     {
         return(true);
     }
     if (a != null && b != null)
     {
         if (a.etype != b.etype)
         {
             return(false);
         }
         if (a.IsGenericParameter)
         {
             return(AreSame((GenericParameter)a, (GenericParameter)b));
         }
         if (a.IsTypeSpecification())
         {
             return(AreSame((TypeSpecification)a, (TypeSpecification)b));
         }
         if (!(a.Name != b.Name) && !(a.Namespace != b.Namespace))
         {
             return(AreSame(a.DeclaringType, b.DeclaringType));
         }
         return(false);
     }
     return(false);
 }
コード例 #2
0
 private static bool AreSame(TypeReference a, TypeReference b)
 {
     if (a == b)
     {
         return(true);
     }
     if (a == null || b == null)
     {
         return(false);
     }
     if (a.etype != b.etype)
     {
         return(false);
     }
     if (a.IsGenericParameter)
     {
         return(MetadataResolver.AreSame((GenericParameter)a, (GenericParameter)b));
     }
     if (a.IsTypeSpecification())
     {
         return(MetadataResolver.AreSame((TypeSpecification)a, (TypeSpecification)b));
     }
     if (a.Name != b.Name || a.Namespace != b.Namespace)
     {
         return(false);
     }
     return(MetadataResolver.AreSame(a.DeclaringType, b.DeclaringType));
 }
コード例 #3
0
        private static void AppendType(TypeReference type, StringBuilder name, bool fq_name, bool top_level)
        {
            TypeReference elementType   = type.GetElementType();
            TypeReference declaringType = elementType.DeclaringType;

            if (declaringType != null)
            {
                AppendType(declaringType, name, false, top_level);
                name.Append('+');
            }
            string @namespace = type.Namespace;

            if (!string.IsNullOrEmpty(@namespace))
            {
                AppendNamePart(@namespace, name);
                name.Append('.');
            }
            AppendNamePart(elementType.Name, name);
            if (fq_name)
            {
                if (type.IsTypeSpecification())
                {
                    AppendTypeSpecification((TypeSpecification)type, name);
                }
                if (RequiresFullyQualifiedName(type, top_level))
                {
                    name.Append(", ");
                    name.Append(GetScopeFullName(type));
                }
            }
        }
コード例 #4
0
        internal virtual TypeReference ImportType(TypeReference type, ImportGenericContext context)
        {
            if (type.IsTypeSpecification())
            {
                return(ImportTypeSpecification(type, context));
            }

            var reference = new TypeReference(
                type.Namespace,
                type.Name,
                module,
                ImportScope(type.Scope),
                type.IsValueType);

            MetadataSystem.TryProcessPrimitiveTypeReference(reference);

            if (type.IsNested)
            {
                reference.DeclaringType = ImportType(type.DeclaringType, context);
            }

            if (type.HasGenericParameters)
            {
                ImportGenericParameters(reference, type);
            }

            return(reference);
        }
コード例 #5
0
ファイル: Import.cs プロジェクト: maria2na/cecil
        public TypeReference ImportType(TypeReference type, Mono.Collections.Generic.Collection <IGenericParameterProvider> context)
        {
            if (type.IsTypeSpecification())
            {
                return(ImportTypeSpecification(type, context));
            }

            var reference = new TypeReference(
                type.Namespace,
                type.Name,
                module,
                ImportScope(type.Scope),
                type.IsValueType);

            MetadataSystem.TryProcessPrimitiveTypeReference(reference);

            if (type.IsNested)
            {
                reference.DeclaringType = ImportType(type.DeclaringType, context);
            }

            if (type.HasGenericParameters)
            {
                ImportGenericParameters(reference, type);
            }

            return(reference);
        }
コード例 #6
0
ファイル: Import.cs プロジェクト: xuan2261/DotNetPatcher
        public TypeReference ImportType(TypeReference type, IGenericContext context)
        {
            if (type.IsTypeSpecification())
            {
                return(ImportTypeSpecification(type, context));
            }

            var reference = new TypeReference(
                type.Namespace,
                type.Name,
                module,
                ImportScope(type.Scope),
                type.IsValueType);

            TypeDefinition typeDef = type.Resolve();

            if (typeDef != null)
            {
                reference.IsValueType = typeDef.IsValueType;
            }

            MetadataSystem.TryProcessPrimitiveType(reference);

            if (type.IsNested)
            {
                reference.DeclaringType = ImportType(type.DeclaringType, context);
            }

            if (type.HasGenericParameters)
            {
                ImportGenericParameters(reference, type);
            }

            return(reference);
        }
コード例 #7
0
ファイル: Import.cs プロジェクト: iskiselev/cecil
        TypeReference ImportType(TypeReference type, ImportGenericContext context)
        {
            if (type.IsTypeSpecification())
            {
                return(ImportTypeSpecification(type, context));
            }

            var reference = default(TypeReference);
            var key       = TypeRefKey.From(type);

            if (cache.TryGetValue(key, out reference))
            {
                // Cecil only fills TypeRef GenericParameters if used ( bug ?)
                // Now that we cache them, we need to make sure the cached version has all of the needed ones
                if (type.HasGenericParameters && reference.GenericParameters.Count != type.GenericParameters.Count)
                {
                    for (int i = reference.GenericParameters.Count - 1; i < type.GenericParameters.Count; i++)
                    {
                        reference.GenericParameters.Add(new GenericParameter(reference));
                    }
                }
                return(reference);
            }

            reference = new TypeReference(
                type.Namespace,
                type.Name,
                module,
                ImportScope(type.Scope),
                type.IsValueType);

            MetadataSystem.TryProcessPrimitiveTypeReference(reference);

            if (type.IsNested)
            {
                reference.DeclaringType = ImportType(type.DeclaringType, context);
            }

            if (type.HasGenericParameters)
            {
                ImportGenericParameters(reference, type);
            }

            cache.Add(key, reference);

            return(reference);
        }
コード例 #8
0
        public TypeReference ImportType(TypeReference type, ImportGenericContext context)
        {
            if (type.IsTypeSpecification())
            {
                return(this.ImportTypeSpecification(type, context));
            }
            TypeReference typeReference = new TypeReference(type.Namespace, type.Name, this.module, this.ImportScope(type.Scope), type.IsValueType);

            MetadataSystem.TryProcessPrimitiveTypeReference(typeReference);
            if (type.IsNested)
            {
                typeReference.DeclaringType = this.ImportType(type.DeclaringType, context);
            }
            if (type.HasGenericParameters)
            {
                MetadataImporter.ImportGenericParameters(typeReference, type);
            }
            return(typeReference);
        }
コード例 #9
0
ファイル: MetadataResolver.cs プロジェクト: tris2481/ILSpy
        static bool AreSame(TypeReference a, TypeReference b)
        {
            if (a.etype != b.etype)
            {
                return(false);
            }

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

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

            return(a.FullName == b.FullName);
        }
コード例 #10
0
        public static int GetHashCode(TypeReference type)
        {
            if (type == null)
            {
                return(0);
            }

            var hashCode =
                (type.DeclaringType == null ? 0 : type.DeclaringType.GetHashCode()) ^
                (type.Name.GetHashCode() << 3) ^
                (type.Namespace.GetHashCode() << 7) ^
                (type.etype.GetHashCode() << 11);

            if (type.IsGenericParameter)
            {
                hashCode ^= MetadataResolver.GetHashCodeHelper((GenericParameter)type);
            }
            else if (type.IsTypeSpecification())
            {
                hashCode ^= MetadataResolver.GetHashCodeHelper((TypeSpecification)type);
            }

            return(hashCode);
        }
コード例 #11
0
        static bool AreSame(TypeReference a, TypeReference b)
        {
            if (ReferenceEquals(a, b))
            {
                return(true);
            }

            if (a == null || b == null)
            {
                return(false);
            }

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

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

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

            if (a.Name != b.Name || a.Namespace != b.Namespace)
            {
                return(false);
            }

            //TODO: check scope

            return(AreSame(a.DeclaringType, b.DeclaringType));
        }
コード例 #12
0
        static void AppendType(TypeReference type, StringBuilder name, bool fq_name, bool top_level)
        {
            var declaring_type = type.DeclaringType;

            if (declaring_type != null)
            {
                AppendType(declaring_type, name, false, top_level);
                name.Append('+');
            }

            var @namespace = type.Namespace;

            if (!string.IsNullOrEmpty(@namespace))
            {
                name.Append(@namespace);
                name.Append('.');
            }

            name.Append(type.GetElementType().Name);

            if (!fq_name)
            {
                return;
            }

            if (type.IsTypeSpecification())
            {
                AppendTypeSpecification((TypeSpecification)type, name);
            }

            if (RequiresFullyQualifiedName(type, top_level))
            {
                name.Append(", ");
                name.Append(GetScopeFullName(type));
            }
        }
コード例 #13
0
ファイル: MetadataResolver.cs プロジェクト: peterwald/cecil
        static bool AreSame(TypeReference a, TypeReference b)
        {
            if (a.etype != b.etype)
                return false;

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

            if (a.IsTypeSpecification ())
                return AreSame ((TypeSpecification) a, (TypeSpecification) b);

            return a.FullName == b.FullName;
        }
コード例 #14
0
ファイル: Import.cs プロジェクト: MarkusSintonen/MNetInjector
        internal TypeReference ImportType(TypeReference type, ImportGenericContext context, 
            IImportMapper mapper)
        {
            if (type.IsTypeSpecification())
                return ImportTypeSpecification(type, context, mapper);

            var mapped = mapper.MapType(type);
            if (mapped == null)
                mapped = type;

            var reference = new TypeReference(
                mapped.Namespace,
                mapped.Name,
                module,
                ImportScope(mapper.MapMetadataScope(type.Scope)),
                mapped.IsValueType);

            MetadataSystem.TryProcessPrimitiveTypeReference(reference);

            if (mapped.IsNested)
                reference.DeclaringType = ImportType(mapped.DeclaringType, context, mapper);

            if (mapped.HasGenericParameters)
                ImportGenericParameters(reference, mapped);

            return reference;
        }
コード例 #15
0
ファイル: Import.cs プロジェクト: jeroldhaas/ContinuousTests
		public TypeReference ImportType (TypeReference type, IGenericContext context)
		{
			if (type.IsTypeSpecification ())
				return ImportTypeSpecification (type, context);

			var reference = new TypeReference (
				type.Namespace,
				type.Name,
				module,
				ImportScope (type.Scope),
				type.IsValueType);

			MetadataSystem.TryProcessPrimitiveType (reference);

			if (type.IsNested)
				reference.DeclaringType = ImportType (type.DeclaringType, context);

			if (type.HasGenericParameters)
				ImportGenericParameters (reference, type);

			return reference;
		}
コード例 #16
0
ファイル: MetadataResolver.cs プロジェクト: lousiCC/cecil
		static bool AreSame (TypeReference a, TypeReference b)
		{
			if (ReferenceEquals (a, b))
				return true;

			if (a == null || b == null)
				return false;

			if (a.etype != b.etype)
				return false;

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

			if (a.IsTypeSpecification ())
				return AreSame ((TypeSpecification) a, (TypeSpecification) b);

			if (a.Name != b.Name || a.Namespace != b.Namespace)
				return false;

			//TODO: check scope

			return AreSame (a.DeclaringType, b.DeclaringType);
		}
コード例 #17
0
 private static bool AreSame(TypeReference a, TypeReference b) =>
 (!ReferenceEquals(a, b) ? ((a != null) && ((b != null) && ((a.etype == b.etype) ? (!a.IsGenericParameter ? (!a.IsTypeSpecification() ? ((a.Name == b.Name) && ((a.Namespace == b.Namespace) && AreSame(a.DeclaringType, b.DeclaringType))) : AreSame((TypeSpecification)a, (TypeSpecification)b)) : AreSame((GenericParameter)a, (GenericParameter)b)) : false))) : true);
コード例 #18
0
        private TypeReference Import(TypeReference tdef, ModuleDefinition module, IInjector injector)
        {
            if (tdef.IsTypeSpecification())
                throw new NotImplementedException();

            var reference = new TypeReference(
                tdef.Namespace,
                tdef.Name,
                module,
                module.ImportScope(injector.MapMetadataScope(tdef.Scope)),
                tdef.IsValueType);

            MetadataSystem.TryProcessPrimitiveTypeReference(reference);

            if (tdef.IsNested)
                reference.DeclaringType = Import(tdef.DeclaringType, module, injector);

            if (tdef.HasGenericParameters)
                CecilHelpers.ImportGenericParameters(reference, tdef);

            return reference;
        }