Generic ServerControl syntax? - c#

Is there a way that I can have a server control
MyControl<T>
so that I can register and use it in an aspx page like so
<mc:MyControl<ThingForControlToUse> ID="instanceOfMyControl" runat="server"
Obviously the designer doesn't like this, are there any cool ways round it other than creating a non generic wrapper with a type parameter?

Generic Tag Names are not possible in ASP.NET, please refer to this article: Generic Controls
You are on the right track in thinking that you will need to create a wrapper with a TYPE parameter.

A quick note - I am not sure if this is true in Visual Studio 2008 but if you were to have that control in a project that you were editing with Visual Studio 2005 you would completely break intellisense with that control. When Visual Studio attempts to create XML schema files to use for intellisense popups in markup files it completely breaks when it sees generic controls like this one and it abandons the schema file completely leaving you with no intellisense for any controls in that assembly.

Related

How to View .cshtml Design Locally

I have a few .cshtml files which contains the design of a form in Visual Studio.
As I am debugging it locally, I do not have access to the database. Therefore, when I click on View in Browser, I will get errors.
May I know are there any others ways that can I preview the design of the form?
Thank you.
Visual Studio doesn't have a visual designer for razor pages like the one available for Web Forms. You could try opening the file with the "HTML (Web Forms) Editor" by using the option "Open with..." in that context menu, but I don't think it will render anything useful.
Your default option would be "View Markup", and you must interpret the layout of your form by looking at the HTML elements composing it.
I have two possible suggestions:
Create a local database with the same basic schema and change the connection to it for debugging. This requires minimal changes to the existing code and is my preferred method.
Alternatively, create some dummy data to display on the page in place of what would be filled from the database. Probably a slightly quicker solution than the first one, but potentially means a lot of code edits.

is there a shortcut/plugin to insert/list all object properties in vs like intellisense does for just one?

Is there a way in visual studio to insert more than one (perhaps all) member/property from the intellisense of an object at a time? Or any plugins that will do this?
I am so tired of having to list them all out half-manually when building forms..
This would be a great shortcut if it exists..
There's Resharper and Code Rush which help with this type of thing. They both have customizations so if it doesn't work how you want then you can add your own templates or add-in to make it do what you want.

Enum Intellisense Display Attribute?

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.

C# Templates for Visual Studio 2005

I'm looking for some template examples, such as a C# windows dialog.
Do many hackers take advantage of template files?
There are times when I'm creating dialog forms that are very similar. I want to make all my forms look and behave consistently, without doing a lot of coping and pasting.
Add New Item -> My Templates
Here's an article on creating your own Project and Project Item templates:
Create Reusable Project And Item Templates For Your Development Team
Much cooler, but not exactly what you asked for is T4 (text template transformation toolkit) that allow you to do intelligent code generation during builds. Take a look at this MSDN article for more info:
Generating Artifacts By Using Text Templates
Make the template yourself, from the first dialog you made. This will avoid the problem of having to search for a template that does exactly what you want.
There are lots of C# code snippets around. They will provide scaffolding for different structures (properties, dispose pattern and more).
Here is one source.

How do I serialize a .NET control to CODE?

I want to create a .NET Form at runtime, add buttons and other controls to that (also at runtime), and then be able to generate a something.designer.cs file from that form (which can then be added to a C# solution and compiled).
What I want to do is very similar to what the WinForm designer does. But instead of having a drag/drop interface for the user, I want to dynamically build the Form/Controls myself at runtime.
I was thinking I could just reuse what the WinForm designer is doing.
Is that possible?
This MSDN magazine article should have everything you need.
It's really not as simple as it was pre-.NET as the visual version of the form you see in Visual Studio is actually the result of multiple files.
But in the simplest form you could simply just mirror what .NET does at the start of creating a new form:
Create three files Form.cs, Form.Designer.cs and Form.resx (which is an XML file).
Place the same default content in them that VS does
Mimic the code generated when adding controls, code-behind and resources
It will be a tedious task, but it can be done. Adding resources however will be burdensome.
Yes, you can do achieve this using Compiler Services (compiling c# code) or Emit class if you know building correct MSIL.

Categories