How do I replace text from second capture group - vim

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..

Related

LinqToExcel - InvalidCastException leading to Object must implement Iconvertible error

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!

Code generated properties in AutoMapper mappings

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?

Parsing YouTube Json for Windows Store apps

I generate C# Class from http://json2csharp.com/ for any YouTube URL, in which some names are invalid like as follows:
public class Feed
{
public string __invalid_name__xmlns$media { get; set; }
public string __invalid_name__gd$etag { get; set; }
}
In the above code actual Youtube name is xmlns$media, gd$etag like that...
when I change those to:
public class Feed
{
public string xmlns$media { get; set; }
public string gd$etag { get; set; }
}
in C# it shows error because of special character $, If I don't use $ parsing doesn't happens and returns Null.
Help me fixing this!
Does this work for you?
[DataContract]
public class Feed
{
[DataMember(Name="xmlns$media")]
public string xmlns_media { get; set; }
[DataMember(Name="gd$etag")]
public string gd_etag { get; set; }
}

How to get a property from a Model when writing a display template

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.

Resharper clean code line breaks with properties and fields

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.

Resources