public RuleContext(object obj, RuleConstants constants) { context = new Dictionary <string, string>(); BeanDefinition definition = BeanDescriptor.GetDefinition(obj.GetType()); BeanPropertyDescriptorCollection properties = definition.Properties; foreach (BeanPropertyDescriptor bean in properties) { context[bean.PropertyName] = bean.GetValue(obj).ToString(); } if (constants != null) { foreach (KeyValuePair <string, string> keyValue in constants.GetValues()) { context.Add(keyValue); } } }
public RuleContext(object obj, RuleConstants constants) { context = new Dictionary <string, object>(); PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(obj); foreach (PropertyDescriptor propDesc in pdc) { object val = propDesc.GetValue(obj); if (val != null) { object value; if (val is IList) { IList valList = (IList)val; value = valList.Cast <object>().Select(v => v.ToString()).ToList(); } else if (val is decimal) { value = val; } else { value = val.ToString(); } context[propDesc.Name] = value; } } if (constants != null) { foreach (KeyValuePair <string, string> keyValue in constants.GetValues()) { context.Add(keyValue.Key, keyValue.Value); } } }