Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reworked property handling to check if each property getter/setter ca…

…n be generated.

Fixes a bug where we tried to generate a setter for a const field.
  • Loading branch information...
commit 23301605ac71cf734d5eaff5b0d8ce525da2f836 1 parent 26b6f6d
@tritao authored
View
17 src/AST/Property.cs
@@ -16,6 +16,23 @@ public Type Type
public Method SetMethod { get; set; }
+ public bool HasGetter
+ {
+ get
+ {
+ return (GetMethod != null) || (Field != null);
+ }
+ }
+
+ public bool HasSetter
+ {
+ get
+ {
+ return (SetMethod != null) ||
+ (Field != null && !Field.QualifiedType.Qualifiers.IsConst);
+ }
+ }
+
// The field that should be get and set by this property
public Field Field { get; set; }
View
4 src/Generator/Generators/CLI/CLIHeadersTemplate.cs
@@ -477,9 +477,7 @@ public void GenerateClassProperties(Class @class)
if (prop.Ignore) continue;
GenerateDeclarationCommon(prop);
- var isGetter = prop.GetMethod != null || prop.Field != null;
- var isSetter = prop.SetMethod != null || prop.Field != null;
- GenerateProperty(prop, isGetter, isSetter);
+ GenerateProperty(prop, prop.HasGetter, prop.HasSetter);
}
PopIndent();
}
View
18 src/Generator/Generators/CLI/CLISourcesTemplate.cs
@@ -240,13 +240,23 @@ private void GenerateProperty(Property property)
if (property.Field != null)
{
- GeneratePropertyGetter(property.Field, @class, property.Name, property.Type);
- GeneratePropertySetter(property.Field, @class, property.Name, property.Type);
+ if (property.HasGetter)
+ GeneratePropertyGetter(property.Field, @class, property.Name,
+ property.Type);
+
+ if (property.HasSetter)
+ GeneratePropertySetter(property.Field, @class, property.Name,
+ property.Type);
}
else
{
- GeneratePropertyGetter(property.GetMethod, @class, property.Name, property.Type);
- GeneratePropertySetter(property.SetMethod, @class, property.Name, property.Type);
+ if (property.HasGetter)
+ GeneratePropertyGetter(property.GetMethod, @class, property.Name,
+ property.Type);
+
+ if (property.HasSetter)
+ GeneratePropertySetter(property.SetMethod, @class, property.Name,
+ property.Type);
}
PopBlock();
}
View
11 src/Generator/Generators/CSharp/CSharpTextTemplate.cs
@@ -898,15 +898,18 @@ private void GenerateClassProperties(Class @class)
if (prop.Field != null)
{
- GeneratePropertyGetter(prop.Field, @class);
- GeneratePropertySetter(prop.Field, @class);
+ if (prop.HasGetter)
+ GeneratePropertyGetter(prop.Field, @class);
+
+ if (prop.HasSetter)
+ GeneratePropertySetter(prop.Field, @class);
}
else
{
- if (prop.GetMethod != null)
+ if (prop.HasGetter)
GeneratePropertyGetter(prop.GetMethod, @class);
- if (prop.SetMethod != null)
+ if (prop.HasSetter)
GeneratePropertySetter(prop.SetMethod, @class);
}

0 comments on commit 2330160

Please sign in to comment.
Something went wrong with that request. Please try again.