Enum Intellisense Display Attribute? - c#

I want to do this:
enum Foo
{
[Display="Item One"]
ItemOne,
}
So that Intellisense will display it like in the attribute instead of the actual name.
I know it's possible, I've seen it before.

Well you could provide XML documentation:
enum Foo
{
/// <summary>Item One</summary>
ItemOne
}
I'm not sure whether that's quite what you were thinking of, but here's an example of what it looks like in VS 2010:
Note that I'm assuming you mean from the code editor... if you mean within a property editor, that could be something entirely different, e.g. DisplayNameAttribute (although that's meant for properties, events or methods).
If you know an example of what you want within the framework, we may be able to help more.

As a note... if you are building a .dll that is to be referenced by another application, just writing a summary will not allow the text to show up in intellisense for the referencing application. To accomplish this, you must deploy the XML documentation file as well, which requires a re-compiled version of the same .dll.
To do this (in VS2008 anyways), go into the Properties of your project, click the Build tab, click the checkbox at the bottom next to 'XML documentation file:', rebuild the application, and now you have the files needed to make it work.

Related

How to compile Item Template Project for Form with substitute parameters

I am trying to make an ItemTemplate for a Form. I create a "c# Item Tamplate"-Project, make my Form, and create my Template by Building the project. That works fine.
Now I want to add Templateparameters but as soon as I do, the project wont compile any more. It throws many different exceptions because the code is no longer valid. How can I solve this problem?
Here is what I tried so far:
Replacing every occurrence of my Classname with $safeitemname$. This, as I already said, throws exception because now the code is invalid and the project can not be built.
Creating CustomParameters in my .vstemplate to change a valid class name to my desired parameter (Classname -> $safeitemname$). This does nothing, even though I set "Replaceparameters="True"".
Ignoring the compiler warnings and implementing the project in my .vsix project anyway. This does nothing either, because the .zip for my template still can not be.
Setting DependentUpon of my Classname.Designer.cs to my Classname.cs. This does nothing either.
Trying a simple ItemTemplate with one class that's divided in two partial classes that have one Property each. Same thing as with the Form. It can no longer be build.
As Reza Aghaei suggested in his comment, the problem was, that I didn't set the build action for the files in my project to 'None'.

How do I automatically generate documentation/comments in Monodevelop?

Monodevelop automatically generates verbose documentation for functions and classes if "///" is typed in the appropriate place, upon typing the third '/'.
I want it to go over all of my code, though - I thought there was some button somewhere, and I looked around in the drop-down menus, tried right-clicking file names, etc.
I could not find such an option - does it not exist? I could not find a plugin that does that either.
Try to use Edit-> Document buffer.
It will make /// comments for all your public methods/classes without any comment upon it in current file.
It won't work if you have // comment upon method/class or for protected/private elements.
It is not possible. Your options are:
Manually typing three slashes before each and every function
Using an external tool
Online searches have not come up with any plugins for monodevelop that would do that, and the option does not exist in the vanilla IDE.

Is it good practise to remove Id tags from Controls that I don't reference in Code Behind

I'm wondering about a feature in Visual Studio. Personally it bugs me when I open a solution someone else has been working on and it's full of Controls with Ids like "label27" "textbox3" etc.
One of the first things I do is either rename them or remove them if they are never referenced in code behind (as is usually the case with the labels).
But I was just wondering why Visual Studio defaults them such meaningless values, then I started thinking if maybe it is better practise to have something in the Id field rather than blank it.
Of course the best situation is to give them all sensible names, but if I come across a project full of those auto generated Ids, am I doing the author a favour by removing them to "clean up" the solution?
I used to think so, but wouldn't the default for dragging and dropping or copying and pasting controls in be without an Id?
I think there's no reason to keep IDs like that. More ids => more html => more size. I know, this may be not significant, but why to plague your source code with something you don't want and don't really need?
If you don't like VS's default behavior, you can disable "auto id-ing" via settings:
Tools -> Options -> (Show all settings) -> Text editor -> HTML -> Miscellaneous
VS will assign ID automatically to the controls you haven't provide them to. But if you are pasting some code with controls without IDs, VS will add autogenerated names to them.
So, Microsoft thinks that all the controls should have uique IDs. And you should provide such IDs. But if you really don't need them, so simply remove ID to adjust readability to your code.
The main point is this should be for all controls accross the project, and it should be easy to read "clean" code.

