Click here to Skip to main content
15,895,667 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: How is the express module both a function/method AND an object with properties? Pin
DaveAuld9-Jun-16 7:35
professionalDaveAuld9-Jun-16 7:35 
GeneralRe: How is the express module both a function/method AND an object with properties? Pin
Mark_Wallace9-Jun-16 9:46
Mark_Wallace9-Jun-16 9:46 
GeneralHey Marc Clifton! Pin
#realJSOP9-Jun-16 6:53
mve#realJSOP9-Jun-16 6:53 
GeneralRe: Hey Marc Clifton! Pin
Kevin Marois9-Jun-16 7:31
professionalKevin Marois9-Jun-16 7:31 
GeneralRe: Hey Marc Clifton! Pin
Kevin Marois9-Jun-16 7:37
professionalKevin Marois9-Jun-16 7:37 
GeneralRe: Hey Marc Clifton! Pin
#realJSOP9-Jun-16 8:36
mve#realJSOP9-Jun-16 8:36 
GeneralRe: Hey Marc Clifton! Pin
Vincent Blais9-Jun-16 8:02
professionalVincent Blais9-Jun-16 8:02 
GeneralRe: Hey Marc Clifton! Pin
Richard Deeming9-Jun-16 8:32
mveRichard Deeming9-Jun-16 8:32 
Not sure you really need let in that example:
C#
public static IEnumerable<T> FindExact<T>(this IEnumerable<T> list, string valuePropertyName, string text)
{
    IEnumerable<T> found = Enumerable.Empty<T>();

    try
    {
        PropertyInfo info = typeof(T).GetProperty(valuePropertyName);
        if (info != null && info.CanRead && info.PropertyType == typeof(string) && info.GetIndexParameters().Length == 0)
        {
            found = list.Where(item => item != null && (string)info.GetValue(item, null) == text).ToList();
        }
    }
    catch (Exception)
    {
    }
    
    return found;
}

As Vince said, it's probably better to use IEnumerable<T>, rather than a List<T>. You can still eagerly evaluate the sequence to prevent exceptions from being thrown during enumeration.

You can eliminate most of the exceptions be checking that the property is found, can be read, returns a string, and doesn't have any index parameters; and by checking that the item is not null.

And I'd be inclined to return an empty sequence if the property is invalid or you get an exception, so that you don't have to check the returned value for null all the time.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Hey Marc Clifton! Pin
#realJSOP9-Jun-16 8:38
mve#realJSOP9-Jun-16 8:38 
GeneralRe: Hey Marc Clifton! Pin
Richard Deeming9-Jun-16 9:33
mveRichard Deeming9-Jun-16 9:33 
GeneralRe: Hey Marc Clifton! Pin
Dan Neely10-Jun-16 3:25
Dan Neely10-Jun-16 3:25 
GeneralRe: Hey Marc Clifton! Pin
Richard Deeming10-Jun-16 6:10
mveRichard Deeming10-Jun-16 6:10 
GeneralRe: Hey Marc Clifton! Pin
Vincent Blais9-Jun-16 8:42
professionalVincent Blais9-Jun-16 8:42 
GeneralRe: Hey Marc Clifton! Pin
#realJSOP10-Jun-16 2:05
mve#realJSOP10-Jun-16 2:05 
GeneralRe: Hey Marc Clifton! Pin
Richard Deeming10-Jun-16 6:07
mveRichard Deeming10-Jun-16 6:07 
GeneralRe: Hey Marc Clifton! Pin
Mark_Wallace9-Jun-16 13:50
Mark_Wallace9-Jun-16 13:50 
GeneralRe: Hey Marc Clifton! Pin
BillWoodruff9-Jun-16 15:35
professionalBillWoodruff9-Jun-16 15:35 
GeneralRe: Hey Marc Clifton! Pin
Middle Manager10-Jun-16 3:00
Middle Manager10-Jun-16 3:00 
GeneralMicrosoft's BITS file transfer tool fooled into malware distribution Pin
237419-Jun-16 6:33
237419-Jun-16 6:33 
GeneralRe: Microsoft's BITS file transfer tool fooled into malware distribution Pin
Pete O'Hanlon9-Jun-16 6:51
mvePete O'Hanlon9-Jun-16 6:51 
GeneralRe: Microsoft's BITS file transfer tool fooled into malware distribution Pin
237419-Jun-16 6:55
237419-Jun-16 6:55 
GeneralRe: Microsoft's BITS file transfer tool fooled into malware distribution Pin
Joe Woodbury9-Jun-16 8:28
professionalJoe Woodbury9-Jun-16 8:28 
GeneralRe: Microsoft's BITS file transfer tool fooled into malware distribution Pin
237419-Jun-16 8:35
237419-Jun-16 8:35 
GeneralRe: Microsoft's BITS file transfer tool fooled into malware distribution Pin
Joe Woodbury9-Jun-16 8:46
professionalJoe Woodbury9-Jun-16 8:46 
GeneralRe: Microsoft's BITS file transfer tool fooled into malware distribution Pin
Mark_Wallace9-Jun-16 13:52
Mark_Wallace9-Jun-16 13:52 

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.