2
// ReducedExtensionMethod.cs
5
// Mike KrĆ¼ger <mkrueger@xamarin.com>
7
// Copyright (c) 2013 Xamarin Inc. (http://xamarin.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
using ICSharpCode.NRefactory.TypeSystem;
28
using System.Collections.Generic;
30
using ICSharpCode.NRefactory.TypeSystem.Implementation;
32
namespace ICSharpCode.NRefactory.CSharp
35
/// An invocated extension method hides the extension parameter in its parameter list.
36
/// It's used to hide the internals of extension method invocation in certain situation to simulate the
37
/// syntactic way of writing extension methods on semantic level.
39
public class ReducedExtensionMethod : IMethod
41
readonly IMethod baseMethod;
43
public ReducedExtensionMethod(IMethod baseMethod)
45
this.baseMethod = baseMethod;
48
public override bool Equals(object obj)
50
var other = obj as ReducedExtensionMethod;
53
return baseMethod.Equals(other.baseMethod);
56
public override int GetHashCode()
59
return baseMethod.GetHashCode() + 1;
63
public override string ToString()
65
return string.Format("[ReducedExtensionMethod: ReducedFrom={0}]", ReducedFrom);
68
#region IMember implementation
71
public sealed class ReducedExtensionMethodMemberReference : IMemberReference
73
readonly IMethod baseMethod;
75
public ReducedExtensionMethodMemberReference (IMethod baseMethod)
77
this.baseMethod = baseMethod;
80
#region IMemberReference implementation
81
public IMember Resolve(ITypeResolveContext context)
83
return new ReducedExtensionMethod ((IMethod)baseMethod.ToMemberReference ().Resolve (context));
86
public ITypeReference DeclaringTypeReference {
88
return baseMethod.ToMemberReference ().DeclaringTypeReference;
94
public IMemberReference ToMemberReference()
96
return new ReducedExtensionMethodMemberReference (baseMethod);
99
public IMember MemberDefinition {
101
return baseMethod.MemberDefinition;
105
public IUnresolvedMember UnresolvedMember {
107
return baseMethod.UnresolvedMember;
111
public IType ReturnType {
113
return baseMethod.ReturnType;
117
public System.Collections.Generic.IList<IMember> ImplementedInterfaceMembers {
119
return baseMethod.ImplementedInterfaceMembers;
123
public bool IsExplicitInterfaceImplementation {
125
return baseMethod.IsExplicitInterfaceImplementation;
129
public bool IsVirtual {
131
return baseMethod.IsVirtual;
135
public bool IsOverride {
137
return baseMethod.IsOverride;
141
public bool IsOverridable {
143
return baseMethod.IsOverridable;
147
public TypeParameterSubstitution Substitution {
149
return baseMethod.Substitution;
153
public IMethod Specialize(TypeParameterSubstitution substitution)
155
return new ReducedExtensionMethod((IMethod)baseMethod.Specialize(substitution));
158
IMember IMember.Specialize(TypeParameterSubstitution substitution)
160
return Specialize(substitution);
163
public bool IsParameterized {
164
get { return baseMethod.IsParameterized; }
169
#region IMethod implementation
171
public System.Collections.Generic.IList<IUnresolvedMethod> Parts {
173
return baseMethod.Parts;
177
public System.Collections.Generic.IList<IAttribute> ReturnTypeAttributes {
179
return baseMethod.ReturnTypeAttributes;
183
public System.Collections.Generic.IList<ITypeParameter> TypeParameters {
185
return baseMethod.TypeParameters;
189
public bool IsExtensionMethod {
195
public bool IsConstructor {
197
return baseMethod.IsConstructor;
201
public bool IsDestructor {
203
return baseMethod.IsDestructor;
207
public bool IsOperator {
209
return baseMethod.IsOperator;
213
public bool IsPartial {
215
return baseMethod.IsPartial;
219
public bool IsAsync {
221
return baseMethod.IsAsync;
225
public bool HasBody {
227
return baseMethod.HasBody;
231
public bool IsAccessor {
233
return baseMethod.IsAccessor;
237
public IMember AccessorOwner {
239
return baseMethod.AccessorOwner;
243
public IMethod ReducedFrom {
249
public IList<IType> TypeArguments {
251
return baseMethod.TypeArguments;
256
#region IParameterizedMember implementation
257
List<IParameter> parameters;
258
public System.Collections.Generic.IList<IParameter> Parameters {
260
if (parameters == null)
261
parameters = new List<IParameter> (baseMethod.Parameters.Skip (1));
268
#region IEntity implementation
270
public EntityType EntityType {
272
return baseMethod.EntityType;
276
public DomRegion Region {
278
return baseMethod.Region;
282
public DomRegion BodyRegion {
284
return baseMethod.BodyRegion;
288
public ITypeDefinition DeclaringTypeDefinition {
290
return baseMethod.DeclaringTypeDefinition;
294
public IType DeclaringType {
296
return baseMethod.DeclaringType;
300
public IAssembly ParentAssembly {
302
return baseMethod.ParentAssembly;
306
public System.Collections.Generic.IList<IAttribute> Attributes {
308
return baseMethod.Attributes;
312
public ICSharpCode.NRefactory.Documentation.DocumentationComment Documentation {
314
return baseMethod.Documentation;
318
public bool IsStatic {
324
public bool IsAbstract {
326
return baseMethod.IsAbstract;
330
public bool IsSealed {
332
return baseMethod.IsSealed;
336
public bool IsShadowing {
338
return baseMethod.IsShadowing;
342
public bool IsSynthetic {
344
return baseMethod.IsSynthetic;
350
#region IHasAccessibility implementation
352
public Accessibility Accessibility {
354
return baseMethod.Accessibility;
358
public bool IsPrivate {
360
return baseMethod.IsPrivate;
364
public bool IsPublic {
366
return baseMethod.IsPublic;
370
public bool IsProtected {
372
return baseMethod.IsProtected;
376
public bool IsInternal {
378
return baseMethod.IsInternal;
382
public bool IsProtectedOrInternal {
384
return baseMethod.IsProtectedOrInternal;
388
public bool IsProtectedAndInternal {
390
return baseMethod.IsProtectedAndInternal;
396
#region INamedElement implementation
398
public string FullName {
400
return baseMethod.FullName;
406
return baseMethod.Name;
410
public string ReflectionName {
412
return baseMethod.ReflectionName;
416
public string Namespace {
418
return baseMethod.Namespace;
424
#region ICompilationProvider implementation
426
public ICompilation Compilation {
428
return baseMethod.Compilation;