Browse Source

Merge pull request #116 from ddobrev/master

Improvements to properties
pull/117/head
João Matos 12 years ago
parent
commit
f490b29bd6
  1. 20
      src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs
  2. 2
      tests/CSharpTemp/CSharpTemp.Tests.cs
  3. 10
      tests/CSharpTemp/CSharpTemp.cpp
  4. 3
      tests/CSharpTemp/CSharpTemp.h

20
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -94,14 +94,16 @@ namespace CppSharp.Passes
foreach (var getter in nonSetters.Where(m => m.Namespace == type)) foreach (var getter in nonSetters.Where(m => m.Namespace == type))
{ {
string name = GetPropertyName(getter.Name); string name = GetPropertyName(getter.Name);
if (string.Compare(name, afterSet, StringComparison.OrdinalIgnoreCase) == 0 && if (name.StartsWith("is"))
{
name = char.ToLowerInvariant(name[2]) + name.Substring(3);
}
if (name == afterSet &&
GetUnderlyingType(getter.OriginalReturnType).Equals( GetUnderlyingType(getter.OriginalReturnType).Equals(
GetUnderlyingType(setter.Parameters[0].QualifiedType)) && GetUnderlyingType(setter.Parameters[0].QualifiedType)) &&
!type.Methods.Any( !type.Methods.Any(m => m != getter && name == m.Name))
m =>
m != getter &&
string.Compare(name, m.Name, StringComparison.OrdinalIgnoreCase) == 0))
{ {
getter.Name = name;
GenerateProperty(getter.Namespace, getter, readOnly ? null : setter); GenerateProperty(getter.Namespace, getter, readOnly ? null : setter);
goto next; goto next;
} }
@ -149,9 +151,8 @@ namespace CppSharp.Passes
private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null) private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null)
{ {
Class type = (Class) context; Class type = (Class) context;
if (type.Properties.All( if (type.Properties.All(p => getter.Name != p.Name ||
p => string.Compare(getter.Name, p.Name, StringComparison.OrdinalIgnoreCase) != 0 || p.ExplicitInterfaceImpl != getter.ExplicitInterfaceImpl))
p.ExplicitInterfaceImpl != getter.ExplicitInterfaceImpl))
{ {
Property property = new Property(); Property property = new Property();
property.Name = GetPropertyName(getter.Name); property.Name = GetPropertyName(getter.Name);
@ -162,9 +163,6 @@ namespace CppSharp.Passes
Property baseVirtualProperty = type.GetRootBaseProperty(property); Property baseVirtualProperty = type.GetRootBaseProperty(property);
if (baseVirtualProperty.SetMethod == null) if (baseVirtualProperty.SetMethod == null)
setter = null; setter = null;
foreach (Method method in type.Methods.Where(m => m.Name == property.Name &&
m.Parameters.Any(p => p.Kind != ParameterKind.IndirectReturnType)))
method.Name = "get" + method.Name;
} }
property.GetMethod = getter; property.GetMethod = getter;
property.SetMethod = setter; property.SetMethod = setter;

2
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -77,5 +77,7 @@ public class CSharpTempTests
ComplexType complexType = new ComplexType(); ComplexType complexType = new ComplexType();
p.ComplexType = complexType; p.ComplexType = complexType;
Assert.That(p.ComplexType.Check(), Is.EqualTo(5)); Assert.That(p.ComplexType.Check(), Is.EqualTo(5));
Assert.That(p.Test, Is.True);
} }
} }

10
tests/CSharpTemp/CSharpTemp.cpp

@ -154,3 +154,13 @@ void P::parent(int i)
{ {
} }
bool P::isTest()
{
return true;
}
void P::setTest(bool value)
{
}

3
tests/CSharpTemp/CSharpTemp.h

@ -112,6 +112,9 @@ public:
virtual void parent(int i); virtual void parent(int i);
bool isTest();
void setTest(bool value);
private: private:
ComplexType m_complexType; ComplexType m_complexType;
}; };

Loading…
Cancel
Save