Browse Source

Fixed bug in cecil loader.

pull/45/merge
Mike Krüger 12 years ago
parent
commit
90c729419e
  1. 6
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs
  2. 13
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs
  3. 29
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

6
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs

@ -87,9 +87,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.TestCase @@ -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 {} }
}

13
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs

@ -336,6 +336,19 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -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()

29
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -1,4 +1,4 @@ @@ -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 @@ -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 @@ -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);

Loading…
Cancel
Save