Permalink
Browse files

Generated properties from <type> get()/void get(<type>) pairs.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Aug 20, 2017
1 parent 4d177b3 commit a056659d093e3f51d7cc664d90157a3756560fed
@@ -49,7 +49,13 @@ private void GenerateProperties(IEnumerable<Method> settersToUse, bool readOnly)
{
var type = (Class) setter.Namespace;
var firstWord = GetFirstWord(setter.Name);
var nameBuilder = new StringBuilder(setter.Name.Substring(firstWord.Length));
string property;
if ((firstWord == "set" || firstWord == "set_") &&
firstWord.Length < setter.Name.Length)
property = setter.Name.Substring(firstWord.Length);
else
property = setter.Name;
var nameBuilder = new StringBuilder(property);
if (char.IsLower(setter.Name[0]))
nameBuilder[0] = char.ToLowerInvariant(nameBuilder[0]);
string afterSet = nameBuilder.ToString();
@@ -241,9 +247,7 @@ private static string GetPropertyNameFromSetter(Method setter)
private void DistributeMethod(Method method)
{
var firstWord = GetFirstWord(method.Name);
if (Match(firstWord, new[] { "set" }) && method.Name.Length > firstWord.Length &&
method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void))
if (method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void))
{
if (method.Parameters.Count == 1)
setters.Add(method);
@@ -470,6 +470,9 @@ public void TestProperties()
Assert.That(prop.FieldValue, Is.EqualTo(20));
prop.FieldValue = 10;
Assert.That(prop.FieldValue, Is.EqualTo(10));
prop.GetterAndSetterWithTheSameName = 25;
Assert.That(prop.GetterAndSetterWithTheSameName, Is.EqualTo(25));
}
[Test]
@@ -489,7 +489,7 @@ std::string& HasStdString::getStdString()
return s;
}
TestProperties::TestProperties() : Field(0), _refToPrimitiveInSetter(0)
TestProperties::TestProperties() : Field(0), _refToPrimitiveInSetter(0), _getterAndSetterWithTheSameName(0)
{
}
@@ -522,6 +522,20 @@ void TestProperties::setRefToPrimitiveInSetter(const double& value)
_refToPrimitiveInSetter = value;
}
int TestProperties::getterAndSetterWithTheSameName()
{
return _getterAndSetterWithTheSameName;
}
void TestProperties::getterAndSetterWithTheSameName(int value)
{
_getterAndSetterWithTheSameName = value;
}
void TestProperties::set(int value)
{
}
HasOverridenSetter::HasOverridenSetter()
{
}
@@ -585,9 +585,15 @@ struct DLL_API TestProperties
double refToPrimitiveInSetter() const;
void setRefToPrimitiveInSetter(const double& value);
int getterAndSetterWithTheSameName();
void getterAndSetterWithTheSameName(int value);
void set(int value);
private:
int FieldValue;
double _refToPrimitiveInSetter;
int _getterAndSetterWithTheSameName;
};
class DLL_API HasOverridenSetter : public TestProperties

0 comments on commit a056659

Please sign in to comment.