expression

How to make expression treat value type as a reference type?

风流意气都作罢 提交于 2019-12-21 18:41:10
问题 I wanted to store a collection of expressions accessing object's properties. For example: class Entity { public int Id { get; set; } public Entity Parent { get; set; } public string Name { get; set; } public DateTime Date { get; set; } public decimal Value { get; set; } public bool Active { get; set; } } static void Main(string[] args) { var list = new List<Expression<Func<Entity, object>>>(); list.Add(e => e.Id); list.Add(e => e.Name); list.Add(e => e.Parent); list.Add(e => e.Date); list.Add

Expression tree depth limitations

假如想象 提交于 2019-12-21 17:39:03
问题 I'm facing a problem trying to call Compile() on the LambdaExpression of type Expression<Func<MyType, bool>> which has a depth around 400. And lesser values do not cause any problems. And I can't find anything about such kind of limitation. Can anyone clarify this? Can I increase this limit? upd: Sorry, forgot to mention, I'm getting StackOverflowException: An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll {Cannot evaluate expression because the

Transform LINQ IQueryable into a paged IQueryable using LINQ to NHibernate

▼魔方 西西 提交于 2019-12-21 17:36:26
问题 I wanna do something like that public IQueryable GetPaged<TSource>(IQueryable<TSource> query, int startIndex, int pageSize) { return GetSession() .Linq<TSource>() .UseQuery(query) .Take(pageSize) .Skip(startIndex); } So you can put any IQuerable statement and "it becomes paged" or it will be paged. I am using LINQ to NHibernate. I hope you get it, sry for this bad english :o edit: Maybe my approach is the wrong one, is it? 回答1: This is copied from working code: public static class

Are there any libraries for parsing “number expressions” like 1,2-9,33- in Java

我与影子孤独终老i 提交于 2019-12-21 15:24:22
问题 I don't think it is hard, just tedious to write: Some small free (as in beer) library where I can put in a String like 1,2-9,33- and it can tell me whether a given number matches that expression. Just like most programs have in their print range dialogs. Special functions for matching odd or even numbers only, or matching every number that is 2 mod 5 (or something like that) would be nice, but not needed. The only operation I have to perform on this list is whether the range contains a given

How to combine two expressions: result = exp1(exp2);

[亡魂溺海] 提交于 2019-12-21 12:40:50
问题 As subject, how to combine two expressions into a single one for this case: Expression<Func<IEnumerable<T>, IEnumerable<T>>> exp1; Expression<Func<IEnumerable<T>, IEnumerable<T>>> exp2; Expression<Func<IEnumerable<T>, IEnumerable<T>>> result = ???; // exp1(exp2) 回答1: This is really just a specific form of combining two Expression<Func<T, T>> values. Here's an example of doing that: using System; using System.Linq.Expressions; public class Test { public static Expression<Func<T, T>> Apply<T>

Finding Points in Contours

落爺英雄遲暮 提交于 2019-12-21 06:14:31
问题 So here is the code that i used to detect the contours : IplImage* DetectAndDrawQuads(IplImage* img) { CvSeq* contours; CvSeq* result; CvMemStorage *storage = cvCreateMemStorage(0); IplImage* ret = cvCreateImage(cvGetSize(img), 8, 3); IplImage* temp = cvCreateImage(cvGetSize(img), 8, 1); cvCvtColor(img, temp, CV_BGR2GRAY); cvFindContours(temp, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); while(contours) { result = cvApproxPoly(contours, sizeof

Notepad ++ How to remove all characters after a string

强颜欢笑 提交于 2019-12-21 05:49:28
问题 I'm using regular expression in Notepad++, trying to delete everything after a particular word. For example here is my text: Bull01 blah blah Bull02 Blah blah Bull03 Blah Bull04 Blah Bull05 Blah ** Bull300 Blah blah blah etc.. Im trying to delete everything after the word Bull , so that my results ends up being just Bull . I thought it was as simple as searching for Bull.* but that deletes the whole row, including the word Bull . 回答1: Use a look behind: Search: (?<=Bull).* Replace: <blank>

expected primary-expression before ‘const’ errors

你。 提交于 2019-12-21 04:33:41
问题 Please help. I am getting many errors. sub2.cpp: In function ‘int main()’: sub2.cpp:11:14: error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive] sub2.cpp:12:14: error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive] sub2.cpp:16:17: error: expected primary-expression before ‘const’ sub2.cpp:16:36: error: expected primary-expression before ‘const’ sub2.cpp:11:6: warning: unused variable ‘outer’ [-Wunused-variable] sub2.cpp:12:6: warning: unused variable ‘inner’ [

Expression.Or, The parameter 'item' is not in scope

青春壹個敷衍的年華 提交于 2019-12-21 01:07:13
问题 I am trying to write a static function to Or two expressions, but recieve the following error: The parameter 'item' is not in scope. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: The parameter 'item' is not in scope. the method: public static Expression<Func<T, bool>> OrExpressions

Using if (!!(expr)) instead of if (expr)

两盒软妹~` 提交于 2019-12-20 10:28:30
问题 While reading the example code provided by Texas Instruments for their SensorTag I came across the following snippet. void SensorTagIO_processCharChangeEvt(uint8_t paramID) { ... if (!!(ioValue & IO_DATA_LED1)) { PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_ON); } else { PIN_setOutputValue(hGpioPin, Board_LED1, Board_LED_OFF); } if (!!(ioValue & IO_DATA_LED2)) { PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_ON); } else { PIN_setOutputValue(hGpioPin, Board_LED2, Board_LED_OFF); } if