1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
// software and associated documentation files (the "Software"), to deal in the Software
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
// to whom the Software is furnished to do so, subject to the following conditions:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17
// DEALINGS IN THE SOFTWARE.
20
using System.Collections.Generic;
21
using System.Globalization;
24
using ICSharpCode.NRefactory.TypeSystem;
26
namespace ICSharpCode.NRefactory.Semantics
29
/// Represents the result of a member invocation.
31
public class MemberResolveResult : ResolveResult
33
readonly IMember member;
34
readonly bool isConstant;
35
readonly object constantValue;
36
readonly ResolveResult targetResult;
37
readonly bool isVirtualCall;
39
public MemberResolveResult(ResolveResult targetResult, IMember member)
40
: base(member.EntityType == EntityType.Constructor ? member.DeclaringType : member.ReturnType)
42
this.targetResult = targetResult;
44
var thisRR = targetResult as ThisResolveResult;
45
this.isVirtualCall = member.IsOverridable && !(thisRR != null && thisRR.CausesNonVirtualInvocation);
47
IField field = member as IField;
49
isConstant = field.IsConst;
51
constantValue = field.ConstantValue;
55
public MemberResolveResult(ResolveResult targetResult, IMember member, bool isVirtualCall)
56
: base(member.EntityType == EntityType.Constructor ? member.DeclaringType : member.ReturnType)
58
this.targetResult = targetResult;
60
this.isVirtualCall = isVirtualCall;
61
IField field = member as IField;
63
isConstant = field.IsConst;
65
constantValue = field.ConstantValue;
69
public MemberResolveResult(ResolveResult targetResult, IMember member, IType returnType, bool isConstant, object constantValue)
72
this.targetResult = targetResult;
74
this.isConstant = isConstant;
75
this.constantValue = constantValue;
78
public ResolveResult TargetResult {
79
get { return targetResult; }
84
/// This property never returns null.
86
public IMember Member {
87
get { return member; }
91
/// Gets whether this MemberResolveResult is a virtual call.
93
public bool IsVirtualCall {
94
get { return isVirtualCall; }
97
public override bool IsCompileTimeConstant {
98
get { return isConstant; }
101
public override object ConstantValue {
102
get { return constantValue; }
105
public override IEnumerable<ResolveResult> GetChildResults()
107
if (targetResult != null)
108
return new[] { targetResult };
110
return Enumerable.Empty<ResolveResult>();
113
public override string ToString()
115
return string.Format(CultureInfo.InvariantCulture, "[{0} {1}]", GetType().Name, member);
118
public override DomRegion GetDefinitionRegion()
120
return member.Region;