From 45376532dc09e7e75f3b2c82c863ae79299026db Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Tue, 11 Oct 2016 17:18:38 +0100 Subject: [PATCH] Implemented initial support for class properties. --- binder/Generators/AstGenerator.cs | 20 ++++++++++++++++---- binder/Generators/C/CGenerator.cs | 2 +- tests/Basic/Basic.Tests.cpp | 9 +++++++++ tests/Basic/Basic.cs | 6 ++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/binder/Generators/AstGenerator.cs b/binder/Generators/AstGenerator.cs index e39ad35..5dfe7ef 100644 --- a/binder/Generators/AstGenerator.cs +++ b/binder/Generators/AstGenerator.cs @@ -151,8 +151,8 @@ namespace MonoManagedToNative.Generators foreach (var property in type.DeclaredProperties) { - //var decl = VisitProperty(property); - //@class.Declarations.Add(decl); + var decl = VisitProperty(property, @class); + @class.Declarations.Add(decl); } foreach (var decl in @class.Declarations) @@ -510,9 +510,21 @@ namespace MonoManagedToNative.Generators throw new NotImplementedException(); } - public Property VisitProperty(PropertyInfo @property) + public Property VisitProperty(PropertyInfo propertyInfo, Class @class) { - throw new NotImplementedException(); + var property = new Property() + { + Name = UnmangleTypeName(propertyInfo.Name), + QualifiedType = VisitType(propertyInfo.PropertyType), + }; + + if (propertyInfo.GetMethod != null) + property.GetMethod = VisitMethod(propertyInfo.GetMethod, @class); + + if (propertyInfo.SetMethod != null) + property.SetMethod = VisitMethod(propertyInfo.SetMethod, @class); + + return property; } } } diff --git a/binder/Generators/C/CGenerator.cs b/binder/Generators/C/CGenerator.cs index c920440..e02d9ef 100644 --- a/binder/Generators/C/CGenerator.cs +++ b/binder/Generators/C/CGenerator.cs @@ -236,7 +236,7 @@ namespace MonoManagedToNative.Generators public virtual bool VisitProperty(Property property) { - throw new NotImplementedException(); + return true; } public virtual bool VisitTemplateParameterDecl(TypeTemplateParameter templateParameter) diff --git a/tests/Basic/Basic.Tests.cpp b/tests/Basic/Basic.Tests.cpp index 3e85c77..9948677 100644 --- a/tests/Basic/Basic.Tests.cpp +++ b/tests/Basic/Basic.Tests.cpp @@ -46,6 +46,15 @@ TEST_CASE("BuiltinTypes", "[BuiltinTypes]") { REQUIRE(strcmp(RefStr->str, "Mono") == 0); } +TEST_CASE("ClassTypes", "[ClassTypes]") { + ClassProperties* prop = ClassProperties_new(); + REQUIRE(ClassProperties_get_Int(prop) == 0); + ClassProperties_set_Int(prop, 10); + REQUIRE(ClassProperties_get_Int(prop) == 10); + + REQUIRE(ClassProperties_get_ReadOnlyInt(prop) == 0); +} + TEST_CASE("StaticTypes", "[StaticTypes]") { REQUIRE(NonStaticClass_StaticMethod() == 0); REQUIRE(StaticClass_StaticMethod() == 0); diff --git a/tests/Basic/Basic.cs b/tests/Basic/Basic.cs index 238938c..61c53f3 100644 --- a/tests/Basic/Basic.cs +++ b/tests/Basic/Basic.cs @@ -83,6 +83,12 @@ public static class EnumTypes #region Classes +public class ClassProperties +{ + public int Int { get; set; } + public int ReadOnlyInt { get; } +} + public class NonStaticClass { public static int StaticMethod() { return 0; }