PageRenderTime 65ms CodeModel.GetById 61ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultProperty.cs

http://github.com/icsharpcode/ILSpy
C# | 99 lines | 67 code | 12 blank | 20 comment | 11 complexity | f9a01cb9f9d3f2ce49f9ce54a14ff5ca MD5 | raw file
 1// Copyright (c) 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
19using System;
20using System.Collections.Generic;
21
22namespace ICSharpCode.NRefactory.TypeSystem.Implementation
23{
24	/// <summary>
25	/// Default implementation of <see cref="IProperty"/>.
26	/// </summary>
27	[Serializable]
28	public class DefaultProperty : AbstractMember, IProperty
29	{
30		IAccessor getter, setter;
31		IList<IParameter> parameters;
32		
33		protected override void FreezeInternal()
34		{
35			parameters = FreezeList(parameters);
36			if (getter != null) getter.Freeze();
37			if (setter != null) setter.Freeze();
38			base.FreezeInternal();
39		}
40		
41		public DefaultProperty(ITypeDefinition declaringTypeDefinition, string name)
42			: base(declaringTypeDefinition, name, EntityType.Property)
43		{
44		}
45		
46		protected DefaultProperty(IProperty p) : base(p)
47		{
48			this.getter = p.Getter;
49			this.setter = p.Setter;
50			this.parameters = CopyList(p.Parameters);
51		}
52		
53		public override void ApplyInterningProvider(IInterningProvider provider)
54		{
55			base.ApplyInterningProvider(provider);
56			if (provider != null) {
57				getter = provider.Intern(getter);
58				setter = provider.Intern(setter);
59				parameters = provider.InternList(parameters);
60			}
61		}
62		
63		public bool IsIndexer {
64			get { return this.EntityType == EntityType.Indexer; }
65		}
66		
67		public IList<IParameter> Parameters {
68			get {
69				if (parameters == null)
70					parameters = new List<IParameter>();
71				return parameters;
72			}
73		}
74		
75		public bool CanGet {
76			get { return getter != null; }
77		}
78		
79		public bool CanSet {
80			get { return setter != null; }
81		}
82		
83		public IAccessor Getter{
84			get { return getter; }
85			set {
86				CheckBeforeMutation();
87				getter = value;
88			}
89		}
90		
91		public IAccessor Setter {
92			get { return setter; }
93			set {
94				CheckBeforeMutation();
95				setter = value;
96			}
97		}
98	}
99}