Here is my issue. I want to put line breaks between properties and not fields.
Here is what I am getting:
private string _field1;
private string _field2;
private string _field3;
public string Property1 { get; set; }
public string Property2 { get; set; }
public string Property3 { get; set; }
Here is what I want:
private string _field1;
private string _field2;
private string _field3;
public string Property1 { get; set; }
public string Property2 { get; set; }
public string Property3 { get; set; }
Does anyone have an idea how to get Resharper to have this type of line breaks? What I currently have is that the Resharper puts lines breaks between all of fields and properties or no line breaks. I cannot seem to find the right settings to get what I want.
Go to ReSharper|Options and under Code Editing, navigate to C#→Formatting Style→Blank Lines. Now, you need to change two separate options:
Change the Keep max blank lines in code value to 0 (zero)
Change the Around single line field value to 0 (zero)
... and you're done!
You may also need to ensure that Keep existing line breaks is not checked under Line Breaks and Wrapping.
Related
I have attributes in a c# file like so, all are gauranteed to be on their own line
[DataType("Checkbox")]
public bool SomeCheckBox { get; set; }
[DataType("Text")]
public string SomeText { get; set; }
Using VSVIM I want to do a search and replace so that the code looks like this
[DataType(Control.Checkbox)]
public bool SomeCheckBox { get; set; }
[DataType(Control.Text)]
public string SomeText { get; set; }
I tested this pattern in regex101 and it seemed to worked, but can't seem to translate it into VSVIM. VSVIM says the pattern didn't match anything.
%s/(?<=\[DataType\(").*?(?="\)\])/[DataType(Control.\1)]/g
Basically I want to remove the quotes and prefix the second capture group with Control..
I'm using the following code to query an excel file in LinqToExcel:
var excelFile = new LinqToExcel.ExcelQueryFactory(#"\"+txtFileName.Text.Replace(#"\\",#"\"));
var properties = from p in excelFile.Worksheet<Property>()
where AssessmentID != null
select p;
foreach (var autoP in properties)
doSomething();
When I look at the runtime debugger, I see an "InvalidCastException" while looking at the "Results View" of the properties variable. So, I'm assuming that there's something funky going on with my class definition. I'm also assuming that I don't need to map all members of the class to the excel file, but rather only the ones I see fit.
So, Here's the class definition as well:
public class Property
{
[DataMember]
public int? Year { get; set; }
[DataMember]
public string ChangeReason { get; set; }
[DataMember]
public string AssessmentID { get; set; }
[DataMember]
public string CallBackNotes { get; set; }
[DataMember]
public string InspectionNotes { get; set; }
[DataMember]
public string Notes { get; set; }
[DataMember]
public bool Authorization { get; set; }
[DataMember]
public string ChargeStatus { get; set; }
[DataMember]
public string LegalLandDesc { get; set; }
[DataMember]
public string Address { get; set; }
}
Here's a link to the source code for linqToExcel on GitHub:LinqToExcel
The generics are more complicated than I've seen, and are something that I (apparently) need to brush up on.
Is there something glaring that I'm missing that would cause this issue? Any ideas as to where to look or what to do to resolve these errors?
The where clause of the query is what was causing the error. It was referencing the null keyword which was not applicable in the context.
I changed it to:
where !String.IsNullOrEmpty(p.AssessmentID)
This solved my issue.
Note to self: When inheriting code from others, check the basics first!
I have an Entity called Artist that looks like this:
public class Artist
{
public int Id { get; set; }
public string FName { get; set; }
public string LName { get; set; }
public string UrlFriendly { get; set; }
}
And my Artist View Model looks exactly the same, except it is named ArtistVM.
Notice the UrlFriendly property. I want this property to be generated through code. I would like all letters with accents ... etc to be replaced with their English equivalent and also to be turned into lower case.
For example the name Édith Piaf would become edith-piaf.
Ignoring Automapper and the accented letters, I know how to do the rest like so:
artist.FName.ToLower() + "-" + artist.LName.ToLower();
But is there a way I can configure AutoMapper Mappings to do this for the UrlFriendly property when mapping from ArtistVM to Artist?
I have a model...
public class PatientACOModel
{
public int EncounterId { get; set; }
public int PatientId { get; set; }
public int EMPIID { get; set; }
public int PopulationPatientID { get; set; }
public string EditAddOrEditCurrent { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime? DateOfBirth { get; set; }
//[UIHint("_PhoneNumFormatter")]
public string Phone { get; set; }
}
I want to specifically format my phone numbers. I just want to put a UIHint over my phone number and possibly other phone numbers. I don't want all strings to be formatted.
I am trying things like this...
#Model String
#if (Model != null) {
String.Format("{0: (###) ###-####}", double.Parse(Model.ModelMetadata.Get));
}
That would be the display template referenced in my UIHint that is commented out.
When I do that, none of my strings show up. What am I doing wrong?
In my display template how do I get the string to parse and then Format?
First I would check if the _PhoneNumFormatter is defined in one of the following locations:
~/Views/Shared/DisplayTemplates/_PhoneNumFormatter.cshtml
~/Views/<Controller>/DisplayTemplates/_PhoneNumFormatter.cshtml
Next I think you wanted to format the string value directly from the Model property:
#model String
#if (!String.IsNullOrWhiteSpace(Model))
{
#String.Format("{0: (###) ###-####}", Convert.ToInt64(Model))
}
This should work fine with the UIHint attribute, I've just checked in a sample application.
Code assumes that numbers in your region don't start with a leading 0 and that the Model property will contain strings containing only numeric characters, if not you should improve the Convert.ToInt64 part.
Hope it helps.
My project is the throwing the above error because the Ship Date in my table is null. I am using Code First, and the DateTime field is declared as nullable both in the generic set and the SQL table. I am populating a gridview with the result set. Ideally, I would like to have the gridview display "not yet shipped" when the ShipDate field is null, but at this point, I would be happy just to be able to display the record. Any help is greatly appreciated. Here is the code-behind and the context class that I am using:
public class Order
{
[Key]
public int OrderID { get; set; }
public int CustomerID { get; set; }
public string ShipAddress { get; set; }
public string ShipCity { get; set; }
public string ShipState { get; set; }
public string ShipZip { get; set; }
[ScaffoldColumn(false)]
public string PaymentTransactionID { get; set; }
[ScaffoldColumn(false)]
public System.DateTime OrderDate { get; set; }
public System.DateTime? ShipDate { get; set; }
public virtual Customers Customers { get; set; }
public List<OrderDetail> OrderDetails { get; set; }
}
The code behind is:
public List<OrderDetail> FetchByOrderID()
{
int myOrderID = CusOrderId;
ProductContext db = new ProductContext();
return db.OrderDetails.Where(
c => c.OrderID == myOrderID).ToList();
}
I was getting the above error when trying to get the max(date_column) through LINQ. The column was defined as NOT NULL and when there are no rows returned in the query its trying to assign null to the DateTime property that's representing the date column. One solution is to change the date column to being NULLable which will create the entities property as type DateTime?
I use VB.Net, but had a similar problem. I do not know if you fixed your problem.
But I declared the variable as Nullable(Of Date) and that did the trick to me. I am told that adding the "?" does the similar thing, but unfortunately did not work out for me, or I did not do it correctly. :o)
private DateTime? _settlementDate {get;set;}
I was having a similar problem, same error.
Turns out I failed to setup my ConnectionString in the configuration.