Пример #1
0
 private static bool AreSame(GenericInstanceType a, GenericInstanceType b)
 {
     if (a.GenericArguments.Count != b.GenericArguments.Count)
     {
         return(false);
     }
     for (int i = 0; i < a.GenericArguments.Count; i++)
     {
         if (!MetadataResolver.AreSame(a.GenericArguments[i], b.GenericArguments[i]))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #2
0
 private static bool AreSame(TypeSpecification a, TypeSpecification b)
 {
     if (!MetadataResolver.AreSame(a.ElementType, b.ElementType))
     {
         return(false);
     }
     if (a.IsGenericInstance)
     {
         return(MetadataResolver.AreSame((GenericInstanceType)a, (GenericInstanceType)b));
     }
     if (a.IsRequiredModifier || a.IsOptionalModifier)
     {
         return(MetadataResolver.AreSame((IModifierType)a, (IModifierType)b));
     }
     return(!a.IsArray || MetadataResolver.AreSame((ArrayType)a, (ArrayType)b));
 }
Пример #3
0
 private MethodDefinition GetMethod(TypeDefinition type, MethodReference reference)
 {
     while (type != null)
     {
         MethodDefinition method = MetadataResolver.GetMethod(type.Methods, reference);
         if (method != null)
         {
             return(method);
         }
         if (type.BaseType == null)
         {
             return(null);
         }
         type = this.Resolve(type.BaseType);
     }
     return(null);
 }
Пример #4
0
 private FieldDefinition GetField(TypeDefinition type, FieldReference reference)
 {
     while (type != null)
     {
         FieldDefinition field = MetadataResolver.GetField(type.Fields, reference);
         if (field != null)
         {
             return(field);
         }
         if (type.BaseType == null)
         {
             return(null);
         }
         type = this.Resolve(type.BaseType);
     }
     return(null);
 }
Пример #5
0
        public virtual TypeDefinition Resolve(TypeReference type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            type = type.GetElementType();
            IMetadataScope scope = type.Scope;

            if (scope == null)
            {
                return(null);
            }
            switch (scope.MetadataScopeType)
            {
            case MetadataScopeType.AssemblyNameReference:
            {
                AssemblyDefinition assemblyDefinition = this.assembly_resolver.Resolve((AssemblyNameReference)scope);
                if (assemblyDefinition == null)
                {
                    return(null);
                }
                return(MetadataResolver.GetType(assemblyDefinition.MainModule, type));
            }

            case MetadataScopeType.ModuleReference:
            {
                Collection <ModuleDefinition> modules = type.Module.Assembly.Modules;
                ModuleReference moduleReference       = (ModuleReference)scope;
                for (int i = 0; i < modules.Count; i++)
                {
                    ModuleDefinition moduleDefinition = modules[i];
                    if (moduleDefinition.Name == moduleReference.Name)
                    {
                        return(MetadataResolver.GetType(moduleDefinition, type));
                    }
                }
                break;
            }

            case MetadataScopeType.ModuleDefinition:
                return(MetadataResolver.GetType((ModuleDefinition)scope, type));
            }
            throw new NotSupportedException();
        }
Пример #6
0
 private static bool IsVarArgCallTo(MethodDefinition method, MethodReference reference)
 {
     if (method.Parameters.Count >= reference.Parameters.Count)
     {
         return(false);
     }
     if (reference.GetSentinelPosition() != method.Parameters.Count)
     {
         return(false);
     }
     for (int i = 0; i < method.Parameters.Count; i++)
     {
         if (!MetadataResolver.AreSame(method.Parameters[i].ParameterType, reference.Parameters[i].ParameterType))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #7
0
        private static bool AreSame(Collection <ParameterDefinition> a, Collection <ParameterDefinition> b)
        {
            int count = a.Count;

            if (count != b.Count)
            {
                return(false);
            }
            if (count == 0)
            {
                return(true);
            }
            for (int i = 0; i < count; i++)
            {
                if (!MetadataResolver.AreSame(a[i].ParameterType, b[i].ParameterType))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #8
0
        private static TypeDefinition GetType(ModuleDefinition module, TypeReference reference)
        {
            TypeDefinition typeDefinition = MetadataResolver.GetTypeDefinition(module, reference);

            if (typeDefinition != null)
            {
                return(typeDefinition);
            }
            if (!module.HasExportedTypes)
            {
                return(null);
            }
            Collection <ExportedType> exportedTypes = module.ExportedTypes;

            for (int i = 0; i < exportedTypes.Count; i++)
            {
                ExportedType exportedType = exportedTypes[i];
                if (!(exportedType.Name != reference.Name) && !(exportedType.Namespace != reference.Namespace))
                {
                    return(exportedType.Resolve());
                }
            }
            return(null);
        }
Пример #9
0
 private static bool AreSame(TypeReference a, TypeReference b)
 {
     if (object.ReferenceEquals(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));
     }
     return(!(a.Name != b.Name) && !(a.Namespace != b.Namespace) && MetadataResolver.AreSame(a.DeclaringType, b.DeclaringType));
 }
Пример #10
0
 private static bool AreSame(IModifierType a, IModifierType b)
 {
     return(MetadataResolver.AreSame(a.ModifierType, b.ModifierType));
 }
Пример #11
0
 public static MethodDefinition GetMethod(Collection <MethodDefinition> methods, MethodReference reference)
 {
     for (int i = 0; i < methods.Count; i++)
     {
         MethodDefinition methodDefinition = methods[i];
         if (!(methodDefinition.Name != reference.Name) && methodDefinition.HasGenericParameters == reference.HasGenericParameters && (!methodDefinition.HasGenericParameters || methodDefinition.GenericParameters.Count == reference.GenericParameters.Count) && MetadataResolver.AreSame(methodDefinition.ReturnType, reference.ReturnType) && methodDefinition.IsVarArg() == reference.IsVarArg())
         {
             if (methodDefinition.IsVarArg() && MetadataResolver.IsVarArgCallTo(methodDefinition, reference))
             {
                 return(methodDefinition);
             }
             if (methodDefinition.HasParameters == reference.HasParameters)
             {
                 if (!methodDefinition.HasParameters && !reference.HasParameters)
                 {
                     return(methodDefinition);
                 }
                 if (MetadataResolver.AreSame(methodDefinition.Parameters, reference.Parameters))
                 {
                     return(methodDefinition);
                 }
             }
         }
     }
     return(null);
 }