Class BooleanExtensions
bool 扩展方法
Inherited Members
Namespace: Lett.Extensions
Assembly: Lett.Extensions.dll
Syntax
public static class BooleanExtensions
Methods
| Improve this Doc View SourceIfFalse(Boolean, Action)
结果为 False 时,执行方法
Declaration
public static void IfFalse(this bool this, Action action)
Parameters
Type | Name | Description |
---|---|---|
Boolean | this | 结果 |
Action | action | 执行的方法 |
Examples
var condition = true;
var rs = "";
condition.IfFalse(() => rs = "it is false"); // rs == "";
var condition = false;
var rs = "";
condition.IfFalse(() => rs = "it is false"); // rs == "it is false";
|
Improve this Doc
View Source
IfFalse<T>(Boolean, T)
结果为 False 时,返回参数
结果为 True 时,返回参数类型默认值
Declaration
public static T IfFalse<T>(this bool this, T result)
Parameters
Type | Name | Description |
---|---|---|
Boolean | this | 结果 |
T | result | 参数 |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T | 参数类型 |
Examples
var condition = true;
var rs = "";
rs = condition.IfFalse("it is false"); // rs == null == default(string)
var condition = false;
var rs = "";
rs = condition.IfFalse("it is false"); // rs == "it is false"
|
Improve this Doc
View Source
IfTrue(Boolean, Action)
结果为 True 时,执行方法
Declaration
public static void IfTrue(this bool this, Action action)
Parameters
Type | Name | Description |
---|---|---|
Boolean | this | |
Action | action | 执行的方法 |
Examples
var condition = true;
var rs = "";
condition.IfTrue(() => rs = "it is true"); // rs == "it is true";
var condition = false;
var rs = "";
condition.IfTrue(() => rs = "it is true"); // rs == "";
|
Improve this Doc
View Source
IfTrue<T>(Boolean, T)
结果为 True 时,返回参数
结果为 False 时,返回参数类型默认值
Declaration
public static T IfTrue<T>(this bool this, T result)
Parameters
Type | Name | Description |
---|---|---|
Boolean | this | |
T | result | 参数 |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T | 参数类型 |
Examples
var condition = true;
var rs = "";
rs = condition.IfTrue("it is true"); // rs == "it is true";
var condition = false;
var rs = "";
rs = condition.IfTrue("it is true"); // rs == null == default(string)