Skip to content

Commit 8d0065b

Browse files
author
Mario Brizic
committed
Move attribute logic to Helpers class
1 parent 39761da commit 8d0065b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

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 & 7 deletions
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 && DoesntContainJsonIgnoreAttribute(p))
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,
@@ -393,11 +393,5 @@ private InterfaceNode AdjustBaseClass(InterfaceNode interfaceNode, InterfaceNode
393393

394394
return interfaceNode;
395395
}
396-
397-
private bool DoesntContainJsonIgnoreAttribute(PropertyDefinition p)
398-
{
399-
return p.CustomAttributes
400-
.All(a => a.AttributeType.Name != "JsonIgnoreAttribute");
401-
}
402396
}
403397
}

0 commit comments

Comments
 (0)