Skip to content

Commit 33b16cd

Browse files
authored
Merge pull request #13 from greymind/issue-11-dont-generate-properties-with-json-ignore-attribute
Don't generate properties marked with json ignore attribute
2 parents 3588597 + 78458bd commit 33b16cd

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/WebApiTestApplication/Controllers/TestController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public class AnotherClass
7070
public int Number { get; set; }
7171
public string Name { get; set; }
7272
public string[] List { get; set; }
73+
[JsonIgnore]
74+
public string JsonIgnoredProperty { get; set; }
7375
}
7476

7577
public class DerivedClassWithShadowedProperty : AnotherClass

src/WebApiToTypeScript/Helpers.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,12 @@ public static bool HasCustomAttribute(ParameterDefinition parameter, string attr
8484
return parameter.HasCustomAttributes
8585
&& parameter.CustomAttributes.Any(a => a.AttributeType.Name == attributeName);
8686
}
87+
88+
public static bool HasCustomAttribute(PropertyDefinition property, string attributeName)
89+
{
90+
return property.HasCustomAttributes
91+
&& property.CustomAttributes.Any(a => a.AttributeType.Name == attributeName);
92+
}
93+
8794
}
8895
}

src/WebApiToTypeScript/Interfaces/InterfaceService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private List<MemberWithCSharpType> GetMembers(TypeDefinition typeDefinition)
334334
});
335335

336336
var properties = typeDefinition.Properties
337-
.Where(p => p.GetMethod != null && p.GetMethod.IsPublic && !p.IsSpecialName)
337+
.Where(p => p.GetMethod != null && p.GetMethod.IsPublic && !p.IsSpecialName && !Helpers.HasCustomAttribute(p, "JsonIgnoreAttribute"))
338338
.Select(p => new MemberWithCSharpType
339339
{
340340
Name = p.Name,

0 commit comments

Comments
 (0)