Click here to Skip to main content
15,913,685 members
Home / Discussions / C#
   

C#

 
QuestionDynamically Insert A Property Into A LINQ Query Statement Pin
MadDashCoder17-May-16 9:56
MadDashCoder17-May-16 9:56 
AnswerRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
Sascha Lefèvre17-May-16 10:32
professionalSascha Lefèvre17-May-16 10:32 
GeneralRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
MadDashCoder17-May-16 10:34
MadDashCoder17-May-16 10:34 
GeneralRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
Sascha Lefèvre17-May-16 11:06
professionalSascha Lefèvre17-May-16 11:06 
AnswerRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
Dave Kreskowiak17-May-16 11:17
mveDave Kreskowiak17-May-16 11:17 
AnswerRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
Matt T Heffron17-May-16 12:22
professionalMatt T Heffron17-May-16 12:22 
GeneralRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
MadDashCoder17-May-16 13:11
MadDashCoder17-May-16 13:11 
GeneralRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
Matt T Heffron17-May-16 14:51
professionalMatt T Heffron17-May-16 14:51 
This still suffers from the problems that I mentioned.
It isn't even close to type-safe.
You'll get a NullReferenceException if the toyId isn't found, unless both price and color are null, in which case you'll never know!
For the "price" case, if the string is not a valid double, it will throw a FormatException (or, less likely, OverflowException).
This is the wrong place in a design to be parsing the price value string to double!
It ought to be done as near as possible to where the user provides the input so it can be reported appropriately.

Finally, in fact, you did not "dynamically choose a property to be inserted into a LINQ query at runtime".
You're choosing different properties of the result of identical LINQ queries based on boolean conditions represented by string values being null or not.

I would consider this abuse of the indexer to gain a syntactic shortcut of very dubious value.

So lesson learned.
Don't do this in production code!
(Or any code! Wink | ;) )

This is serious "code smell".
I'm sorry, but it needed to be said. Dead | X|
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton

AnswerRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
Gerry Schmitz19-May-16 6:41
mveGerry Schmitz19-May-16 6:41 
QuestionHow record behavior of a process in windows? Pin
saeedmir17-May-16 7:26
saeedmir17-May-16 7:26 
AnswerRe: How record behavior of a process in windows? Pin
BillWoodruff17-May-16 7:46
professionalBillWoodruff17-May-16 7:46 
GeneralRe: How record behavior of a process in windows? Pin
saeedmir17-May-16 7:52
saeedmir17-May-16 7:52 
GeneralRe: How record behavior of a process in windows? Pin
Eddy Vluggen17-May-16 8:03
professionalEddy Vluggen17-May-16 8:03 
Rant[REPOST] How record behavior of a process in windows? Pin
Richard Deeming17-May-16 7:49
mveRichard Deeming17-May-16 7:49 
QuestionObject is currently in use elsewhere C# - System.Drawing Exception Pin
Django_Untaken16-May-16 21:56
Django_Untaken16-May-16 21:56 
AnswerRe: Object is currently in use elsewhere C# - System.Drawing Exception Pin
Pete O'Hanlon16-May-16 23:09
mvePete O'Hanlon16-May-16 23:09 
Question[Updated] AnyCPU and exposing functionality via COM Pin
Matt T Heffron16-May-16 13:51
professionalMatt T Heffron16-May-16 13:51 
AnswerRe: AnyCPU and exposing functionality via COM Pin
Garth J Lancaster16-May-16 16:28
professionalGarth J Lancaster16-May-16 16:28 
GeneralRe: AnyCPU and exposing functionality via COM Pin
Matt T Heffron17-May-16 7:20
professionalMatt T Heffron17-May-16 7:20 
Questionsearch quickly Pin
Denis Tarasov16-May-16 13:26
Denis Tarasov16-May-16 13:26 
AnswerRe: search quickly Pin
OriginalGriff16-May-16 19:27
mveOriginalGriff16-May-16 19:27 
QuestionHow to create http client server application in C#? Pin
Jaimesh.241115-May-16 21:23
Jaimesh.241115-May-16 21:23 
AnswerRe: How to create http client server application in C#? Pin
Richard MacCutchan15-May-16 22:31
mveRichard MacCutchan15-May-16 22:31 
QuestionHow can i protect c# .net Code to be decompile? Pin
Member 1243103913-May-16 6:39
Member 1243103913-May-16 6:39 
AnswerRe: How can i protect c# .net Code to be decompile? Pin
Eddy Vluggen13-May-16 7:12
professionalEddy Vluggen13-May-16 7:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.