这个问题的最佳解决方案是什么?我正在尝试创建一个具有几个类类型可选参数的函数,其中null是一个有意义的值,不能用作默认值.如,
public void DoSomething(Class1 optional1, Class2 optional2, Class3 optional3)
{
if (! WasSpecified(optional1)) { optional1 = defaultForOptional1; }
if (! WasSpecified(optional2)) { optional2 = defaultForOptional2; }
if (! WasSpecified(optional3)) { optional3 = defaultForOptional3; }
// ... do the actual work ...
}
我不能使用Class1 optional1 = null因为null是有意义的.我不能使用一些占位符类实例,Class1 optional1 = defaultForOptional1因为这些可选参数的编译时常量要求我提出了以下选项:
有没有人想出一些聪明的解决方案呢?
谢谢!
编辑:我最后写了一个包装类,所以我没有必要继续重复Boolean HasFoo.
/// <summary>
/// A wrapper for variables indicating whether or not the variable has
/// been set.
/// …Run Code Online (Sandbox Code Playgroud) 我试图获得类似于基线的垂直对齐方式,但在文本的第一行而不是最后一行。top两者都没有正确text-top对齐。有任何想法吗?谢谢!
编辑:这假设对齐的元素中的字体大小相同。请参阅下面 @FelipeAls 对已接受答案的评论。
编辑:现在带有代码示例和图片:
我想做的是垂直对齐几个内联块元素中的文本,以便它们的基线都位于相同的位置。我宁愿不做类似使用边距和填充来推动事物的事情,因为我发现每当我这样做时,我最终都会在不同的浏览器上玩打地鼠游戏。
HTML:
<div class="foo">
<span>one</span>
<span>two two two two</span>
<span>three three three three three three three three three</span>
<button type="button">action</button>
</div>
<div class="bar">
<span>one</span>
<span>two two two two</span>
<span>three three three three three three three three three</span>
<button type="button">action</button>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
body {
font-family: sans-serif;
font-size: 12px;
}
button {
font-family: inherit;
font-size: inherit;
}
div {
position: relative;
width: 500px;
text-align: center;
}
div.foo, div.bar {
margin-bottom: 2em; …Run Code Online (Sandbox Code Playgroud) Mule表达式组件中的变量范围是什么,以及它与流变量的关系如何?我有一个带有a的流程,set-variable并且惊讶地看到该值被一个赋值所覆盖expression-component.例如,
<flow name="HelloWorldFlow1" doc:name="HelloWorldFlow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="9999" doc:name="HTTP"
doc:description="This endpoint receives an HTTP message." path="helloworld"/>
<set-variable variableName="asdf" value="firstvalue" doc:name="Variable"/>
<logger message="#[flowVars["asdf"]]" level="INFO" doc:name="Logger"/>
<expression-component doc:name="Expression"><![CDATA[asdf = "secondvalue";]]></expression-component>
<logger message="#[flowVars["asdf"]]" level="INFO" doc:name="Logger"/>
<expression-component doc:name="Expression"><![CDATA[qwer = "thirdvalue";]]></expression-component>
<logger message="#[flowVars["qwer"]]" level="INFO" doc:name="Logger"/>
</flow>
Run Code Online (Sandbox Code Playgroud)
这个输出是:
INFO 2014-04-25 08:58:46,889 [[helloworld].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: firstvalue
INFO 2014-04-25 08:58:46,893 [[helloworld].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: secondvalue
INFO 2014-04-25 08:58:46,895 [[helloworld].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: null
Run Code Online (Sandbox Code Playgroud)
如果可能的话,您能指出我对范围规则的文档吗?我尝试了一些不同的搜索,并继续获得无关的结果.
澄清:在expression-componentMule中,是否首先检查是否存在具有给定名称的流变量,然后使用该变量而不是创建新变量?如果表达式组件创建变量,那么范围是否仅限于表达式组件代码?在http://blogs.mulesoft.org/mule-school-the-mulemessage-property-scopes-and-variables/中,它说Mule流变量"表现得像实例属性",但我找不到定义什么是实例属性.单词范围也不在表达式组件参考页面中(http://www.mulesoft.org/documentation/display/current/Expression+Component+Reference).
我尝试使用Spark视图引擎发出一个文字美元符号,打开大括号,文本和关闭大括号.我怎样才能让Spark发出${Hello},而不是试图评估变量名Hello?我能想到的最好的是${'$'}{Hello},但这看起来太复杂了,而且难以阅读.
对于上下文,我使用Spark作为ASP.NET MVC视图引擎,但我也将它用作模板引擎,因此我的应用程序的(高级)用户可以在文本区域中键入一个简单的Spark视图并保存它呈现电子邮件等
谢谢!