I really did no expect that.

ReSharper is crazy

Is said to in Europe, every man has an average of omega replica three watches, and to pay attention to the instrument famous Italy the average man watch has reached eight, these watches can mix and match clothing, to cope with a variety of uk replica watches occasions need. Here we are not talking about the fashion of men in Italy wear what table, but to explore the famous British Agent 007 James Bond in the film wearing what table. Isn't James Bond fashionable? The answer is obviously negative. Rolex Rolex, Omega and Seiko, is the most popular 007 favored brand, these brands period alternating from one side reflects the development path of rolex uk brand watches, and watch the performance in the film also a good interpretation of the brand connotation and the personality. ROLEX Rolex, OMEGA OMEGA and SEIKO precision, is the most popular brand of 007

While writing up an answer for a Stack Overflow question I had a code like this:

foreach (var property in sourceType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
    if (!property.CanRead)

    var targetProperty = targetType.GetProperty(property.Name, BindingFlags.Public | BindingFlags.Instance);
    if (targetProperty != null
            && targetProperty.CanWrite
            && targetProperty.PropertyType.IsAssignableFrom(property.PropertyType))
                Expression.Property(targetVariable, targetProperty),
                    Expression.Property(sourceVariable, property), targetProperty.PropertyType)));

Nothing overly complicated, but not the simplest thing either. Then I noticed a green squiggly line under the foreach. Apparently, ReSharper can convert that code into a LINQ-expression. That's interesting, I wondered, how would the result look like? Like this:

    (from property in sourceType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
        where property.CanRead
        let targetProperty = targetType.GetProperty(property.Name, BindingFlags.Public | BindingFlags.Instance)
            targetProperty != null && targetProperty.CanWrite
            && targetProperty.PropertyType.IsAssignableFrom(property.PropertyType)
                Expression.Property(targetVariable, targetProperty),
                Expression.Convert(Expression.Property(sourceVariable, property), targetProperty.PropertyType))).

Okay, the final Cast() is unnecessary (and ReSharper itself knows that and offers you to remove it), but otherwise, great job!

In the end, I chose not to use LINQ here, but it's good to know the option is there and it's so easy.

c# resharper
Posted by: Petr Onderka
Last revised: 23 Oct, 2016 10:11 PM History


31 Oct, 2012 07:56 AM

Hi i have had an .net exe written for me and have been using it for about 3 years... i am not a developer

but i do have questions and need some help here and there.......i was searching for an understanding of a line in my config file and saw some of your commentary

i wonder if you can help

i live in australia. kind regards denis

07 Nov, 2012 11:04 PM

I'm sorry, I don't have much time lately, so I'm afraid I can't help you.

15 Jan, 2013 09:14 PM

It must have been very much fun to write this R# transformation as a dev at Jetbrains.

Vincy Chen
Vincy Chen
17 Jul, 2014 12:35 PM

Dear Stack Exchange User,

I am a MA student in HKU, hoping to get your help with my project of Online Knowledge Sharing. For more details of my project, please kindly see this link: https://drive.google.com/file/d/0BwxpA83ulrhXYVJhNm0xd3Fma2s/edit?usp=sharing

Best regards, CHEN Yongsi, Vincy

McMile Technologies
McMile Technologies
11 Apr, 2015 10:09 AM

Hello Svick,

I am Katheline Collins, legal and dispute resolution manager at McMile Technologies, inc from UK.

Our developpers would like to have a talk with you regarding alleged plagiarism in one of your productts and our consequential loss. Would you mind if we contact you by skype telephone? What would be the best Czech time and date for you?


Katheline Collins Legal and Dispute Resolution Manager (LDR) McMile Technologies, inc ldr-mcmiletec@gmail.com

Your Comments

Used for your gravatar. Not required. Will not be public.
Posting code? Indent it by four spaces to make it look nice. Learn more about Markdown.