public void AddAttributeCondition(string attributName, string value, ValueRule valueRule, GroupRule groupRule) { if (attributName == null) { Err("Attribute name not specified"); return; } //check attribut existence in the specified type PropertyInfo attr = Type.GetProperty(attributName); if (attr == null) { Err("Attribute name '" + attributName + "' does not exist in specified type '" + Type.Name + "'."); return; } //create expression to access attribute Expression attrExp = Expression.Property(input, attr); //get value from the string Expression val = XbimQueryFactory.PromoteToConstant(attr.PropertyType, value); if (val == null) { Err("Value '" + value + "' could not be converted to the type of the attribute '" + attributName + "'."); return; } //create binary expression according to valueRule Expression expression = CreateValueExpression(attrExp, val, valueRule); if (expression == null) { Err("Value rule'" + Enum.GetName(typeof(ValueRule), valueRule) + "' cannot be applied on the attribute '" + attributName + "'."); return; } //add resulting expression to the group AddToGroup(expression, groupRule); }
public static bool EvaluatePropertyValue(IPersistIfcEntity element, string pSetName, NameRule pSetNameRule, string propertyName, NameRule propNameRule, string value, ValueRule valueRule) { Dictionary <IfcLabel, Dictionary <IfcIdentifier, IfcValue> > allProperties = null; if (string.IsNullOrEmpty(propertyName)) { return(false); } //properties could be defined in IfcTypeObject as HasProperties IfcTypeObject typeObject = element as IfcTypeObject; if (typeObject != null) { allProperties = typeObject.GetAllPropertySingleValues(); } //or properties could be defined in IfcObject in IsDefinedBy IfcObject ifcObject = element as IfcObject; if (ifcObject != null) { allProperties = ifcObject.GetAllPropertySingleValues(); } //or properties could be defined for material as ExtendedMaterialProperties IfcMaterial material = element as IfcMaterial; if (material != null) { allProperties = material.GetAllPropertySingleValues(); } //getting properties is not supported otherwise if (allProperties != null) { foreach (var p in allProperties) { //if pSetName is null all property sets are inspected if (pSetName != null) { if (!IsRightName(pSetName, p.Key, pSetNameRule)) { continue; } } foreach (var prop in p.Value) { //if name is not specified all values are returned if (IsRightName(propertyName, prop.Key, propNameRule)) { Type t = ((ExpressType)(prop.Value)).UnderlyingSystemType; Expression right = XbimQueryFactory.PromoteToConstant(t, value); Expression left = XbimQueryFactory.PromoteToConstant(t, prop.Value.ToString()); //todo: this should be more sofisticated than 'ToString()' Expression eval = CreateValueExpression(left, right, valueRule); return(Expression.Lambda <Func <bool> >(eval).Compile()()); } } } } return(false); }