Browse Source

Fixed the generated C# when a field is named after a property to be generated.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/847/merge
Dimitar Dobrev 8 years ago
parent
commit
cfc6da4600
  1. 9
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  2. 3
      tests/Common/Common.h

9
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -77,8 +77,7 @@ namespace CppSharp.Passes @@ -77,8 +77,7 @@ namespace CppSharp.Passes
char.ToUpperInvariant(@event.Name[0]), @event.Name.Substring(1));
Diagnostics.Debug("Event {0}::{1} renamed to {2}", @event.Namespace.Name, oldName, @event.Name);
}
getter.Name = name;
GenerateProperty(getter.Namespace, getter, readOnly ? null : setter);
GenerateProperty(name, getter.Namespace, getter, readOnly ? null : setter);
goto next;
}
}
@ -132,9 +131,13 @@ namespace CppSharp.Passes @@ -132,9 +131,13 @@ namespace CppSharp.Passes
}
private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null)
{
GenerateProperty(GetPropertyName(getter.Name), context, getter, setter);
}
private static void GenerateProperty(string name, DeclarationContext context, Method getter, Method setter)
{
var type = (Class) context;
var name = GetPropertyName(getter.Name);
if (type.Properties.Any(p => p.Name == name &&
p.ExplicitInterfaceImpl == getter.ExplicitInterfaceImpl))
return;

3
tests/Common/Common.h

@ -531,11 +531,14 @@ DLL_API int Function() @@ -531,11 +531,14 @@ DLL_API int Function()
// Tests properties
struct DLL_API TestProperties
{
public:
TestProperties();
int Field;
int getFieldValue();
void setFieldValue(int Value);
private:
int FieldValue;
};
TestProperties::TestProperties() : Field(0) {}

Loading…
Cancel
Save