R# 4.0.751: "Use object initializer" does not take all the properties in the initializer

I have the following code:

CdrDetail cdrDetail = new CdrDetail();
cdrDetail.TotalAmount = CalculateTotalPrice(...);
cdrDetail.VatAmount = CalculateVat(...);
cdrDetail.CurrencyCode = price.Currency.Code;

cdrDetail.NormalAmount = normalAmount;
cdrDetail.MinimumAmount = minimumAmount;
cdrDetail.SetupAmount = setupAmount;

ReSharper suggests to use an object initializer but when I do this only the
first line will be included in the object initializer:

CdrDetail cdrDetail = new CdrDetail {
TotalAmount = CalculateTotalPrice(...)
};
cdrDetail.VatAmount = CalculateVat(...);
cdrDetail.CurrencyCode = price.Currency.Code;

cdrDetail.NormalAmount = normalAmount;
cdrDetail.MinimumAmount = minimumAmount;
cdrDetail.SetupAmount = setupAmount;

Cheers

Gabriel Lozano-Moran

2 comments
Comment actions Permalink

Hello,

We appreciate your feedback. The corresponding JIRA request has been created,
and you are welcome to monitor its status at http://www.jetbrains.net/jira/browse/RSRP-61453.

You may want to check our request tracking policy here: http://www.jetbrains.net/confluence/display/ReSharper/ReSharperIssueTracker

Best regards,
- Development Team.


0
Comment actions Permalink

The same problem happens when you accidentally set a property twice like in
this sample:

BundleDetailInstanceTransaction transaction = new
BundleDetailInstanceTransaction();

transaction.TransactionType = BundleDetailInstanceTransactionType.Initial;
transaction.BundleDetailInstanceId = bundleDetailInstance.Id;
transaction.Created = DateTime.Now;
transaction.StartBalance = 0;
transaction.EndBalance = bundleDetailInstance.Credits;
transaction.BundleDetailInstanceId = bundleDetailInstance.Id;
transaction.ReferenceId = null;
transaction.TrafficType = TrafficType.Voice;

In the above code we set transaction.BundleDetailInstanceId twice therefore
when we use an object initializer through the quick fix feature we get this
code:

BundleDetailInstanceTransaction transaction = new
BundleDetailInstanceTransaction {
TransactionType = BundleDetailInstanceTransactionType.Initial,
BundleDetailInstanceId = bundleDetailInstance.Id,
Created = DateTime.Now,
StartBalance = 0,
EndBalance = bundleDetailInstance.Credits
};

transaction.BundleDetailInstanceId = bundleDetailInstance.Id;
transaction.ReferenceId = null;
transaction.TrafficType = TrafficType.Voice;

Regards

Gabriel Lozano-Moran



"Ilya Ryzhenkov" <orangy@jetbrains.com> wrote in message
news:76a2bd0b152dfd8ca540cd717071e@news.intellij.net...

Hello,

>

We appreciate your feedback. The corresponding JIRA request has been
created, and you are welcome to monitor its status at
http://www.jetbrains.net/jira/browse/RSRP-61453.

>

You may want to check our request tracking policy here:
http://www.jetbrains.net/confluence/display/ReSharper/ReSharperIssueTracker

>

Best regards,
- Development Team.

>


0

Please sign in to leave a comment.