Show / Hide Table of Contents

    Class BooleanExtensions

    bool 扩展方法

    Inheritance
    Object
    BooleanExtensions
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Lett.Extensions
    Assembly: Lett.Extensions.dll
    Syntax
    public static class BooleanExtensions

    Methods

    | Improve this Doc View Source

    IfFalse(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)
    • Improve this Doc
    • View Source
    In This Article
    • Methods
      • IfFalse(Boolean, Action)
      • IfFalse<T>(Boolean, T)
      • IfTrue(Boolean, Action)
      • IfTrue<T>(Boolean, T)
    Back to top Copyright (c) 2019 viacooky. All rights reserved.