Can I change the way ReSharper generates properties? - resharper

Is it possible to change the way that Resharper formats properties?
I don't like:
public string Foo
{
get
{
return bar;
}
set
{
bar = value;
}
}
I like:
public string Foo
{
get { return bar; }
set { bar = value; }
}

You sure can, just go to Resharper > Options > Languages > C# > Formatting Style
and tick "place simple property/indexer/event declaration on a single line"
Updated for Resharper 8.2:
Resharper > Options > Code Editing > C# > Formatting Style > Line Breaks and Wrapping > Other > Place simple property/indexer/event declaration on single line

If you're using the code expansion template to produce a property, you can update the template in the ReSharper Settings at: ReSharper >> Live Templates >> Predefined Templates >> C# >> prop.
If you're referring to the code produced by refactoring commands, I don't believe it's configurable. However, you may be able to run Code Cleanup and have it reformat.

Related

text field attributes/methods dynamics crm 2011

I'm looking a method or way how to check that the text field in crm form is "null"
I've got a tab, there are section and text field inside of it;
furthermore, I'm using that function in order to hide/show tab.
function setVisibleTabSection(tabname, TextFieldName, show) {
var tab = Xrm.Page.ui.tabs.get(tabname);
if (tab != null) {
if (TextFieldName == null)
tab.setVisible(show);
else {
var section = Xrm.Page.data.entity.attributes.get(TextFieldName).getValue();
if (section != null) {
show == true;
tab.setVisible(show);
}
}
}
}
however, It doesn't work. There is nothing inside of the text box, and the tab expanded anyway.
by the way, parameters, which I give the function: "tab_8", "new_conf_report", false
where the secon one the name of the text field
Try
if (section != null && section !="")...
You may find that a field which is initially blank is null, whereas one from which you have deleted content but not yet saved the form is simply an empty string.
Certainly worth a shot.
show==true
is incorrect as others have pointed out (needs to be show=true) but is simply redundant as written inside the same IF statement, just replace next line as:
tab.setVisible(true);
It is possible you intended "show" to be the default tab state to use if text field is not empty, in which case just move this line outside the IF instead of changing it (as shown below)
It looks like the construction using the third "show" parameter is to allow you to use the function to set the tab state to a specific state of shown or not without looking for a text field value at all. You would need to pass parameters as eg tabname,,true - you might consider swapping the TextFieldName and Show parameters so it is easier to just drop the third rather than remember to double-comma.
While we're fixing stuff, lets replace that variable "section" with something with a more meaningful name:
function setVisibleTabSection(tabname, show, TextFieldName) //usage: show is state Tab will have if no TextFieldName is specified, or if text field is empty
{
var tab = Xrm.Page.ui.tabs.get(tabname);
if (tab != null)
{
if (show==null){show=true;}
if (TextFieldName == null)
{
tab.setVisible(show);
}
else
{
var strFieldValue = Xrm.Page.data.entity.attributes.get(TextFieldName).getValue();
if (strFieldValue != null && strFieldValue !="")
{show=true;}
tab.setVisible(show);
}
}
}
I don't see anything wrong with your Javascript (besides what Guido points out, which basically will only set the tab to visible if you pass in true for show). Use the debugging tool within IE by pushing F12, and set a break point at the top of your function to see where your logic is failing.
If you've never debugged javascript before, see http://social.technet.microsoft.com/wiki/contents/articles/3256.how-to-debug-jscript-in-microsoft-dynamics-crm-2011.aspx
or
How to debug jScript for Dynamics CRM?
I think there is a typo in the code:
show == true;
actually the code (assuming "=" instead of "==") will show always the tab if TextFieldName isn't empty, removing that line will show/hide the tab according to show parameter value
It seems to work when I run it but I'm not sure what you'd expect it to do so it might not be working the way you'd like it to. :)
function setVisibleTabSection(tabName, textFieldName, show) {
var tab = Xrm.Page.ui.tabs.get(tabName);
if(!tab) return;
if (!TextFieldName)
tab.setVisible(show);
else {
var section = Xrm.Page.data.entity.attributes.get(textFieldName).getValue();
if (section)
tab.setVisible(true);
}
}

Is there a way to specify the initial cursor position in a Visual Studio item template?

When you add, for example, a class to a project by selecting Add > New Item > Visual C# Items > Class, the blinking text cursor inside the new class will be at row 1, column 1. Is there a way to modify the template so that the blinking cursor appears in a different location?
using System;
namespace SomeNamespace
{
class SomeClass
{
| <--- I'd like the blinking cursor to initially appear here
}
}
You want to use $END$. You can also make fields by surrounding other keywords with $$.
using System;
namespace $Namespace$
{
public class $ClassName$
{
$END$
}
}

