expression

What is the purpose of LINQ's Expression.Quote method?

点点圈 提交于 2019-12-20 09:14:58
问题 The MSDN documentation states: Expression.Quote Method Creates a UnaryExpression that represents an expression that has a constant value of type Expression. I've been able to build predicate expressions for use in LINQ queries by manually constructing them using the Expression class, but have never come across the need for Expression.Quote. When and why would you use this? From the LINQ expressions I've seen that have them, they just seem to wrap existing expressions without adding any value.

What is the purpose of LINQ's Expression.Quote method?

限于喜欢 提交于 2019-12-20 09:13:36
问题 The MSDN documentation states: Expression.Quote Method Creates a UnaryExpression that represents an expression that has a constant value of type Expression. I've been able to build predicate expressions for use in LINQ queries by manually constructing them using the Expression class, but have never come across the need for Expression.Quote. When and why would you use this? From the LINQ expressions I've seen that have them, they just seem to wrap existing expressions without adding any value.

Using the Swift if let with logical AND operator &&

核能气质少年 提交于 2019-12-20 08:31:09
问题 We know that we can use an if let statement as a shorthand to check for an optional nil then unwrap. However, I want to combine that with another expression using the logical AND operator && . So, for example, here I do optional chaining to unwrap and optionally downcast my rootViewController to tabBarController. But rather than have nested if statements, I'd like to combine them. if let tabBarController = window!.rootViewController as? UITabBarController { if tabBarController.viewControllers

How to convert an Expression<Func<T, bool>> to a Predicate<T>

狂风中的少年 提交于 2019-12-20 08:24:31
问题 I have a method that accepts an Expression<Func<T, bool>> as a parameter. I would like to use it as a predicate in the List.Find() method, but I can't seem to convert it to a Predicate which List takes. Do you know a simple way to do this? public IList<T> Find<T>(Expression<Func<T, bool>> expression) where T : class, new() { var list = GetList<T>(); var predicate = [what goes here to convert expression?]; return list.Find(predicate); } Update Combining answers from tvanfosson and 280Z28, I am

Split a complex String based on grouping of small brackets in java

邮差的信 提交于 2019-12-20 07:46:09
问题 I have a complex string coming from the UI like: (region = "asia") AND ((status = null) OR ((inactive = "true") AND (department = "aaaa")) OR ((costcenter = "ggg") OR (location = "india"))) I need to split it and use it in my code, but I have to take into consideration the braces so that grouping occurs exactly as shown. After split, I have to get something like the following in each iteration and break it down First time: (region = "asia") AND ((status = null) OR ((inactive = "true") AND

Replace img elements src attribute in regex

本秂侑毒 提交于 2019-12-20 07:06:39
问题 Solved it in case anyone needs it here it is var feed = feeds.entries[i].content; var parsedFeed = feed.replace(/src=/gi, "tempsrc="); var tmpHolder = document.createElement('div'); tmpHolder.innerHTML=parsedFeed; I have a string containing html markup which include <img src='path.jpg'/> I would like to run a regex against the string to replace every src attr to tmpSrc so <img src='path.jpg'/> would turn into <img tmpSrc='path.jpg'/> this is in javascript by the way and here is the root issue

Regular expression to validate Excel cell

浪尽此生 提交于 2019-12-20 05:27:08
问题 I'm working on a php application where the user has to insert an Excel's cell id (for example A1 or AB32 ), a value which is stored in the database for later use and I'm trying to validate the cell id format using a regular expression, but it just doesn't seem to be working, this is what I've got so far. ^[a-zA-Z]\d$ 回答1: There's an awesome answer in this question by @BartKiers where he builds a function to construct these type of regexes that need to match ranges of x to y. His logic

C# Turning magic string into lambda expression

家住魔仙堡 提交于 2019-12-20 05:18:08
问题 I have a set of extension methods that allow for using magic strings in the LINQ OrderBy() methods. I know the first question will be why, but it's part of a generic repository and is there for flexibility so that strings can be sent from the UI and used directly. I have it working if you pass in a magic string that represents a property on the main entity you are querying, but I'm having trouble making it more generic so it can handle multiple levels deep magic string. For example:

Modifying Lambda Expression

对着背影说爱祢 提交于 2019-12-20 04:27:09
问题 I'm developing an application with NHibernate 3.0. I have developed a Repository hat accept a expression to do some filter with QueryOver. My method is something like this: public IEnumerable<T> FindAll(Expression<Func<T, bool>> filter) { return Session.QueryOver<T>().Where(filter).List(); } It works fine. So, I have a Service layer as well, and My methods in this services accepts primitives types, like this: public IEnumerable<Product> GetProducts(string name, int? stock, int? reserved) { //

Superscripts in heat plot labels in ggplot r

半世苍凉 提交于 2019-12-20 03:29:18
问题 Good morning, I am making a heat map in ggplot of correlations between specific phenotypes. I would like to label each tile with the R^2 for the association. I have a correlation matrix, max_all, which looks like this: phenolist2 pheno1 pheno2 pheno3 pheno4 pheno5 max.pheno1 pheno1 0.05475998 0.05055959 0.05056578 0.10330301 0.05026997 max.pheno2 pheno2 0.15743312 0.05036100 0.05151750 0.04880302 0.31008809 max.pheno3 pheno3 0.05458550 0.07672537 0.04043422 0.16845294 0.14268895 max.pheno4