Does safe delete work in combination with object initializers?

Hello

I don't know if I am doing something wrong but assume that you have the
following class:

public class Customer
{
public string Name { get; set;}
public string FirstName {get; set;}
}

and assume that in some other class I create a new instance of the Customer
class using the object initializer method like this:

var customer = new Customer { Name = "Lozano-Moran", FirstName =
"Gabriel" };

Now when I try to safe-delete (]]>) the property FirstName I
always get a "conflict" where I have used the object initializer. Does this
mean that ReSharper does not support safe deleting properties that are in
use in object initializers?

Cheers

Gabriel Lozano-Moran


1 comment
Comment actions Permalink

Hello Gabriel Lozano-Moran,

It is not always safe to delete properties like that. For example, initialization
expresion could have side effects and blindly removing it can change code
semantics. I admit, ReSharper could be smarter in some cases. Like, if property
is auto-property, and used only in object initializers, and all expressions
are known to not have side effects - remove silently.

Could you please file an issue in our tracker? Thanks.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


G> Hello
G>
G> I don't know if I am doing something wrong but assume that you have
G> the following class:
G>
G> public class Customer
G> {
G> public string Name { get; set;}
G> public string FirstName {get; set;}
G> }
G> and assume that in some other class I create a new instance of the
G> Customer class using the object initializer method like this:
G>
G> var customer = new Customer { Name = "Lozano-Moran", FirstName =
G> "Gabriel" };
G>
G> Now when I try to safe-delete () the property FirstName G> I always get a "conflict" where I have used the object initializer. G> Does this mean that ReSharper does not support safe deleting G> properties that are in use in object initializers? G> G> Cheers G> G> Gabriel Lozano-Moran G>]]>


0

Please sign in to leave a comment.