private PropertyInfo GetInstanceComplexPropertyInstance(object obj, string propName, out object instance) { instance = null; PropertyInfo info = null; foreach (String part in propName.Split('.')) { if (obj == null) { return(null); } instance = obj; Type type = obj.GetType(); info = RuleAwareEntityPropertyInfo.GetInstancePropertyInfo(type, part); if (info == null) { return(null); } obj = info.GetValue(obj, null); } return(info); }
public void AttachAggregatePropertyToEntity(TEntity entity) { foreach (var item in _allProperties) { entity.InitializeCalculatedProperty(RuleAwareEntityPropertyInfo.GetCalculatedProperty(_entityType, item) , _aggregateProperties[item]); } }
private void CompilePlaceHolders() { foreach (var item in _placeHolders) { if (RuleAwareEntityPropertyInfo.HasProperty <TEntity>(_context.RootEntityType, item.Key)) { throw new PlaceHolderException(item.Key, item.Key, _context.RootEntityType, _context.RuleEngineId); } _propertyparser.AddPlaceHolder(item.Key, item.Value); _ruleparser.AddPlaceHolder(item.Key, item.Value); } }
private static bool TryParseSimpleProperty(string entityType, RuleEntityContextMetadata ruleEntityMetadata, string property, Type type, out string replacedString, out bool resolvedAsDynamicProperty, Dictionary <string, string> customplaceholders, bool resolveInstanceProperty = false) { resolvedAsDynamicProperty = false; replacedString = string.Empty; if (TryParseRuleEnginePlaceHolders(customplaceholders, property, out replacedString)) { return(true); } string alias; string propertyWithoutAlias; if (TryGetAlias(property, out alias, out propertyWithoutAlias)) { replacedString = property = propertyWithoutAlias; if (!TryGetEntityTypeFromAlias(out entityType, ruleEntityMetadata, out type, alias)) { return(true); } } Property prop = RuleAwareEntityPropertyInfo.GetProperty(entityType, property, type); if (prop == Property.PropertyNotFound) { return(false); } if (prop.IsDynamicType || prop.IsCalculated) { resolvedAsDynamicProperty = true; string resolvedString = prop.ResolveRuleDynamicContext(); if (string.IsNullOrEmpty(resolvedString)) { return(false); } replacedString = resolvedString; } if (prop.IsInstanceType) { replacedString = resolveInstanceProperty ? prop.ResolveRuleDynamicContext() : property; } return(true); }
public Grouping(RuleEngineContext.RuleEngineContext context, IEnumerable <TEntity> entity, IEnumerable <AggregatePropertyMetadata <TEntity> > aggregateProps) { _aggregateProperties = new PropertyBag(BagType.Calculated, context.RootEntityType); _entityType = context.RootEntityType; Entity = entity; this._aggregateProps = aggregateProps; foreach (var item in aggregateProps) { var prop = RuleAwareEntityPropertyInfo.GetCalculatedProperty(_entityType, item.PropertyName); _aggregateProperties.Initialize(prop); _allProperties.Add(item.PropertyName); } CalculateAggregatePropertiesForGroup(entity); }
public Property SearchProperty(string property) { if (BagType == BagType.Dynamic) { if (ContainsProperty(property)) { return(RuleAwareEntityPropertyInfo.GetDynamicProperty(_entityType, property)); } } if (BagType == BagType.Calculated) { if (ContainsProperty(property)) { return(RuleAwareEntityPropertyInfo.GetCalculatedProperty(_entityType, property)); } } throw new PropertyNotFoundException(property, _entityType); }
private bool TryGetInstanceProperty(string property, out PropertyInfo info, out object instance) { if (property.Contains(".")) { info = GetInstanceComplexPropertyInstance(this, property, out instance); } else { info = RuleAwareEntityPropertyInfo.GetInstancePropertyInfo(GetType(), property); instance = this; } if (info == null) { return(false); } return(true); }
public bool ContainsProperty(string property) { if (BagType == BagType.Dynamic) { var prop = RuleAwareEntityPropertyInfo.GetDynamicProperty(_entityType, property); if (prop.IsNotFound) { return(false); } return(true); } if (BagType == BagType.Calculated) { var prop = RuleAwareEntityPropertyInfo.GetCalculatedProperty(_entityType, property); if (prop.IsNotFound) { return(false); } return(true); } return(false); }
public static void CreateDynamicPropertyForType <TEnity, TType>(string entityType, string name) { RuleAwareEntityPropertyInfo.CreateDynamicProperty <TEnity, TType>(entityType, name); }
public static void CreateDynamicPropertyForType <TEnity>(string entityType, string name, Type type, object defaultValue) { RuleAwareEntityPropertyInfo.CreateDynamicProperty <TEnity>(entityType, name, type, defaultValue); }