diff --git a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs index c6b533fe58..cea7a115f1 100644 --- a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs +++ b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs @@ -87,9 +87,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.TestCase public int PropertyWithProtectedSetter { get; protected set; } public object PropertyWithPrivateSetter { get; private set; } - + public object PropertyWithoutSetter { get { return null; } } - + + public object PropertyWithPrivateGetter { private get; set; } + public string this[int index] { get { return "Test"; } set {} } } diff --git a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs index f1b8c977bf..ae0c247b6c 100644 --- a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs +++ b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs @@ -336,6 +336,19 @@ namespace ICSharpCode.NRefactory.TypeSystem Assert.AreEqual(Accessibility.Private, p.Setter.Accessibility); Assert.IsTrue(p.Getter.HasBody); } + + [Test] + public void PropertyWithPrivateGetter() + { + var testClass = GetTypeDefinition(typeof(PropertyTest)); + IProperty p = testClass.Properties.Single(pr => pr.Name == "PropertyWithPrivateGetter"); + Assert.IsTrue(p.CanGet); + Assert.IsTrue(p.CanSet); + Assert.AreEqual(Accessibility.Public, p.Accessibility); + Assert.AreEqual(Accessibility.Private, p.Getter.Accessibility); + Assert.AreEqual(Accessibility.Public, p.Setter.Accessibility); + Assert.IsTrue(p.Getter.HasBody); + } [Test] public void PropertyWithoutSetter() diff --git a/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs b/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs index c53d269979..7b98deb240 100644 --- a/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs +++ b/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team +// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team // // Permission is hereby granted, free of charge, to any person obtaining a copy of this // software and associated documentation files (the "Software"), to deal in the Software @@ -2198,6 +2198,30 @@ namespace ICSharpCode.NRefactory.TypeSystem #region Read Property + Accessibility MergePropertyAccessibility (Accessibility left, Accessibility right) + { + if (left == Accessibility.Public || right == Accessibility.Public) + return Accessibility.Public; + + if (left == Accessibility.ProtectedOrInternal || right == Accessibility.ProtectedOrInternal) + return Accessibility.ProtectedOrInternal; + + if (left == Accessibility.Protected && right == Accessibility.Internal || + left == Accessibility.Internal && right == Accessibility.Protected) + return Accessibility.ProtectedOrInternal; + + if (left == Accessibility.Protected || right == Accessibility.Protected) + return Accessibility.Protected; + + if (left == Accessibility.Internal || right == Accessibility.Internal) + return Accessibility.Internal; + + if (left == Accessibility.ProtectedAndInternal || right == Accessibility.ProtectedAndInternal) + return Accessibility.ProtectedAndInternal; + + return left; + } + [CLSCompliant(false)] public IUnresolvedProperty ReadProperty(PropertyDefinition property, IUnresolvedTypeDefinition parentType, EntityType propertyType = EntityType.Property) { @@ -2208,6 +2232,9 @@ namespace ICSharpCode.NRefactory.TypeSystem DefaultUnresolvedProperty p = new DefaultUnresolvedProperty(parentType, property.Name); p.EntityType = propertyType; TranslateModifiers(property.GetMethod ?? property.SetMethod, p); + if (property.GetMethod != null && property.SetMethod != null) + p.Accessibility = MergePropertyAccessibility (GetAccessibility (property.GetMethod.Attributes), GetAccessibility (property.SetMethod.Attributes)); + p.ReturnType = ReadTypeReference(property.PropertyType, typeAttributes: property); p.Getter = ReadMethod(property.GetMethod, parentType, EntityType.Accessor, p);