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