Resharper live templates - inn & ifn

Do I have something similiar to intelij's "ifn" and "inn" live template in ReSharper?
("if not null" and "if null" templates )
Thanks.
ReSharper doesn't have these built in, but you can easily write them yourself.
Just go to ReSharper > Templates Explorer... > Surround Templates and add a new template with something like this:
if ($SELECTION$ == null)
{
throw new ArgumentNullException("$SELECTION$");
}
Then you can select something and hit Ctrl+E, U to surround the selection with your template:
In my case, I added it to the quicklist with the letter F.
If you want to be able to type ifn and press Tab, you need to add a Live Template. This can be done in the Template Explorer, under Live Templates, but the content has to be different:
if ($ARGUMENT$ == null)
{
throw new ArgumentNullException("$ARGUMENT$");
}
or maybe:
if ($ARGUMENT$ == null)
{
$END$
}
Then you can write ifn (if that was the shortcut you specified) and press Tab

Is there a way to change the text of checked/unchecked MCheckBox states?

How would I go about changing the default MCheckBox state text (currently I/0) to, for example, YES/NO or ON/OFF?
Mr. Daniel Kurka is the author for all the widget classes in MGWT. If the look & feel is not
fulfilling our requirement, We can edit those classes and rewrite them according to our requirement.Because they are open source. I done this on many classes like CellList,FormListEntry and MCheckBox. code for ON/OFF instead of I/O
public MyOwnCheckBox(CheckBoxCss css) {
this.css = css;
css.ensureInjected();
setElement(DOM.createDiv());
addStyleName(css.checkBox());
onDiv = DOM.createDiv();
onDiv.setClassName(css.on());
onDiv.setInnerText("ON");
getElement().appendChild(onDiv);
middleDiv = DOM.createDiv();
middleDiv.setClassName(css.middle());
Element middleContent = DOM.createDiv();
middleContent.setClassName(css.content());
middleDiv.appendChild(middleContent);
getElement().appendChild(middleDiv);
offDiv = DOM.createDiv();
offDiv.setClassName(css.off());
offDiv.setInnerText("OFF");
getElement().appendChild(offDiv);
addTouchHandler(new TouchHandlerImplementation());
setValue(true, false);
}
Write a new class like MyOwnCheckBox.just copy the code in MCheckBox and paste in your class MyOwnCheckBox, find and replace the MCheckBox with MyOwnCheckBox in the code(change constructor's name). do the following changes.
onDiv.setInnerText("ON");
offDiv.setInnerText("OFF");
and finally create object to MyOwnCheckBox rather MCheckBox, it'll shows MCheckBox with ON/OFF.
Right now there is no way to do that, but there is no real reasons that checkbox does not implement HasText other than we might need to update the css so that big text will not break the layout.
If you think mgwt should implement this go and vote for this issue: http://code.google.com/p/mgwt/issues/detail?id=171
Well, an easy way to accomplish the same thing, without creating a new class that mimics MCheckBox, is to do something like the code below:
CheckBoxCss css = MGWTStyle.getTheme().getMGWTClientBundle().getCheckBoxCss();
String offClass = css.off();
String onClass = css.on();
NodeList<Node> checkBoxElems;
mIsSingleSkuBox = new MCheckBox(css);
checkBoxElems = mIsSingleSkuBox.getElement().getChildNodes();
for( int i = 0; i < checkBoxElems.getLength(); i++ )
{
Element openElem = (Element) checkBoxElems.getItem(i);
String className = openElem.getClassName();
if( className.equals( offClass))
{
openElem.setInnerText("No" );
}
else if( className.equals( onClass))
{
openElem.setInnerText("Yes" );
}
}
It will probably have space problems with anything longer than 3 characters, but it works consistently with "Yes" and "No" for me.

Make ReSharper reformat code according to StyleCop rule SA1206: The 'static' keyword must come before the 'other' keyword in the element declaration

I suspect I should create a pattern in ReSharper / Options / Languages / C# / Formatting Style / Type Membership Layout for this. I am currently using the default pattern and I would like some help from someone who is good at them.
I want this to be WRONG:
public new static Age Empty {
get {
return empty;
}
set {
empty = value;
}
}
And this to be right:
public static new Age Empty {
get {
return empty;
}
set {
empty = value;
}
}
In other words, I want static to come before other keywords, like new. Currently ReSharper 5.1 does it the "wrong" way.
ReSharper now has the possibility to configure the arrangement of modifiers.
Open the ReSharper options and go to Code Editing | C# | Code Style. In the Modifiers section Modifiers order you can reorder the arrangement according to your needs (see ReSharper online help: Arranging Modifiers).
To satisfy StyleCop's rule SA1206 move the static modifier above the new modifier:
It is impossible.

Resources