public PropertyExpressionViewModel(HermesViewModel parent, PropertyExpression model) : base(parent, model) { this.RemovePropertyCommand = new DelegateCommand(this.RemoveProperty); this.OpenPropertySelectionDialogCommand = new DelegateCommand(this.OpenPropertySelectionDialog); this.IntializeViewModel(model); }
public void Prepare(ref int currentOrdinal) // start ordinal for the table fields in SELECT clause - move to constructor ? { string propertyAlias = property.Name; PropertyExpression consumer = property.Consumer as PropertyExpression; if (consumer != null) { propertyAlias = consumer.Alias; } bool isMultiValued = (property.Property.Fields.Count > 1); foreach (Field field in property.Property.Fields) { string name = string.Empty; if (currentOrdinal > 0) { name += $"\n\t,"; } name += $"[{property.Table.Alias}].[{field.Name}] AS "; if (isMultiValued) { name += $"[{propertyAlias}_{GetFieldPurposeSuffix(field)}]"; } else { name += $"[{propertyAlias}]"; } ordinals.Add(currentOrdinal, name); purposes.Add(field.Purpose, currentOrdinal); currentOrdinal++; } }
public void NullAnniversary() { var builder = new WebFilterConverter <User>(); var goodUser = new User { BirthDay = DateTime.Today }; var badUser = new User { BirthDay = DateTime.Today.AddDays(1) }; var nullUser = new User { }; var filter = new WebFilter <User>(PropertyExpression <User> .New(u => u.BirthDay), WebFilterOperand.Anniversary, new List <DateTime?> { DateTime.Today, null }); var expression = builder.ToExpression(filter); var users = new List <User> { goodUser, badUser, nullUser }.AsQueryable().Where(expression).ToList(); Assert.Equal(2, users.Count); Assert.Equal(users[0], goodUser); Assert.Equal(users[1], nullUser); }
public void LessThanOrEqualFilter() { var builder = new WebFilterConverter <User>(); var goodUser = new User { Id = 0 }; var goodUser2 = new User { Id = 1 }; var badUser = new User { Id = 3 }; var filter = new WebFilter <User>(PropertyExpression <User> .New(u => u.Id), WebFilterOperand.LessThanOrEqual, new List <int> { 1, 2 }); var expression = builder.ToExpression(filter); var users = new List <User> { goodUser, goodUser2, badUser }.AsQueryable().Where(expression).ToList(); Assert.Equal(2, users.Count); Assert.Equal(users[0], goodUser); Assert.Equal(users[1], goodUser2); }
public DailyInfoDescriptor(string prefix) : base(prefix) { this._DailyId = new PropertyExpression(prefix + "DailyId"); this._Content = new PropertyExpression(prefix + "Content"); this._UpdateTime = new PropertyExpression(prefix + "UpdateTime"); ALL = new PropertyExpression[] { this._DailyId, this._Content, this._UpdateTime }; }
public void Visit(PropertyExpression expression) { //outStream.Write("("); expression.Container.Accept(this); //outStream.Write(").{0}", expression.Text); outStream.Write(".{0}", expression.Text); }
internal override PropertyExpression Export([NotNull] ConditionGroup parent, [NotNull] IPropertyCollection propertyCollection) { var property = propertyCollection.GetProperty(PropertyName); var propertyExpression = new PropertyExpression { Parent = parent, Property = property }; var dataTypeExpression = propertyExpression.DataTypeExpression; dataTypeExpression.SelectedCondition = Condition.Matches; var reflectionService = this.GetDependencyResolver().Resolve <IReflectionService>(); var properties = reflectionService.GetInstanceProperties(property.Type); var group = new ConditionGroup() { Type = ConditionGroupType.And }; Conditions.Select(o => o.Export(group, properties)).Sink(group.Items.Add); ((ComplexTypeExpression)dataTypeExpression).Value = new FilterScheme(property.Type, "Default", group); return(propertyExpression); }
// can process just primitve filter query options: [propertyName] [operator] [constValue] // due to a very primitive type conversion only string and int types are supported private static ComparisonExpression ProcessFilter(string filterExp, ResourceContainer resourceContainer) { string[] components = SplitFilterExpression(filterExp).Where(s => s.Length > 0).ToArray(); if (components.Length != 3) { throw new Exception("filter expression too complicated."); } ComparisonOperator @operator; switch (components[1]) { case "lt": @operator = ComparisonOperator.LessThan; break; case "le": @operator = ComparisonOperator.LessThanOrEqual; break; case "eq": @operator = ComparisonOperator.Equal; break; case "ge": @operator = ComparisonOperator.GreaterThanOrEqual; break; case "gt": @operator = ComparisonOperator.GreaterThan; break; case "ne": @operator = ComparisonOperator.NotEqual; break; default: throw new NotSupportedException(string.Format("Operator {0} is either unknown or not supported", components[1])); } PropertyExpression left = new PropertyExpression(resourceContainer.BaseType.Properties.Where(p => p.Name == components[0]).First()); //the type on the right side has to be the same as the one on the left side object value = components[2][0] == '\'' ? components[2].Substring(1, components[2].Length - 2) : (object)(int.Parse(components[2])); ConstantExpression right = new ConstantExpression(new NodeValue(value, left.Type)); return(new ComparisonExpression(left, right, @operator)); }
public void ExpressionTest() { var a = new Container(); var expression = new PropertyExpression <int>(a, "Child.X"); Assert.AreEqual(10, expression.Value); expression.Value = 1; Assert.AreEqual(1, expression.Value); Assert.AreEqual(1, a.Child.X); expression = new PropertyExpression <int>(a, "Children[0].X"); Assert.AreEqual(10, expression.Value); expression.Value = 1; Assert.AreEqual(1, expression.Value); Assert.AreEqual(1, a.Children[0].X); expression = new PropertyExpression <int>(a, "Dictionary[\"Name\"].X"); Assert.AreEqual(10, expression.Value); expression.Value = 1; Assert.AreEqual(1, expression.Value); Assert.AreEqual(1, a.Dictionary["Name"].X); expression = new PropertyExpression <int>(a.Dictionary, "['Name2'].X"); Assert.AreEqual(10, expression.Value); expression.Value = 1; Assert.AreEqual(1, expression.Value); Assert.AreEqual(1, a.Dictionary["Name2"].X); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyRule{TEntity, TProperty}"/> class. /// </summary> /// <param name="propertyExpression">The <see cref="LambdaExpression"/> to reference the entity property.</param> public PropertyRule(Expression <Func <TEntity, TProperty> > propertyExpression) { _property = PropertyExpression.Create(propertyExpression, true); Name = _property.Name; JsonName = _property.JsonName; Text = _property.Text; }
public void StartsFilter() { var builder = new WebFilterConverter <User>(); var goodUser = new User { Name = "AAAseed" }; var goodUser2 = new User { Name = "bBbseed" }; var badUser = new User { Name = "edgseed" }; var filter = new WebFilter <User>(PropertyExpression <User> .New(u => u.Name), WebFilterOperand.Starts, new List <string> { "aAa", "bbb" }); var expression = builder.ToExpression(filter); var users = new List <User> { goodUser, goodUser2, badUser }.AsQueryable().Where(expression).ToList(); Assert.Equal(2, users.Count); Assert.Equal(users[0], goodUser); Assert.Equal(users[1], goodUser2); }
private void OnExpressionSelected(HermesViewModel selectedExpression) { PropertyExpression model = (PropertyExpression)this.Model; if (selectedExpression == null) { model.Expression = null; this.Expression = null; this.ExpressionView = null; return; } model.Expression = selectedExpression.Model; this.Expression = selectedExpression; //this.Expression.Parent = this; if (selectedExpression is PropertyReferenceViewModel) { //model.Expression.Consumer = model; if (string.IsNullOrEmpty(this.Alias)) { this.Alias = ((PropertyReferenceViewModel)this.Expression).Name; // this sets model's property Alias as well } this.ExpressionView = new PropertyReferenceView((PropertyReferenceViewModel)this.Expression); } else if (selectedExpression is ParameterReferenceViewModel) { this.Alias = ((ParameterReferenceViewModel)this.Expression).Name; // this sets model's property Alias as well this.ExpressionView = new ParameterReferenceView((ParameterReferenceViewModel)this.Expression); } }
/// <summary> /// Adds (or gets) a source <see cref="PropertySrceMapper{TSrce, TSrceProperty, TDest}"/>. /// </summary> /// <typeparam name="TSrceProperty">The source property <see cref="Type"/>.</typeparam> /// <param name="srcePropertyExpression">The <see cref="Expression"/> to reference the source entity property.</param> /// <param name="property">An <see cref="Action"/> enabling access to the created <see cref="PropertyMapper{TSrce, TSrceProperty, TDest, TDestProperty}"/>.</param> /// <returns>The <see cref="EntityMapper{TSrce, TDest}"/>.</returns> public virtual EntityMapper <TSrce, TDest> HasSrceProperty <TSrceProperty>(Expression <Func <TSrce, TSrceProperty> > srcePropertyExpression, Action <PropertySrceMapper <TSrce, TSrceProperty, TDest> > property = null) where TSrceProperty : class { if (srcePropertyExpression == null) { throw new ArgumentNullException(nameof(srcePropertyExpression)); } var spe = PropertyExpression <TSrce, TSrceProperty> .Create(srcePropertyExpression); var px = GetBySrcePropertyName(spe.Name); if (px != null && (px.DestPropertyName != null)) { throw new ArgumentException($"Source property '{srcePropertyExpression.Name}' mapping already exists with a different destination property name"); } PropertySrceMapper <TSrce, TSrceProperty, TDest> p = null; if (px == null) { p = new PropertySrceMapper <TSrce, TSrceProperty, TDest>(spe); AddPropertyMapper(p); } else { p = (PropertySrceMapper <TSrce, TSrceProperty, TDest>)px; } property?.Invoke(p); return(this); }
private bool PropertyExpressionFromPrevious(MemberExpression node, Expression source, out Expression result) { var newExpr = (NewExpression)source; if (newExpr.Members == null) { return(PropertyExpressionFromIntermediate(node, source, out result)); } for (var i = 0; i < newExpr.Members.Count; i++) { if (MembersMatch(newExpr.Members[i], node.Member)) { var target = newExpr.Arguments[i]; if (target is PropertyExpression) { result = new PropertyExpression(node, ((PropertyExpression)newExpr.Arguments[i]).PropertyInfo); } else { //It's a ConstantExpression, intermediate NewExpression or something else we can't deal with. //Leave it alone. Note that we're ok with having an intermediate NewExpression; it's not something //that violates strict result = target; } return(true); } } result = null; return(false); }
//sample: filtered list method for the Workflow General/Process Instance SmartObject static void ExecuteFilteredListMethodWCF() { Console.WriteLine("Executing filtered List method via WCF (Active instances only)"); //set up the service client WorkflowGeneralReport_WCFService.Process_InstanceSvcClient processInstanceSvcClient = new Process_InstanceSvcClient(); processInstanceSvcClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; //set up a filter object (you could also constrcut the filter directly in XML if you prefer) Equals statusEquals = new Equals(); PropertyExpression statusPropertyExp = new PropertyExpression("Status", PropertyType.Text); ValueExpression statusValueExp = new ValueExpression("Active", PropertyType.Text); statusEquals.Left = statusPropertyExp; statusEquals.Right = statusValueExp; // Serialize the filter to XML FilterExp filterExpression = new FilterExp(statusEquals); XmlDocument filterXml = filterExpression.GetFilterXml(); string filterXmlString = filterXml.InnerXml; //call the filter method, passing in the filter XML WorkflowGeneralReport_WCFService.Process_Instance[] processInstanceList = processInstanceSvcClient.Process_InstanceSvc_List_Filtered(filterXmlString); foreach (Process_Instance processInstance in processInstanceList) { Console.WriteLine("Folio: " + processInstance.Folio + " | ProcInstID: " + processInstance.ProcessInstanceID.ToString()); } Console.WriteLine("Completed execution of filtered List method via WCF (Active instances only)"); Console.ReadLine(); }
/// <summary> /// Adds (or gets) a <see cref="DatabasePropertyMapper{TSrce, TSrceProperty}"/>. /// </summary> /// <typeparam name="TSrceProperty">The source property <see cref="Type"/>.</typeparam> /// <param name="srcePropertyExpression">The <see cref="Expression"/> to reference the source entity property.</param> /// <param name="columnName">The database column name.</param> /// <param name="operationTypes">The <see cref="Mapper.OperationTypes"/> selection to enable inclusion or exclusion of property (default to <see cref="OperationTypes.Any"/>).</param> /// <param name="property">An <see cref="Action"/> enabling access to the created <see cref="DatabasePropertyMapper{TSrce, TSrceProperty}"/>.</param> /// <returns>The <see cref="DatabaseMapper{TEntity}"/>.</returns> public DatabaseMapper <TSrce> HasProperty <TSrceProperty>(Expression <Func <TSrce, TSrceProperty> > srcePropertyExpression, string columnName = null, OperationTypes operationTypes = OperationTypes.Any, Action <DatabasePropertyMapper <TSrce, TSrceProperty> > property = null) { if (srcePropertyExpression == null) { throw new ArgumentNullException(nameof(srcePropertyExpression)); } var spe = PropertyExpression <TSrce, TSrceProperty> .Create(srcePropertyExpression); var px = GetBySrcePropertyName(spe.Name); if (px != null && px.DestPropertyName != columnName) { throw new ArgumentException($"Source property '{srcePropertyExpression.Name}' mapping already exists with a different destination column name"); } DatabasePropertyMapper <TSrce, TSrceProperty> p = null; if (px == null) { p = Property(srcePropertyExpression, columnName, operationTypes); } else { p = (DatabasePropertyMapper <TSrce, TSrceProperty>)px; } property?.Invoke(p); return(this); }
private static void DumpValueExpression(StringWriter s, SBExpression expression, string ident = " ") { if (expression is NegativeExpression) { NegativeExpression negativeExpression = (NegativeExpression)expression; s.WriteLine(ident + $"-----> Expression: {negativeExpression.Expression.Dump()}"); DumpValueExpression(s, negativeExpression.Expression, ident + " "); } else if (expression is BinaryExpression) { BinaryExpression binaryExpression = (BinaryExpression)expression; s.WriteLine(ident + $"-----> Operator: {binaryExpression.Operator.Dump()}"); s.WriteLine(ident + $"-----> LeftHandSide: {binaryExpression.LeftHandSide.Dump()}"); DumpValueExpression(s, binaryExpression.LeftHandSide, ident + " "); s.WriteLine(ident + $"-----> RightHandSide: {binaryExpression.RightHandSide.Dump()}"); DumpValueExpression(s, binaryExpression.RightHandSide, ident + " "); } else if (expression is MethodCallExpression) { MethodCallExpression methodCallExpression = (MethodCallExpression)expression; s.WriteLine($"{ident}-----> MethodName: {methodCallExpression.MethodName.Dump()}"); s.WriteLine($"{ident}-----> TypeName: {methodCallExpression.TypeName.Dump()}"); s.WriteLine($"{ident}-----> Arguments: {methodCallExpression.Arguments}"); } else if (expression is PropertyExpression) { PropertyExpression propertyExpression = (PropertyExpression)expression; s.WriteLine($"{ident}-----> PropertyName: {propertyExpression.PropertyName.Dump()}"); s.WriteLine($"{ident}-----> TypeName: {propertyExpression.TypeName.Dump()}"); } }
/// <summary> /// Initializes a new instance of the <see cref="DependsOnClause{TEntity, TProperty}"/> class. /// </summary> /// <param name="dependsOnExpression">The <see cref="Expression"/> to reference the compare to entity property.</param> public DependsOnClause(Expression <Func <TEntity, TProperty> > dependsOnExpression) { // Validate the expression. Beef.Check.NotNull(dependsOnExpression, nameof(dependsOnExpression)); _dependsOn = PropertyExpression.Create(dependsOnExpression, true); }
public void Visit(PropertyExpression expression) { if (expression.PropertyType == typeof(bool)) { var columnName = expression.PropertyName; MatchValue(columnName, true); } }
public void Bool_property_access_without_explicit_comparison_yields_PropertyExpression_with_boolean_property_type() { var expression = _parser.Parse <Book>(x => x.IsPublicDomain); var expectedExpression = new PropertyExpression("IsPublicDomain", typeof(bool)); Assert.AreEqual(expectedExpression, expression); }
void ITreeWalker.Visit(PropertyExpression expression) { expression.Validate(this); expression.Name.Accept(this); expression.Value.Accept(this); _operations.Add(InitObjOperation.Instance); }
public void Bool_property_access_without_explicit_comparison_yields_PropertyExpression_with_boolean_property_type() { var expression = _parser.Parse<Book>(x => x.IsPublicDomain); var expectedExpression = new PropertyExpression("IsPublicDomain", typeof(bool)); Assert.AreEqual(expectedExpression, expression); }
private void OnAddExpression(ConditionGroup group) { var propertyExpression = new PropertyExpression(); propertyExpression.Property = InstanceProperties.FirstOrDefault(); group.Items.Add(propertyExpression); propertyExpression.Parent = group; }
public void Visit(PropertyExpression expression) { if (expression.PropertyType == typeof(bool)) { var columnName = expression.PropertyName; var columnReference = new ColumnReference(columnName, Escape); ConstraintCommandText = string.Format("{0} = 1", columnReference); } }
/// <summary> /// Generates a property query plan /// </summary> /// <param name="myPropertyExpression">The property expression that is going to be transfered</param> /// <param name="myTransaction">The current transaction token</param> /// <param name="mySecurity">The current security token</param> /// <returns>A property query plan</returns> private IQueryPlan GenerateFromPropertyExpression(PropertyExpression myPropertyExpression, Int64 myTransaction, SecurityToken mySecurity) { var type = _vertexTypeManager.ExecuteManager.GetType(myPropertyExpression.NameOfVertexType, myTransaction, mySecurity); return(new QueryPlanProperty(type, type.GetPropertyDefinition(myPropertyExpression.NameOfProperty), myPropertyExpression.Edition, myPropertyExpression.Timespan)); }
public void Translates_property_name_to_column_name_when_translated() { var expression = new ReflectedPropertyExpression(typeof(User).GetProperty("Username")); var expectedExpression = new PropertyExpression("USERNAME", typeof(string)); var actualExpression = expression.Translate(new UpperCaseConvention()); Assert.AreEqual(expectedExpression, actualExpression); }
protected override object GetRawValue(object entity, IExpressionTree fields, PropertyExpression property) { if (property.Name == nameof(IEntityBase.Url)) { return(UrlProvider?.GetEntityApiUri(entity as IPrimaryKey)); } return(base.GetRawValue(entity, fields, property)); }
private static void GenerateUnaryExpression(ScriptGenerator generator, MemberSymbol symbol, UnaryExpression expression) { ScriptTextWriter writer = generator.Writer; PropertyExpression propExpression = expression.Operand as PropertyExpression; if ((propExpression != null) && ((expression.Operator == Operator.PreIncrement) || (expression.Operator == Operator.PostIncrement) || (expression.Operator == Operator.PreDecrement) || (expression.Operator == Operator.PostDecrement))) { Debug.Assert(propExpression.Type == ExpressionType.PropertyGet); string fudgeOperator; GenerateExpression(generator, symbol, propExpression.ObjectReference); writer.Write(".set_"); writer.Write(propExpression.Property.GeneratedName); writer.Write("("); GenerateExpression(generator, symbol, propExpression.ObjectReference); writer.Write(".get_"); writer.Write(propExpression.Property.GeneratedName); writer.Write("()"); if ((expression.Operator == Operator.PreIncrement) || (expression.Operator == Operator.PostIncrement)) { writer.WriteTrimmed(" + "); fudgeOperator = " - "; } else { writer.WriteTrimmed(" - "); fudgeOperator = " + "; } writer.Write("1"); writer.Write(")"); if ((expression.Operator == Operator.PreIncrement) || (expression.Operator == Operator.PreDecrement)) { writer.WriteTrimmed(fudgeOperator); writer.Write("1"); } return; } if ((expression.Operator == Operator.PreIncrement) || (expression.Operator == Operator.PreDecrement)) { ExpressionGenerator.GenerateExpression(generator, symbol, expression.Operand); writer.Write(OperatorConverter.OperatorToString(expression.Operator)); } else { writer.Write(OperatorConverter.OperatorToString(expression.Operator)); ExpressionGenerator.GenerateExpression(generator, symbol, expression.Operand); } }
private List <MemberBinding> CreateMemberBindings(ExpressionRequest request, TypeMap typeMap, Expression instanceParameter, TypePairCount typePairCount, LetPropertyMaps letPropertyMaps) { var bindings = new List <MemberBinding>(); foreach (var propertyMap in typeMap.PropertyMaps .Where(pm => (!pm.ExplicitExpansion || request.MembersToExpand.Contains(pm.DestinationMember)) && pm.CanResolveValue && ReflectionHelper.CanBeSet(pm.DestinationMember)) .OrderBy(pm => pm.DestinationName)) { var propertyExpression = new PropertyExpression(propertyMap); letPropertyMaps.Push(propertyExpression); CreateMemberBinding(propertyExpression); letPropertyMaps.Pop(); } return(bindings); void CreateMemberBinding(PropertyExpression propertyExpression) { var propertyMap = propertyExpression.PropertyMap; var result = ResolveExpression(propertyMap, request.SourceType, instanceParameter, letPropertyMaps); propertyExpression.Expression = result.ResolutionExpression; var propertyTypeMap = _configurationProvider.ResolveTypeMap(result.Type, propertyMap.DestinationType); var propertyRequest = new ExpressionRequest(result.Type, propertyMap.DestinationType, request.MembersToExpand, request); if (propertyRequest.AlreadyExists) { return; } var binder = _configurationProvider.Binders.FirstOrDefault(b => b.IsMatch(propertyMap, propertyTypeMap, result)); if (binder == null) { var message = $"Unable to create a map expression from {propertyMap.SourceMember?.DeclaringType?.Name}.{propertyMap.SourceMember?.Name} ({result.Type}) to {propertyMap.DestinationMember.DeclaringType?.Name}.{propertyMap.DestinationName} ({propertyMap.DestinationType})"; throw new AutoMapperMappingException(message, null, typeMap.Types, typeMap, propertyMap); } var bindExpression = binder.Build(_configurationProvider, propertyMap, propertyTypeMap, propertyRequest, result, typePairCount, letPropertyMaps); if (bindExpression == null) { return; } var rhs = propertyMap.ValueTransformers .Concat(typeMap.ValueTransformers) .Concat(typeMap.Profile.ValueTransformers) .Where(vt => vt.IsMatch(propertyMap)) .Aggregate(bindExpression.Expression, (current, vtConfig) => ToType(ReplaceParameters(vtConfig.TransformerExpression, ToType(current, vtConfig.ValueType)), propertyMap.DestinationType)); bindExpression = bindExpression.Update(rhs); bindings.Add(bindExpression); } }
protected override Expression VisitProperty(PropertyExpression node) { //If we don't have this property already and this isn't a dummy expression if (Members.All(m => node.PropertyInfo.Name != m.PropertyInfo.Name) && node.Expression != null) { Members.Add(node); } return(node); }
protected override Expression VisitProperty(PropertyExpression node) { //It's a real node and not a member of a MemberInitExpression / NewExpression if (node.CanReduce) { SortProperty = node; } return(node); }
public void Translate_returns_property_expression_with_foreign_key_name_according_to_convention_for_reference_property_as_property_name() { var blogProperty = Reflector<BlogPost>.GetProperty(x => x.Blog); var blogIdProperty = Reflector<Blog>.GetProperty(x => x.Id); var entityReferenceExpression = new EntityReferenceExpression(blogProperty, blogIdProperty); var expectedExpression = new PropertyExpression("BLOGID"); Assert.AreEqual(expectedExpression, entityReferenceExpression.Translate(new UpperCaseConvention())); }
protected override bool NullSafeEquals(PropertyExpression other) { var otherReference = other as EntityReferenceExpression; if (otherReference == null) { return false; } return Equals(DataPropertyInfo, otherReference.DataPropertyInfo) && Equals(ReferencePropertyInfo, otherReference.ReferencePropertyInfo); }
public ExpandExpression(QueryNode input, PropertyExpression[] properties) : base(input) { _properties = properties; }
public ThenByExpression(QueryNode input, PropertyExpression[] properties, QueryNode scannode, bool bAscDesc) : this(input, properties, scannode, bAscDesc, false) { }
public NavigationExpression(QueryNode input, PropertyExpression property) : this(input, property, false) { }
public NavigationExpression(QueryNode input, PropertyExpression property, bool isLink) : base(input) { _isLink = isLink; _property = property; }
public static QueryNode ExpandIfApplicable(this QueryNode input, PropertyExpression[] properties, bool applicable) { return applicable ? Expand(input, properties) : input; }
private static MemberBindExpression BindProperty(ResourceType resourceType, string LeftHandSide, string RightHandSide) { PropertyExpression sourceProperty = new PropertyExpression(resourceType.Properties[RightHandSide] as ResourceProperty); TypedMemberExpression targetProperty = new TypedMemberExpression(resourceType.ClientClrType, resourceType.Properties[LeftHandSide].Name); return new MemberBindExpression(sourceProperty, targetProperty); }
public override void Visit(PropertyExpression expression) { _expressionString.AppendFormat(" PE'{0}' ", expression.Name); }
private static Expression ParseExpression(Match match) { string expressionText = match.Value.Trim(); Expression expression; lock (_expressions) { if (_expressions.TryGetValue(expressionText, out expression)) { return expression; } // temporarily add a dummy expression to prevent other threads from parsing the same expression again Log.Debug("Cacheing expression: {0}", expressionText); _expressions.Add(expressionText, new LiteralExpression(expressionText)); } if (match.Groups["string"].Success) { expression = new LiteralExpression(match.Groups["string"].Value); } else if (match.Groups["int"].Success) { expression = new LiteralExpression(int.Parse(match.Groups["int"].Value)); } else if (match.Groups["float"].Success) { expression = new LiteralExpression(float.Parse(match.Groups["float"].Value, CultureInfo.InvariantCulture)); } else if (match.Groups["property"].Success) { expression = new PropertyExpression(match.Groups["property"].Value); } else if (match.Groups["function"].Success) { string functionName = match.Groups["function"].Value; FunctionDefinition function; if (!_registeredFunctions.TryGetValue(functionName, out function)) { Log.Error("Undefined function '{0}' in expression '{1}'", functionName, match.Value); expression = new LiteralExpression(match.Value); } else { int paramCount = match.Groups["param"].Captures.Count; Expression[] parameters = new Expression[paramCount]; for (int i = 0; i < paramCount; i++) { string paramText = match.Groups["param"].Captures[i].Value; Match paramMatch = _expressionRegEx.Match(paramText); parameters[i] = ParseExpression(paramMatch); } expression = new FunctionExpression(_registeredFunctions[functionName], parameters); } } lock (_expressions) { // now replace with the real expression _expressions[expressionText] = expression; } return expression; }
public static ThenByExpression ThenBy(this QueryNode input, PropertyExpression[] properties, bool bAscDesc) { return ThenBy(input, properties, bAscDesc, false); }
public AstoriaRequest EntitySetTopLevelWithSingleExpand(ResourceContainer container, ResourceProperty property) { PropertyExpression[] expandValues = new PropertyExpression[] { new PropertyExpression(property) }; ExpNode q = Query.From( Exp.Variable(container)) .Expand(expandValues) .Select(); return _workspace.CreateRequest(q); }
public void Expand() { string sExpand = String.Empty; PropertyExpression[] expandValues = new PropertyExpression[1]; List<ResourceProperty> properties = new List<ResourceProperty>(); foreach (ResourceProperty property in from.Properties) { if (property.IsNavigation && from.Properties.Contains(property) && !(from.Name == "BugDefectTrackingSet" || from.Name == "BugProjectTrackingSet")) properties.Add(property); } if (properties.Count > 0) { expandValues[0] = new PropertyExpression(properties[0]); sExpand = expandValues[0].ToString(); if (_query is TopExpression) _query = ((TopExpression)_query).Expand(expandValues) as ExpandExpression; else if (_query is OrderByExpression) _query = ((OrderByExpression)_query).Expand(expandValues) as ExpandExpression; else if (_query is ScanExpression) _query = ((ScanExpression)_query).Expand(expandValues) as ExpandExpression; else if (_query is NavigationExpression) _query = ((NavigationExpression)_query).Expand(expandValues) as ExpandExpression; else if (_query is SkipExpression) _query = ((SkipExpression)_query).Expand(expandValues) as ExpandExpression; else if (_query is PredicateExpression) _query = ((PredicateExpression)_query).Expand(expandValues) as ExpandExpression; else if (_query is CountExpression) _query = ((CountExpression)_query).Expand(expandValues) as ExpandExpression; else if (_query is NavigationExpression) _query = ((NavigationExpression)_query).Expand(expandValues) as ExpandExpression; bExpand = true; _action = LastAction.Expand; bIsOption = true; AstoriaTestLog.WriteLineIgnore(".Expand(" + sExpand + ")"); } }
public override void Visit(PropertyExpression expression) { //This code is here to prevent the Visit(Identifier) to be called. Works fine in VS wo/ but not in mono base.Visit(expression); }
public ThenByExpression(QueryNode input, PropertyExpression[] properties, QueryNode scannode, bool bAscDesc, bool excludeFromUri) : base(input) { _properties = properties; _scannode = scannode; _bAscDesc = bAscDesc; _excludeFromUri = excludeFromUri; if (excludeFromUri) _properties = properties.OrderBy(p => p.Name).ToArray(); }
public static ExpandExpression Expand(this QueryNode input, PropertyExpression[] properties) { //if(!properties.Any()) return new ExpandExpression(input, properties); //ResourceType type = (ResourceType)properties[0].Property.Parent; //foreach (PropertyExpression p in properties) //{ // if (type != p.Property.Parent) // return new ExpandExpression(input, properties); //} //QueryNode query = Sort(input, type.Key.Properties.Select(p => p.Property()).ToArray(), true, true); //return new ExpandExpression(query, properties); }
public static ThenByExpression ThenBy(this QueryNode input, PropertyExpression[] properties, bool bAscDesc, bool excludeFromUri) { QueryNode scaninput = input; while (!(scaninput is ScanExpression) && !(scaninput is PredicateExpression) && !(scaninput is NavigationExpression)) { scaninput = scaninput.Input as QueryNode; } if (input is ScanExpression || input is PredicateExpression || input is NavigationExpression) return new ThenByExpression(input, properties, input, bAscDesc, excludeFromUri); else return new ThenByExpression(input, properties, scaninput, bAscDesc, excludeFromUri); }
public virtual void Select() { PropertyExpression ordervalues = new PropertyExpression( this.ResType.Properties.Choose() ); if (_query is ScanExpression) _query = ((ScanExpression)_query).Select() as ProjectExpression; if (_query is NavigationExpression) _query = ((NavigationExpression)_query).Select() as ProjectExpression; if (_query is TopExpression) _query = ((TopExpression)_query).Select() as ProjectExpression; if (_query is SkipExpression) _query = ((SkipExpression)_query).Select() as ProjectExpression; if (_query is CountExpression) _query = ((CountExpression)_query).Select() as ProjectExpression; if (_query is ExpandExpression) _query = ((ExpandExpression)_query).Select() as ProjectExpression; if (_query is PredicateExpression) { int i = this.Engine.Options.Random.Next( 0, 2 ); if (bFilter) { i = 0; } switch (i) { case 0: _query = ((PredicateExpression)_query).Select() as ProjectExpression; break; case 1: if (ordervalues.Type is CollectionType) { this.ResType = (ResourceType)((ResourceCollection)ordervalues.Type).SubType; _pType = this.ResType.ClientClrType; } else if (ordervalues.Type is ResourceType) { this.ResType = (ResourceType)ordervalues.Type; _pType = ordervalues.Type.ClrType; } else _pType = ordervalues.Type.ClrType; _query = ((PredicateExpression)_query).Select( ordervalues ) as ProjectExpression; break; } } if (_query != null) { bSelect = true; _action = LastAction.Select; _isValid = isValid.Yes; AstoriaTestLog.WriteLineIgnore( ".Select()" ); this.Disabled = true; } }
public static NavigationExpression Nav(this QueryNode input, PropertyExpression property, bool isLink) { return new NavigationExpression(input, property, isLink); }