• C#中的各种各样的索引器


      对上一篇的扩展,索引器不但可以以字符串为索引参数还以各种数据类型做为索引参数,例如Type,委托,下面是对上一篇文章中的扩展,由于类中只有一个bool类型的变量,所以可以这样使用索引

    Parameter parameter = new Parameter();

    parameter[typeof(bool)] = ture;

    bool b = parameter[typeof(bool)];

    还可以这样调用函数:

    parameter[typeof(CalcWithDotType),"Get_Hf"](ExtractDotType.FiveDot);

      #region Custom's ValueType and Delegate
        /// <summary>
        /// 体温类型
        /// </summary>
        public enum BodyTemperatureType
        {LowTemperature,NormalTemperature,HighTemperature,type};
        /// <summary>
        /// 抽点类型
        /// </summary>
        public enum ExtractDotType{FiveDot,NineDot,type};
        #region Custom's Delegates
        public delegate double CalcWithDotType(ExtractDotType edType);
        public delegate double CalcWithTempType(BodyTemperatureType btType);
        public delegate double CalcWithDouble(double type);
        public delegate double CalcWithNone();
        #endregion
        #endregion
        #region Parameter Class
        public class Parameter
        {
            #region Fields
            private double Hf1;
            private double Hf2;
            private double Hf3;
            private double Hf4;
            private double Hf5;
            private double Hf6;
            private double Hf7;
            private double Hf8;
            private double Hf9;

            private double Ts1;
            private double Ts2;
            private double Ts3;
            private double Ts4;
            private double Ts5;
            private double Ts6;
            private double Ts7;
            private double Ts8;
            private double Ts9;

            private double Tr;

            private double Tcl1;
            private double Tcl2;
            private double Tcl3;
            private double Tcl4;
            private double Tcl5;
            private double Tcl6;
            private double Tcl7;
            private double Tcl8;
            private double Tcl9;

            private double Icl;
            private double _Ts;
            private double _Tcl;
            private double _Hf;
            private double s;
            private double _Tb;
            private double _s;

            private BodyTemperatureType _btType = default(BodyTemperatureType);
            private ExtractDotType _edType = default(ExtractDotType);
            private  double _weight;//体重
            private  double _area;//体表面积

            private double _delta_Tb;
            private  bool  _Calculates_s = false;
            #endregion
            #region Members
            /// <summary>
            /// 加权平均热流
            /// </summary>
            /// <param name="edType"></param>
            /// <returns></returns>
           

            public double Get_Hf(ExtractDotType edType)
            {
                if (edType == ExtractDotType.FiveDot)
                {
                    _Hf = 0.07 * Hf1 + 0.50 * Hf2 + 0.05 * Hf6 + 0.18 * Hf7 + 0.20 * Hf8;
                }
                else if (edType == ExtractDotType.NineDot)
                {
                    _Hf = 0.07 * Hf1 + 0.18 * Hf2 + 0.18 * Hf3 + 0.07 * Hf4 + 0.07 * Hf5 + 0.05 * Hf6 + 0.19 * Hf7 + 0.13 * Hf8 + 0.06 * Hf9;
                }
                else
                    _Hf =  default(double);
                return _Hf;

            }
            /// <summary>
            /// 加权平均皮肤温度
            /// </summary>
            /// <param name="edType"></param>
            /// <returns></returns>
            public double Get_Ts(ExtractDotType edType)
            {
                if (edType == ExtractDotType.FiveDot)
                {
                    _Ts =  (0.07 * Ts1 + 0.50 * Ts2 + 0.05 * Ts6 + 0.18 * Ts7 + 0.20 * Ts8);
                }
                else if (edType == ExtractDotType.NineDot)
                {
                    _Ts =  (0.07 * Ts1 + 0.18 * Ts2 + 0.18 * Ts3 + 0.07 * Ts4 + 0.07 * Ts5 + 0.05 * Ts6 + 0.19 * Ts7 + 0.13 * Ts8 + 0.06 * Ts9);
                }
                else
                    _Ts =  default(double);
                return _Ts;

            }
            /// <summary>
            /// 加权平均请外表温度
            /// </summary>
            /// <param name="edType"></param>
            /// <returns></returns>
            public double Get_Tcl(ExtractDotType edType)
            {
                if (edType == ExtractDotType.FiveDot)
                {
                   _Tcl =  (0.07 * Tcl1 + 0.50 * Tcl2 + 0.05 * Tcl6 + 0.18 * Tcl7 + 0.20 * Tcl8);
                }
                else if (edType == ExtractDotType.NineDot)
                {
                    _Tcl =  (0.07 * Tcl1 + 0.18 * Tcl2 + 0.18 * Tcl3 + 0.07 * Tcl4 + 0.07 * Tcl5 + 0.05 * Tcl6 + 0.19 * Tcl7 + 0.13 * Tcl8 + 0.06 * Tcl9);
                }
                else
                    _Tcl =  default(double);
                return _Tcl;

            }
            /// <summary>
            /// 服装总隔热值
            /// </summary>
            /// <returns></returns>
            public double GetIcl()
            {
                Icl = 6.45 * (_Ts - _Tcl)/_Hf;
                return Icl;
            }
            /// <summary>
            /// 加权平均体温
            /// </summary>
            /// <param name="btType"></param>
            /// <returns></returns>
            public double Get_Tb(BodyTemperatureType btType)
            {
                if (btType == BodyTemperatureType.LowTemperature)
                {
                    _Tb = 0.50 * _Ts + 0.50 * Tr;
                }
                else if (btType == BodyTemperatureType.NormalTemperature)
                {
                    _Tb = 0.33 * _Ts + 0.67 * Tr;
                }
                else if (btType == BodyTemperatureType.HighTemperature)
                {
                    _Tb = 0.20 * _Ts + 0.80 * Tr;
                }
                else
                    _Tb = default(double);
                return _Tb;
               
            }
            /// <summary>
            /// 热积或热债
            /// </summary>
            /// <param name="delta_Tb"></param>
            /// <param name="weight"></param>
            /// <returns></returns>
            public double Gets(double delta_Tb)
            {
                s = 3.473 * delta_Tb * _weight;
                return s;
            }
            public double Get_s(double delta_Tb)
            {
                _s = 3.474 * delta_Tb * _weight / _area;
                return _s;
            }
            public double Calculate()
            {
                Get_Ts(_edType);
                Get_Tcl(_edType);
                Get_Hf(_edType);
                Get_Tb(_btType);
                GetIcl();
                s = default(double);
                _s = default(double);
                if (_Calculates_s)
                {
                    Gets(_delta_Tb);
                    Get_s(_delta_Tb);
                }
                return 0.0;
            }
     
            /// //////
            CalcWithDotType  GHf;
            CalcWithDotType  GTs;
            CalcWithDotType  GTcl;
            CalcWithNone     GIcl;
            CalcWithTempType GTb;
            CalcWithDouble   Gs;
            CalcWithDouble   G_s;
            public CalcWithNone     Calc;
            #endregion
            #region Construction
            public Parameter()
            {
                GHf = Get_Hf;
                GTs = Get_Ts;
                GTcl = Get_Tcl;
                GIcl = GetIcl;
                GTb = Get_Tb;
                Gs = Gets;
                G_s = Get_s;
                Calc = Calculate;
            }
            #endregion
            #region Indexers
            public CalcWithDotType this[Type type, string delname]
            {
                get
                {
                    if (type == typeof(CalcWithDotType) && (delname.ToLower() == "Get_Hf"))            
                        return  GHf;
                    else if (type == typeof(CalcWithDotType) && (delname.ToLower() == "Get_Ts"))
                        return GTs;
                    else if (type == typeof(CalcWithDotType) && (delname.ToLower() == "Get_Tcl"))
                        return GTcl;
                    else
                    {
                        MessageBox.Show(this.ToString() + "中不存在这样的成员:" + type.ToString(), "成员不存在", MessageBoxButtons.OK);
                        return null;
                    }
                }
                set
                {
                    if (type == typeof(CalcWithDotType) && (delname.ToLower() == "Get_Hf"))
                    {
                        GHf = value;
                    }
                    else if (type == typeof(CalcWithDotType) && (delname.ToLower() == "Get_Ts"))
                    {
                        GTs = value;
                    }
                    else if (type == typeof(CalcWithDotType) && (delname.ToLower() == "Get_Tcl"))
                    {
                        GTcl = value;
                    }
                    else
                    {
                        MessageBox.Show(this.ToString() + "中不存在这样的成员:" + type.ToString(), "成员不存在", MessageBoxButtons.OK);
                    }
                }

            }
            public bool this[Type type]
            {
                get
                {
                    if (type == typeof(bool))
                        return _Calculates_s;
                    else
                        return Convert.ToBoolean( MessageBox.Show(this.ToString() + "中不存在这样的成员:" + type.ToString(), "成员不存在", MessageBoxButtons.OK).GetHashCode());
                }
                set
                {
                    if (type == typeof(bool))
                        _Calculates_s = value;
                    else
                        MessageBox.Show(this.ToString() + "中不存在这样的成员:" + type.ToString(), "成员不存在", MessageBoxButtons.OK);
                }
            }
            public Enum this[Enum type]
            {
                get
                {
                    if (type.GetType() == typeof(BodyTemperatureType))
                        return _btType;
                    else if (type.GetType() == typeof(ExtractDotType))
                        return _edType;
                    else
                        return (Enum)MessageBox.Show(this.ToString() + "中不存在这样的成员:" + type.ToString(), "成员不存在", MessageBoxButtons.OK) ;
                }
                set
                {
                    if (type.GetType() == typeof(BodyTemperatureType))
                        _btType = (BodyTemperatureType)value;
                    else if (type.GetType() == typeof(ExtractDotType))
                        _edType = (ExtractDotType)value;
                    else
                        MessageBox.Show(this.ToString() + "中不存在这样的成员:" + type.ToString(), "成员不存在", MessageBoxButtons.OK).GetHashCode();

                }
            }
            public double this[string paraid]
            {
                get
                {
                    if (paraid == "Hf1")
                        return Hf1;
                    else if (paraid == "Hf2")
                        return Hf2;
                    else if (paraid == "Hf3")
                        return Hf3;
                    else if (paraid == "Hf4")
                        return Hf4;
                    else if (paraid == "Hf5")
                        return Hf5;
                    else if (paraid == "Hf6")
                        return Hf6;
                    else if (paraid == "Hf7")
                        return Hf7;
                    else if (paraid == "Hf8")
                        return Hf8;
                    else if (paraid == "Hf9")
                        return Hf9;

                    else if (paraid == "Ts1")
                        return Ts1;
                    else if (paraid == "Ts2")
                        return Ts2;
                    else if (paraid == "Ts3")
                        return Ts3;
                    else if (paraid == "Ts4")
                        return Ts4;
                    else if (paraid == "Ts5")
                        return Ts5;
                    else if (paraid == "Ts6")
                        return Ts6;
                    else if (paraid == "Ts7")
                        return Ts7;
                    else if (paraid == "Ts8")
                        return Ts8;
                    else if (paraid == "Ts9")
                        return Ts9;
                    else if (paraid == "Tr")
                        return Tr;

                    else if (paraid == "Tcl1")
                        return Tcl1;
                    else if (paraid == "Tcl2")
                        return Tcl2;
                    else if (paraid == "Tcl3")
                        return Tcl3;
                    else if (paraid == "Tcl4")
                        return Tcl4;
                    else if (paraid == "Tcl5")
                        return Tcl5;
                    else if (paraid == "Tcl6")
                        return Tcl6;
                    else if (paraid == "Tcl7")
                        return Tcl7;
                    else if (paraid == "Tcl8")
                        return Tcl8;
                    else if (paraid == "Tcl9")
                        return Tcl9;

                    else if (paraid == "Icl")
                        return Icl;
                    else if (paraid == "_Ts")
                        return _Ts;
                    else if (paraid == "_Tcl")
                        return _Tcl;
                    else if (paraid == "_Hf")
                        return _Hf;
                    else if (paraid == "s")
                        return s;
                    else if (paraid == "_Tb")
                        return _Tb;
                    else if (paraid == "_s")
                        return _s;
                    else if (paraid == "delta_Tb")
                        return _delta_Tb;
                    else if (paraid.ToLower() == "weight")
                        return _weight;
                    else if (paraid.ToLower() == "area")
                        return _area;
                    else
                        return MessageBox.Show(this.ToString() + "中不存在这样的成员:" + paraid, "成员不存在", MessageBoxButtons.OK).GetHashCode();
                }
                set
                {
                    if (paraid == "Hf1")
                        Hf1 = value;
                    else if (paraid == "Hf2")
                        Hf2 = value;
                    else if (paraid == "Hf3")
                        Hf3 = value;
                    else if (paraid == "Hf4")
                        Hf4 = value;
                    else if (paraid == "Hf5")
                        Hf5 = value;
                    else if (paraid == "Hf6")
                        Hf6 = value;
                    else if (paraid == "Hf7")
                        Hf7 = value;
                    else if (paraid == "Hf8")
                        Hf8 = value;
                    else if (paraid == "Hf9")
                        Hf9 = value;

                    else if (paraid == "Ts1")
                        Ts1 = value;
                    else if (paraid == "Ts2")
                        Ts2 = value;
                    else if (paraid == "Ts3")
                        Ts3 = value;
                    else if (paraid == "Ts4")
                        Ts4 = value;
                    else if (paraid == "Ts5")
                        Ts5 = value;
                    else if (paraid == "Ts6")
                        Ts6 = value;
                    else if (paraid == "Ts7")
                        Ts7 = value;
                    else if (paraid == "Ts8")
                        Ts8 = value;
                    else if (paraid == "Ts9")
                        Ts9 = value;
                    else if (paraid == "Tr")
                        Tr = value;

                    else if (paraid == "Tcl1")
                        Tcl1 = value;
                    else if (paraid == "Tcl2")
                        Tcl2 = value;
                    else if (paraid == "Tcl3")
                        Tcl3 = value;
                    else if (paraid == "Tcl4")
                        Tcl4 = value;
                    else if (paraid == "Tcl5")
                        Tcl5 = value;
                    else if (paraid == "Tcl6")
                        Tcl6 = value;
                    else if (paraid == "Tcl7")
                        Tcl7 = value;
                    else if (paraid == "Tcl8")
                        Tcl8 = value;
                    else if (paraid == "Tcl9")
                        Tcl9 = value;

                    else if (paraid == "Icl")
                        Icl = value;
                    else if (paraid == "_Ts")
                        _Ts = value;
                    else if (paraid == "_Tcl")
                        _Tcl = value;
                    else if (paraid == "_Hf")
                        _Hf = value;
                    else if (paraid == "s")
                        s = value;
                    else if (paraid == "_Tb")
                        _Tb = value;
                    else if (paraid == "_s")
                        _s = value;
                    else if (paraid == "delta_Tb")
                        _delta_Tb = value;
                    else if (paraid == "weight")
                        _weight =  value;
                    else if (paraid == "area")
                        _area =  value;
                    else
                        MessageBox.Show(this.ToString() + "中不存在这样的成员:" + paraid, "成员不存在", MessageBoxButtons.OK);
                }
            }     
            #endregion

        }
        #endregion

  • 相关阅读:
    Thinkphp无法加载验证码 undefined function Thinkimagettftext() 解决方案 mac系统
    fragment使用不当 导致java.lang.IllegalStateException
    怎样从GitHub项目中,下载单个文件夹或文件
    Android 5.0 app样式
    OpenCV fitline直线拟合函数学习
    Linux文件系统
    Ubuntu 12.04 笔记本触摸板失灵解决方法
    利用微软测试工具PICT生成测试用例
    Myeclipse 使用JUnit 进行单元测试
    Myeclipse 2014 安装checkstyle、PMD和Metrics
  • 原文地址:https://www.cnblogs.com/mcjtcnblog/p/1366354.html
Copyright © 2020-2023  润新知