c# - Modify properties when class is created -
I have a number of controllers that remove the same value from the input value stdo
, as seen In the controller below.
// Controller Public Action Gateways (Statistics DTo studo) {var startDate = DateTime.Parse (stdo.Timespan.Substring (0, 10)); Var Enddate = DateTime Purse (stdo.Timespan.Substring (12)); // The rest of the controller functions ...}
What do I want to do, these two actions are done in the manufacturer of the StatisticsDTO
object, and then any other Added to property.
I tried to move lines into two separate constructors but the TimeSpan
value is always empty, is it possible or is there any other way to refact it?
public class statistics dtO {public string timespane {received; Set; } Public string country {get; Set; } Public string AppName {get; Set; } Public DataTime StartDate {Received; Set; } // new property public date expiration {received; Set; } // New property public statistics DTO () {this.StartDate = DateTime.Parse (TimePan. Substring (0, 10)); This.EndDate = DateTime.Parse (Timespan; Springing (12)); } Public Stats DTO (String Typpan, String Country, String API Name) {this.StartDate = DateTime.Parse (Timepain. Springing (0, 10)); This.EndDate = DateTime.Parse (Timespan; Springing (12)); }}
I hope that you will understand what I am after here.
Edit
Let me assume that I call this action to the client with the data variable $ ajax
$ Ajax ({Type: "GET", url: "/ Gateviews", Data: {Timepain: "01/01/01 - 02/02/02", Country: "US", APPName: "V1"}}) ;
These parameters have been translated into the StatisticsDTO
object when I become Stdo object, I want to get started with StartDate
and endDate
Want to set the properties in the constructor.
Your default constructor (i.e. paramamlas) can not work here because it is your timepan
runs before the asset is handed over. Remove it and other constructors should work fine.
However, you see this object being used as a MVC parameter, so a parametic constructor will not work. You can do this:
Public Date Time Start Date {Time Received Date Purse (timepin shuttleing (0, 10)); }} Public Datetime End Date {Get Date Date Purse (timepain substring (12)); }}
Alternatively, if you want to modify start / end date properties later, you can:
private String _timespan; Public string tympan {get {return_timespan; } Set {_timespan = value; StartDate = DateTime Percy (Timepain. Springing (0, 10)); Enddate = Datetime. Percy (TimePan. Substring (12)); }}
Comments
Post a Comment