/// <summary> /// 从字符串中获得参数 /// </summary> /// <param name="pParameters"></param> public void FromString(string pParameters) { if (string.IsNullOrEmpty(pParameters)) { return; } for (int i = 0; i < pParameters.Split(',').Length; i++) { var para = pParameters.Split(',')[i]; var p = DicProperties.ElementAt(i); p.Value.Value = Convert.ChangeType(para, p.Value.Value.GetType()); var fi = this.GetType().GetField(p.Key, this.Bf); if (fi != null) { fi.SetValue(this, p.Value.Value); //配置字段的值 } } }
protected StrategyBase() { //处理参数 DicProperties.Clear(); foreach (var v in GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)) { object[] ps = v.GetCustomAttributes(typeof(ParameterAttribute), false); if (ps.Length <= 0) { continue; } ParameterAttribute pa = (ParameterAttribute)ps[0]; Property p = new Property(v.Name, v.GetValue(this)) { Category = pa.Category, Description = pa.Description }; Add(p); } }
/// <summary> /// 构造器:Strategy /// </summary> protected Strategy() { this.BarSerieses = new List <BarSeries>(); this.StrategyDatas = new List <StrategyData>(); //属性参数字典处理 DicProperties.Clear(); FieldInfo[] fis = GetType().GetFields(this.Bf); foreach (var v in fis) { object[] ps = v.GetCustomAttributes(typeof(ParameterAttribute), false); if (ps.Length <= 0) { continue; } ParameterAttribute pa = (ParameterAttribute)ps[0]; Property p = new Property(v.Name, v.GetValue(this)) { Category = pa.Category, Description = pa.Description }; Add(p); } }