简体   繁体   English

使用.With方法的Amazon Web Services .Net SDK

[英]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. 我注意到,可以使用适用于.Net的AWS开发工具包创建的许多Request对象都具有.With()方法以及可以直接设置的公共属性。

My question is there a reason to use the .With method as opposed to just setting the property ie: 我的问题是有理由使用.With方法,而不是仅仅设置属性,即:

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 . 这是一种称为方法链接的编程风格,主要源自Java编程以创建Fluent接口

The WithQueueNamePrefix() method will return the same ListQueuesRequest object so that you can immediately continue "chaining" more statements on the same object. WithQueueNamePrefix()方法将返回相同的ListQueuesRequest对象,以便您可以立即继续在同一对象上“链接”更多语句。 The idea is that this improves readability and amount of source code, although not everybody agrees. 这个想法是,尽管并非所有人都同意,但这可以提高源代码的可读性和数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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