Hi
Consider the following class;
C#using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VtlFishTracker
{
class VtlInvoicePayment
{
public int InvoiceId { get; set; }
public int CustomerId { get; set; }
public DateTime InvoicePaymentDate { get; set; }
public decimal AmountPaid { get; set; }
public int PaymentTypeId { get; set; }
public string ChequeNumber { get; set; }
public DateTime? ChequeDate { get; set; }
public int? BankAccountId { get; set; }
public int? InvoiceCreditNoteId { get; set; }
public decimal? ConversionFactor { get; set; }
public bool? MultipleInvoicesPaid { get; set; }
public bool? PaidIntoBank { get; set; }
public VtlInvoicePayment()
{
}
}
}
if after I have entered the properties I type cc and then space and ensure that none of the parameters are selected in the smart constructor I end up with the standard constructor as seen.
Now suppose that I want an overloaded constructor with some of the properties as optional parameters in the constructor. When I type cc and select all in the smart constructor it creates all of the parameters but when I then try to assign a value it acts as if I am renaming the parameter (which is not what I want), see the attached movie.
Am I doing something wrong here, or is it not possible to use the smart constructor if one wants optional parameters in a constructor?
Many thanks
Dom
Hi Dom,
Thank you for pointing out this issue and providing the code sample. We have reproduced this issue.
We believe that you are right, Smart Constructor should provide the capability to add a default value in this case and not change a linked value.
So, we will research this and let you know when we make any progress.
Many Thanks Pavel.
Dom
You are always welcome, Dom!
Does the fix allow for the creation of optional parameters, or does it just fix the issue where parameters and values were being altered at the same time?
Dom
Hi Dom,
The fixed version does not change the linked value in the constructor body when you define a default value for a parameter.
Would you please describe in detail what you mean by "allow for the creation of optional parameters" ?
Hi Pavel
I guess the problem is that prolonged use of CodeRush makes one lazy!!
If you look at the original class code above you'll see that the last few properties are nullable types. In essence I'm hoping that it would be possible for code rush to automatically assign null values to those in the constructor's signature, thus making them optional.
Pure laziness on my part I know…but isn't that what CodeRush is for?
Dom
Thank you for the clarification, Dom!
We believe that we can add an option for Smart Constructor to generate optional parameters where it make sense.
I have added this request to our product backlog, so we will consider it when we plan future releases.