1 | // Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team |
---|
2 | // |
---|
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: |
---|
8 | // |
---|
9 | // The above copyright notice and this permission notice shall be included in all copies or |
---|
10 | // substantial portions of the Software. |
---|
11 | // |
---|
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. |
---|
18 | |
---|
19 | using System; |
---|
20 | using System.Collections.Generic; |
---|
21 | using System.Diagnostics.Contracts; |
---|
22 | using System.Linq; |
---|
23 | |
---|
24 | namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
---|
25 | { |
---|
26 | /// <summary> |
---|
27 | /// Default implementation for IType interface. |
---|
28 | /// </summary> |
---|
29 | [Serializable] |
---|
30 | public abstract class AbstractType : IType |
---|
31 | { |
---|
32 | public virtual string FullName { |
---|
33 | get { |
---|
34 | string ns = this.Namespace; |
---|
35 | string name = this.Name; |
---|
36 | if (string.IsNullOrEmpty(ns)) { |
---|
37 | return name; |
---|
38 | } else { |
---|
39 | return ns + "." + name; |
---|
40 | } |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | public abstract string Name { get; } |
---|
45 | |
---|
46 | public virtual string Namespace { |
---|
47 | get { return string.Empty; } |
---|
48 | } |
---|
49 | |
---|
50 | public virtual string ReflectionName { |
---|
51 | get { return this.FullName; } |
---|
52 | } |
---|
53 | |
---|
54 | public abstract bool? IsReferenceType { get; } |
---|
55 | |
---|
56 | public abstract TypeKind Kind { get; } |
---|
57 | |
---|
58 | public virtual int TypeParameterCount { |
---|
59 | get { return 0; } |
---|
60 | } |
---|
61 | |
---|
62 | readonly static IList<IType> emptyTypeArguments = new IType[0]; |
---|
63 | public virtual IList<IType> TypeArguments { |
---|
64 | get { return emptyTypeArguments; } |
---|
65 | } |
---|
66 | |
---|
67 | public virtual IType DeclaringType { |
---|
68 | get { return null; } |
---|
69 | } |
---|
70 | |
---|
71 | public virtual bool IsParameterized { |
---|
72 | get { return false; } |
---|
73 | } |
---|
74 | |
---|
75 | public virtual ITypeDefinition GetDefinition() |
---|
76 | { |
---|
77 | return null; |
---|
78 | } |
---|
79 | |
---|
80 | public virtual IEnumerable<IType> DirectBaseTypes { |
---|
81 | get { return EmptyList<IType>.Instance; } |
---|
82 | } |
---|
83 | |
---|
84 | public abstract ITypeReference ToTypeReference(); |
---|
85 | |
---|
86 | public virtual IEnumerable<IType> GetNestedTypes(Predicate<ITypeDefinition> filter = null, GetMemberOptions options = GetMemberOptions.None) |
---|
87 | { |
---|
88 | return EmptyList<IType>.Instance; |
---|
89 | } |
---|
90 | |
---|
91 | public virtual IEnumerable<IType> GetNestedTypes(IList<IType> typeArguments, Predicate<ITypeDefinition> filter = null, GetMemberOptions options = GetMemberOptions.None) |
---|
92 | { |
---|
93 | return EmptyList<IType>.Instance; |
---|
94 | } |
---|
95 | |
---|
96 | public virtual IEnumerable<IMethod> GetMethods(Predicate<IUnresolvedMethod> filter = null, GetMemberOptions options = GetMemberOptions.None) |
---|
97 | { |
---|
98 | return EmptyList<IMethod>.Instance; |
---|
99 | } |
---|
100 | |
---|
101 | public virtual IEnumerable<IMethod> GetMethods(IList<IType> typeArguments, Predicate<IUnresolvedMethod> filter = null, GetMemberOptions options = GetMemberOptions.None) |
---|
102 | { |
---|
103 | return EmptyList<IMethod>.Instance; |
---|
104 | } |
---|
105 | |
---|
106 | public virtual IEnumerable<IMethod> GetConstructors(Predicate<IUnresolvedMethod> filter = null, GetMemberOptions options = GetMemberOptions.IgnoreInheritedMembers) |
---|
107 | { |
---|
108 | return EmptyList<IMethod>.Instance; |
---|
109 | } |
---|
110 | |
---|
111 | public virtual IEnumerable<IProperty> GetProperties(Predicate<IUnresolvedProperty> filter = null, GetMemberOptions options = GetMemberOptions.None) |
---|
112 | { |
---|
113 | return EmptyList<IProperty>.Instance; |
---|
114 | } |
---|
115 | |
---|
116 | public virtual IEnumerable<IField> GetFields(Predicate<IUnresolvedField> filter = null, GetMemberOptions options = GetMemberOptions.None) |
---|
117 | { |
---|
118 | return EmptyList<IField>.Instance; |
---|
119 | } |
---|
120 | |
---|
121 | public virtual IEnumerable<IEvent> GetEvents(Predicate<IUnresolvedEvent> filter = null, GetMemberOptions options = GetMemberOptions.None) |
---|
122 | { |
---|
123 | return EmptyList<IEvent>.Instance; |
---|
124 | } |
---|
125 | |
---|
126 | public virtual IEnumerable<IMember> GetMembers(Predicate<IUnresolvedMember> filter = null, GetMemberOptions options = GetMemberOptions.None) |
---|
127 | { |
---|
128 | IEnumerable<IMember> members = GetMethods(filter, options); |
---|
129 | return members |
---|
130 | .Concat(GetProperties(filter, options)) |
---|
131 | .Concat(GetFields(filter, options)) |
---|
132 | .Concat(GetEvents(filter, options)); |
---|
133 | } |
---|
134 | |
---|
135 | public virtual IEnumerable<IMethod> GetAccessors(Predicate<IUnresolvedMethod> filter = null, GetMemberOptions options = GetMemberOptions.None) |
---|
136 | { |
---|
137 | return EmptyList<IMethod>.Instance; |
---|
138 | } |
---|
139 | |
---|
140 | public TypeParameterSubstitution GetSubstitution() |
---|
141 | { |
---|
142 | return TypeParameterSubstitution.Identity; |
---|
143 | } |
---|
144 | |
---|
145 | public TypeParameterSubstitution GetSubstitution(IList<IType> methodTypeArguments) |
---|
146 | { |
---|
147 | return TypeParameterSubstitution.Identity; |
---|
148 | } |
---|
149 | |
---|
150 | public override sealed bool Equals(object obj) |
---|
151 | { |
---|
152 | return Equals(obj as IType); |
---|
153 | } |
---|
154 | |
---|
155 | public override int GetHashCode() |
---|
156 | { |
---|
157 | return base.GetHashCode(); |
---|
158 | } |
---|
159 | |
---|
160 | public virtual bool Equals(IType other) |
---|
161 | { |
---|
162 | return this == other; // use reference equality by default |
---|
163 | } |
---|
164 | |
---|
165 | public override string ToString() |
---|
166 | { |
---|
167 | return this.ReflectionName; |
---|
168 | } |
---|
169 | |
---|
170 | public virtual IType AcceptVisitor(TypeVisitor visitor) |
---|
171 | { |
---|
172 | return visitor.VisitOtherType(this); |
---|
173 | } |
---|
174 | |
---|
175 | public virtual IType VisitChildren(TypeVisitor visitor) |
---|
176 | { |
---|
177 | return this; |
---|
178 | } |
---|
179 | } |
---|
180 | } |
---|