简体   繁体   中英

Amazon Web Services .Net SDK using .With methods

I notice that many of the Request objects that can be created with the AWS SDK for .Net have .With() methods along with public properties that can be set directly.

My question is there a reason to use the .With method as opposed to just setting the property ie:

var listQueuesRequest = new ListQueuesRequest().WithQueueNamePrefix(queueNamePrefix);

or

var listQueuesRequest = new ListQueuesRequest() {
    QueueNamePrefix = queueNamePrefix
};

It's a programming style called Method chaining originating mainly from Java programming in order to create a Fluent interface .

The WithQueueNamePrefix() method will return the same ListQueuesRequest object so that you can immediately continue "chaining" more statements on the same object. The idea is that this improves readability and amount of source code, although not everybody agrees.

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