protected internal override YqlCompiledNode CompileNode(YqlCompiler compiler) { if (List == null) { throw new ArgumentNullException("List"); } if (ItemToFind == null) { throw new ArgumentNullException("ItemToFind"); } var compiledList = List.CompileNode(compiler); var listType = compiledList.Expression.Type; YqlCompiledNode compiledItemToFind = null; Expression expression = null; if (listType.IsArray) { Type itemType = compiledList.Expression.Type.GetElementType(); compiledItemToFind = compiler.CoerceTo( ItemToFind.CompileNode(compiler), itemType ); expression = Expression.Call( Info_ContainsCallback.MakeGenericMethod(itemType), compiledList.Expression, compiledItemToFind.Expression ); } else if (listType == typeof(YamsterUserSet)) { compiledItemToFind = compiler.CoerceTo( ItemToFind.CompileNode(compiler), typeof(long) ); // list.FindUserById(itemToFind) != null expression = Expression.NotEqual( Expression.Call( compiledList.Expression, YamsterUserSet.Info_FindUserById, compiledItemToFind.Expression ), Expression.Constant(null) ); } else { ReportError("The expression type " + listType.Name + " is not a list"); } return(new YqlCompiledNode(this, expression, new[] { compiledList, compiledItemToFind })); }
public YqlCompiledNode CoerceTo(YqlCompiledNode compiledNode, Type desiredType, string messageIfFailed = null) { var actualType = compiledNode.Expression.Type; if (actualType == desiredType) { return(compiledNode); // nothing to do } if (messageIfFailed == null) { messageIfFailed = "The value should be of type " + actualType.Name + ", but instead is " + "actualType.Name"; } compiledNode.Node.ReportError(messageIfFailed); return(null); }
protected Expression CompileTargetExpression(YqlCompiler compiler, out YqlCompiledNode[] compiledArgs) { Type targetType = YamsterModel.GetModelClass(this.TargetObjectType); Expression targetExpression; if (TargetObject != null) { var compiledTargetObject = compiler.CompileNode(TargetObject); if (compiledTargetObject.Expression.Type != targetType) { ReportError("The target object is " + compiledTargetObject.Expression.Type.Name + ", which cannot be converted to " + targetType.Name); } targetExpression = compiledTargetObject.Expression; compiledArgs = new[] { compiledTargetObject }; } else { if (compiler.ModelType != TargetObjectType) { ReportError("This expression attempts to retrieve a {0} property from the" + " current context item, which is a {1} object", this.TargetObjectType, compiler.ModelType); } switch (compiler.ModelType) { case YamsterModelType.Thread: targetExpression = Expression.Property(compiler.ExecutionContextParameter, YqlExecutionContext.Info_Thread); break; case YamsterModelType.Message: targetExpression = Expression.Property(compiler.ExecutionContextParameter, YqlExecutionContext.Info_Message); break; default: throw new NotSupportedException(); } compiledArgs = new YqlCompiledNode[0]; } return(targetExpression); }
protected internal override YqlCompiledNode CompileNode(YqlCompiler compiler) { if (SourceString == null) { throw new ArgumentNullException("SourceString"); } YqlCompiledNode sourceStringNode = SourceString.CompileNode(compiler); // Get the body text TextMatcher textMatcher = new TextMatcher(this.searchText, this.WholeWords, this.MatchAllWords); Expression expression = Expression.Call(Expression.Constant(textMatcher), TextMatcher.Info_IsMatch, sourceStringNode.Expression); return(new YqlCompiledNode(this, expression, new[] { sourceStringNode })); }