简体   繁体   中英

Hide some public properties in ServiceStack service Request and Response DTO's

I am building some services using ServiceStack , I have a following service

public class FooRequest: IReturn<FooResponse>
    {
        public int FooID { get; set; }
        public decimal Amount { get; set; }
        public string SortColumnName { get; set; }
    }
public class FooResponse 
{
    private List<Payment> payments;
    public FooResponse()
    {
        payments= new List<Payment>();
    }
    public List<Payment> Payments
    {
        get { return payments; }
        set { payments = value; }
    }
}

public class Payment
{
    public int ID { get; set; }
    public string Amount { get; set; }  // Amount is formatted string based on the user language          
    public decimal PaymentAmount{ get; set; } // this is Alias for Amount
}

From above FooResponse, I don't want to show PaymentAmount in response/metadata .

If we make it as normal variable instead of property, it won't be visible in metadata. but that should be a property for other requirement.

Is it possible in ServiceStack to restrict some properties in response DTO?

Use the IgnoreDataMember attribute on the PaymentAmount property. Last time I checked ServiceStack was using and complying to the default .NET serialization attributes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM