/// <summary> /// 通过指定的条件类别和对象定位条件 /// </summary> /// <param name="conditionType"></param> /// <param name="conditionObject"></param> /// <returns></returns> public static QCCondition SelectQCCondition(QCConditionType conditionType, object conditionObject) { IList <QCCondition> kindConditions = new List <QCCondition>(); foreach (QCCondition qcc in _allConditions) { if (qcc._conditionType == conditionType) { kindConditions.Add(qcc.Clone()); } } string objtype = Qcsv.ConditionType2String(conditionType); if (string.IsNullOrEmpty(objtype)) { foreach (QCCondition qcc in kindConditions) { if (qcc.JudgeSetting == conditionObject.ToString()) { return(qcc); } } } else { foreach (QCCondition qcc in kindConditions) { QCParams qcp = new QCParams(qcc.JudgeSetting); if (Qcsv.JudgeObjIsEqualProps(Type.GetType(objtype), conditionObject, qcp)) { return(qcc); } } } return(null); }
/// <summary> /// 通过指定的条件类别和对象定位条件 /// </summary> /// <param name="resultType"></param> /// <param name="resultObject"></param> /// <returns></returns> public static QCResult SelectQCResult(QCResultType resultType, object resultObject) { IList <QCResult> kindResults = new List <QCResult>(); foreach (QCResult qcr in _allResults) { if (qcr._type == resultType) { kindResults.Add(qcr.Clone()); } } string objtype = Qcsv.ResultType2String(resultType); if (string.IsNullOrEmpty(objtype)) { foreach (QCResult qcr in kindResults) { if (qcr.JudgeSetting == resultObject.ToString()) { return(qcr); } } } else { foreach (QCResult qcr in kindResults) { QCParams qcp = new QCParams(qcr.JudgeSetting); if (Qcsv.JudgeObjIsEqualProps(Type.GetType(objtype), resultObject, qcp)) { return(qcr); } } } return(null); }
/// <summary> /// 判断一个实例是否满足指定类型的参数设置 /// </summary> /// <param name="t"></param> /// <param name="conditionObject"></param> /// <param name="qcp"></param> /// <returns></returns> public static bool JudgeObjIsEqualProps(Type t, object conditionObject, QCParams qcp) { if (t == null || conditionObject == null || qcp == null || qcp.Settings.Count == 0) { return(false); } if (!t.IsAssignableFrom(conditionObject.GetType())) { return(false); } foreach (string key in qcp.Settings.Keys) { object value = conditionObject; Type proptype = t; string[] props = key.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < props.Length; i++) { PropertyInfo pi = proptype.GetProperty(props[i], BindingFlags.Public | BindingFlags.Instance); if (pi == null) { return(false); } value = pi.GetValue(value, null); proptype = pi.PropertyType; } if (value == null) { return(false); } string cmpvalue = value.GetType().IsEnum ? ((int)value).ToString() : value.ToString(); if (!qcp.Settings[key].Check(cmpvalue)) { return(false); } } return(true); }
/// <summary> /// 设置属性条件集合 /// </summary> public void SetClassParams(string qcparams) { _qcParams = new QCParams(qcparams); FillPropValue(); }