External alias in XAML

I'm currently using a library that implements Menus and ContextMenus for Silverlight 3 and 4. This library defines a MenuItem class in the System.Windows.Controls namespace.
No problems with SL3 because there is no MenuItem class elsewhere in the Silverlight class library; but now I need to use another control in a Silverlight 4 Toolkit assembly and the toolkit now defines a System.Windows.Controls.MenuItem in this same assembly !
So I need a way to indicate to the compiler that I want to use the System.Windows.Controls.MenuItem from my old assembly and not the one in the toolkit 4 assembly.
The solution seems the "external aliases" features.
I can tweak the files I write myself with external aliases but how to indicate to the code generator, the one that generates ".g.i.cs" files from XAML, wich assembly, more exactly which aliases, to use ?
By default it always generates System.Windows.Controls.MenuItem variables in the ".g.i.cs" files, and of course without aliases the C# compiler is unable to know which assembly to use.
I'm using VS 2010 Professional but I haven't been able to find an option to change this behaviour.
Thanks in advance.
I'm afraid the only way around this is to rip the contents of the .g.i.cs file and move it your .cs file, tweak it up with your aliases, remove the partial keyword and then remove the x:Class from the Xaml.
Upside is the designer will still work. The downside is you need create any new control fields yourself and add the FindName code to the copy of InitializeComponent you now have in your .cs. Personally I quite like this, there are plenty of reasons to give an element a name other than it needing to be a field in the class (binding and animation being two of them). Its annoying that fields are automatically created and precious load time devoted to finding and assigning when they're never used.
Finally I've found a workaround :
I've created a library project that wraps the types from the menus library.
For instance :
namespace Alias
{
public class MenuItem : System.Windows.Controls.MenuItem
{
}
}
I then reference this project from my real project and can use the type through their "new" namespace "Alias".
It's a kind of "heavy alias" but seems to work.

ASP.net c#, how do I know what to use?

I keep coming accross code samples online for ASP.net c#, however they never seem to list which namespaces they include, for example:
using System.Data.SqlClient;
etc etc
Am I missing something obvious or should I be expected to know exactly what namespaces each code example requires?
When I'm in that situation, typically I search for the class on MSDN. The documentation will tell you which namespaces contain the class.
If they don't include them, you can follow this list in order:
Find that they are in one of the namespaces listed in the "blank code file" template , or
In Visual Studio You can click the missing type and press shift+F10 or Ctrl+. To get the option to automatically add the using statement (if the assembly is referenced)
With Resharper, Select the type and hit alt+enter for Resharper to find the namespace for you, and add it to the usings (possibly even reference the assembly as well)
Go to MSDN and search the name.
Go to Google and search the name (honestly, I normally do this before hitting MSDN anyway)
Compain to the article author
If code samples use the assemblies that a project references by default, then you can hover on the class name and click shift+F10 which will add the using statement automatically. If the class is not in any of the referenced assemblies then you are out of luck and need to know in what assembly does the class resides.
A quick google search can help, and in time you will memorize the namespaces... Of course its best if samples included the namespace and reference info, but mostly they do not.
If you are viewing code in Visual studio, just hover mouse over class or object you want and you will get tool tip about it if assemly of that class is present or you can google for particular class.For example if you want to know more about 'DataTable'class, just google it and you will come to know that its part of Syste.Data namespace.
I'm with the OP on this one. Having to just magically "know" what namespaces are required seems supremely silly.
I spent some time before C# as a Java Developer, and the NetBeans IDE will resolve these for you automatically. Ctrl-Shift-I, and it will insert all the packages (ie, namespaces) you need. If more than one package defines the class you are resolving, a window pops up and lets you choose which one you want.
For as fine a product as VS is, I am incredulous that this feature is not included.

Categories