0

I have a service in ServiceStack with a DTO that returns multiple properties, but some can only be returned if the person is authenticated, or if some rule.

How can I do this?

The attribute can only be used in class or method and not a property.

Scott
  • 20,853
  • 8
  • 63
  • 72

1 Answers1

2

There are many ways to ignore properties in serialization, using Conditional Serialization is likely the most useful here.

But I'd personally avoid using bespoke serialization features and just use vanilla C# to set the properties you don't want to return to null, either within your service or in one of the Custom Response Filters and Hooks.

Community
  • 1
  • 1
mythz
  • 138,929
  • 27
  • 237
  • 382
  • Would for example create an attribute, permission and GlobalResponseFilters, change the DTO to return the correct object? Because it would be difficult for any property to create a validation method. Tranks. – Rudá Cunha Sep 05 '14 at 13:22