~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/CecilTypeResolver.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
using System;
30
30
using System.Collections;
 
31
using System.Collections.Generic;
31
32
 
32
33
using Mono.Cecil;
33
34
 
51
52
                        AssemblyDefinition asm = (AssemblyDefinition) _assemblies [name.Name];
52
53
                        if (asm == null) {
53
54
                                asm = base.Resolve (name);
54
 
                                asm.Resolver = this;
55
55
                                _assemblies [name.Name] = asm;
56
56
                        }
57
57
 
60
60
 
61
61
                public TypeDefinition Resolve (TypeReference type)
62
62
                {
63
 
                        type = type.GetOriginalType ();
 
63
                        type = type.GetElementType ();
64
64
 
65
65
                        if (type is TypeDefinition)
66
66
                                return (TypeDefinition) type;
68
68
                        AssemblyNameReference reference = type.Scope as AssemblyNameReference;
69
69
                        if (reference != null) {
70
70
                                AssemblyDefinition assembly = Resolve (reference);
71
 
                                return assembly.MainModule.Types [type.FullName];
 
71
                                return assembly.MainModule.GetType (type.FullName);
72
72
                        }
73
73
 
74
74
                        ModuleDefinition module = type.Scope as ModuleDefinition;
75
75
                        if (module != null)
76
 
                                return module.Types [type.FullName];
 
76
                                return module.GetType (type.FullName);
77
77
 
78
78
                        throw new NotImplementedException ();
79
79
                }
102
102
                public MethodDefinition Resolve (MethodReference method)
103
103
                {
104
104
                        TypeDefinition type = Resolve (method.DeclaringType);
105
 
                        method = method.GetOriginalMethod ();
106
 
                        if (method.Name == MethodDefinition.Cctor || method.Name == MethodDefinition.Ctor)
107
 
                                return GetMethod (type.Constructors, method);
108
 
                        else
109
 
                                return GetMethod (type, method);
 
105
                        method = method.GetElementMethod ();
 
106
                        return GetMethod (type, method);
110
107
                }
111
108
 
112
109
                MethodDefinition GetMethod (TypeDefinition type, MethodReference reference)
128
125
                                if (meth.Name != reference.Name)
129
126
                                        continue;
130
127
 
131
 
                                if (!AreSame (meth.ReturnType.ReturnType, reference.ReturnType.ReturnType))
 
128
                                if (!AreSame (meth.ReturnType, reference.ReturnType))
132
129
                                        continue;
133
130
 
134
131
                                if (!AreSame (meth.Parameters, reference.Parameters))
140
137
                        return null;
141
138
                }
142
139
 
143
 
                static bool AreSame (ParameterDefinitionCollection a, ParameterDefinitionCollection b)
 
140
                static bool AreSame (IList<ParameterDefinition> a, IList<ParameterDefinition> b)
144
141
                {
145
142
                        if (a.Count != b.Count)
146
143
                                return false;
177
174
 
178
175
                        return a.FullName == b.FullName;
179
176
                }
180
 
 
181
 
                public void CacheAssembly (AssemblyDefinition assembly)
182
 
                {
183
 
                        _assemblies [assembly.Name.FullName] = assembly;
184
 
                        assembly.Resolver = this;
185
 
                }
186
177
        }
187
178
}