How to get full intellisense tooltip comments working? - documentation

I've got some C++/CLI software which is all nice and documented in a C#'ish kind of way which means DOxygen is able to pull it out into some nice html. Is there any way I can get that same information to appear in the intellisense tool tips the way that the .net framework does?
For example, lets say this is my header file (MyApp.h):
/*************** MyApp.h ***************/
/// My namespace containing all my funky classes
namespace MyNamespace
{
using namespace System;
ref class WorldHunger;
/// A truly elegent class which solves all the worlds problems
public ref class MyClass
{
public:
/// Constructs a MyClass
MyClass()
{
}
/// <summary>Attempts to fix world hunger</summary>
/// <param name="problem">The problem to try and fix</param>
/// <returns>Whether or not the problem was solved</param>
bool FixWorldHunger( WorldHunger^ problem );
};
}
...and this it's corresponding implementation:
/*************** MyApp.cpp ***************/
#include "MyApp.h"
using namespace MyNamespace;
MyClass::MyClass()
{
}
bool MyClass::FixWorldHunger( WorldHunger^ problem )
{
bool result = false;
/// TODO: implement something clever
return result;
}
Here's what intellisense does for built in functions when I'm typing:
http://www.geekops.co.uk/photos/0000-00-02%20%28Forum%20images%29/BrokenIntellisense1.jpg
Here's what intellisense does for my own functions when I type:
http://www.geekops.co.uk/photos/0000-00-02%20%28Forum%20images%29/BrokenIntellisense2.jpg
Surely there's a way to do this?

Just to summarise, for this to work you need your comments in a compatible form:
/// <summary>
/// Retrieves the widget at the specified index
/// </summary>
/// <param name="widgetIndex">Index of the widget to retrieve.</param>
/// <returns>The widget at the specified index</returns>
Widget* GetWidget(int widgetIndex);
Then you simply right-click on the project in Visual Studio and go to properties > configuration properties > C/C++ > Output Files and change Generate XML Documentation Files to Yes.
When you rebuild your project ad import it somewhere else, you should see fully documented tooltips appear.

Related

Load VSPackage with dynamic items did not load on startup

I have a Visual Studio Package where items are dynamically added to the menu bar. However, only the fixed entries are shown because the extension is not loaded correctly.
The package is only loaded when you click on a fixed entry. But it should be loaded at the start of the studio.
I tried everything with ProvideAutoLoad, the dynamic items are not shown. I don't know why. What is the problem ?
I hope someone can help me here
thx
[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
should be enough to automatically load a package on Visual Studio startup.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System.Windows.Forms;
namespace VSIXOpenSCE
{
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
[ProvideMenuResource("Menus.ctmenu", 1)]
[Guid(MenuControlPackage.PackageGuidString)]
[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
public sealed class MenuControlPackage : Package
{
public const string PackageGuidString = "f5c6cb4a-bb86-48e4-92e6-f0ee6de2de3a";
public MenuControlPackage()
{
// Inside this method you can place any initialization code that does not require
// any Visual Studio service because at this point the package object is created but
// not sited yet inside Visual Studio environment. The place to do all the other
// initialization is the Initialize method.
}
#region Package Members
/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
protected override void Initialize()
{
base.Initialize();
MenuControl.Initialize(this);
}
#endregion
}
}

Code documentation comments for ASP.NET razor pages?

Is it possible to add code documentation comments to razor pages (resp.: components)?
I found it possible to use standard documentation comments for page parameters (which are declared in #code blocks), but I am still looking for a way to add comments for the component (class) itself.
For parameters, this works:
#code
{
/// <summary> The Id of the selected account. </summary>
[Parameter]
public int SelectedAccount { get; set; }
}
So, for a class, it should be something like this:
#***
<summary> This component renders a table. </summary>
***#
or
#classcomment{
<summary> This component renders a table. </summary>
}
Does anyone know a way?
The simple answer is "it cannot be done", for now.
I've opened a feature request on the razor repo. If you want this feature, please upvote it!
Until this is possible, the accepted answer is a very nice workaround (but requires an extra file, which is a nuisance).
I don't think this is possible just from .razor files. However, you can add a "code-behind" file where you could place the documentation (this is not ideal, of course, because the documentation is separate from the Razor code).
For example, let this be your Component.razor:
<p>Some component</p>
#code
{
/// <summary> The Id of the selected account. </summary>
[Parameter]
public int SelectedAccount { get; set; }
}
You can create Component.razor.cs with the component's documentation comment (the filename is not important, but it's a nice convention to follow this scheme):
/// <summary> This component renders a table. </summary>
partial class Component { }
Note that the namespaces must match (in this example I haven't used any, but you could specify namespace via #namespace directive in the .razor file or folder structure, and namespace block in the .cs file as usual).

User customizable validation with metadata saved in a database

I'm working on an application which should validate the model based on some metadata saved in a database. The purpose of this is to allow administrators change how some models are validated, without changing the code, depending on clients' preferences. The changes are applied for the entire application, not for specific users accessing it. How it is changed, doesn't matter at the moment. They could be modified directly on the database, or using an application. The idea is that they should be customizable.
Let's say i have the model "Person" with the property "Name" of type "string".
public class Person
{
public string Name { get; set; }
}
This model is used by my app which is distributed and istalled on several servers. Each of them is independent. Some users may want the Name to have maximum 30 letters and to be required when creating a new "Person", others may want it to have 25 and not to be required. Normally, this would be solved using data annotations, but those are evaluated during the compile time and are somehow "hardcoded".
Shortly, I want to find a way to customize and store in a database how the model validates, without the need of altering the application code.
Also, it would be nice to work with jquery validation and have as few request to database(/service) as possible. Besides that, i can't use any known ORM like EF.
You could create a custom validation attribute that validates by examining the metadata stored in the database. Custom validation attributes are easy to create, simply extend System.ComponentModel.DataAnnotations.ValidationAttribute and override the IsValid() method.
To get the client side rules that work with jQuery validation you will need to create a custom adapter for the type of your custom validation attribute that extends System.Web.Mvc.DataAnnotationsModelValidator<YourCustomValidationAttribute>. This class then needs to be registered in the OnApplicationStart() method of your Global.asax.
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(YourCustomValidationAttribute), typeof(YourCustomAdapter));
Here's an example adapter:
public class FooAdapter : DataAnnotationsModelValidator<FooAttribute>
{
/// <summary>
/// This constructor is used by the MVC framework to retrieve the client validation rules for the attribute
/// type associated with this adapter.
/// </summary>
/// <param name="metadata">Information about the type being validated.</param>
/// <param name="context">The ControllerContext for the controller handling the request.</param>
/// <param name="attribute">The attribute associated with this adapter.</param>
public FooAdapter(ModelMetadata metadata, ControllerContext context, FooAttribute attribute)
: base(metadata, context, attribute)
{
_metadata = metadata;
}
/// <summary>
/// Overrides the definition in System.Web.Mvc.ModelValidator to provide the client validation rules specific
/// to this type.
/// </summary>
/// <returns>The set of rules that will be used for client side validation.</returns>
public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
{
return new[] { new ModelClientValidationRequiredRule(
String.Format("The {0} field is invalid.", _metadata.DisplayName ?? _metadata.PropertyName)) };
}
/// <summary>
/// The metadata associated with the property tagged by the validation attribute.
/// </summary>
private ModelMetadata _metadata;
}
This may also be useful if you would like to asynchronously call server side validation http://msdn.microsoft.com/en-us/library/system.web.mvc.remoteattribute(v=vs.108).aspx

How to extend Ninject Binding Syntax

is there a way to extend the existing binding syntax (e.g. extension method) that will allow us to have something like this:
Bind<IRepository>().ToProvider<MyProvider<MyRepository>>().WhenCustom<SomeType>()
Write an extension method for IBindingWhenSyntax<T> and use the existing When overload to implement your logic:
class BindingWhenExtensions
{
public IBindingInNamedWithOrOnSyntax<T> WhenCustom<T>(
this IBindingWhenSyntax<T> syntax)
{
return syntax.When(r => true);
}
}
Reframing the question (to align with your comment) you want to create an extension with a signature similar to the following;
public static IBindingInNamedWithOrOnSyntax<T> WhenCustom<TParent>(
this IBindingWhenSyntax<T> binding)
As far as I can tell we're not able to extend as cleanly as this with Ninject because as you rightly allude to T here is defined on an interface that our extension doesn't know about.
So our extension signature must be;
public static IBindingInNamedWithOrOnSyntax<T> WhenCustom<T>(
this IBindingWhenSyntax<T> binding)
At this point the only way I see us being able to successfully pass TParent is to drop the generic parameter and pass it as a standard type parameter (or pass several types);
public static IBindingInNamedWithOrOnSyntax<T> WhenCustom(
this IBindingWhenSyntax<T> binding, params Type[] parents)
This is still consistent with Ninjects own binding syntax methods;
/// <summary>
/// Indicates that the binding should be used only for injections on the specified types.
/// Types that derive from one of the specified types are considered as valid targets.
/// Should match at lease one of the targets.
/// </summary>
/// <param name="parents">The types to match.</param>
/// <returns>The fluent syntax.</returns>
IBindingInNamedWithOrOnSyntax<T> WhenInjectedInto(params Type[] parents);
It's just unfortunate that we don't have the luxury of extending with 'pure' generics.

Singleton Data Access Object (Dao) & SQL Helper Instance, Is here any Performance drawback?

I need comments from Experts. I write my own SQL Helper Class to Communicate with DB.
Why I use it as because I try to
Encapsulate the Ado.Net logic.
Try to set a common standard for my developer in terms of DAL coding.
Flexible & Easy to use.
Same kind of code block for SQL Server/ Oracle / Access / Excel / Generic Database code block approach (SQL Server & Oracle) e.t.c.
Plug & Play or Reusable approach.
In terms of code optimization
This helper class or Assembly is CLS Compliant.
It pass Successfully by FxCop / Static Code Analysis.
I give you the sample Code Block (DAO). Please check bellow
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
#region include SQL Helper Namespace
using DBManager;
#endregion
#region include SQL Helper Namespace
using DBManager;
#endregion
namespace ContentManagementSystem.DataAccessLayer
{
/// <summary>
///
/// </summary>
public sealed class DaoContentOwner : DataAccessBase
{
#region CONSTRUCTOR
/// <summary>
///
/// </summary>
private DaoContentOwner()
{
GetInstance = new DaoContentOwner();
}
#endregion
//############################################# M E T H O D S ##########################
#region Retrieve Content Owner
/// <summary>
/// Retrieve Content Owner
/// </summary>
/// <returns></returns>
public static DataTable RetrieveContentOwner()
{
DataTable dt = null;
try
{
using (DBQuery dq = new DBQuery("stpGetContentOwner"))
{
dt = dq.ResultSetAsDataTable();
return dt;
}
}
catch (Exception)
{
throw;
}
finally
{
if (dt != null)
{
dt.Dispose();
}
}
}
#endregion
//############################################# P R O P E R T Y ########################
#region READ ONLY PROPERTY
/// <summary>
/// GetInstance of DaoContentOwner Class
/// </summary>
public static DaoContentOwner GetInstance { get; private set; }
#endregion
}
}
Justification:
"DataAccessBase" It is a Abstract class. Implement IDisposable Interface.
"DBQuery" is SQL Helper for SQL Server Only. It is a Sealed class. It is takes T-SQL / SP according to needs. Open an close database connection. No need to handel any thing by developer.
Why I make DAO Singleton Class, Because my all the methods withing DAO is a static method. I order to memory optimization I make it Singleton. It is also a design Principal.
Note: Needs comments. Whether need to change in the design or some thing is wrong that need to correct.
Personally I would go with:
DALFileItem dalF = new DALFileItem(DSN);
List<FileItem> list = dalF.GetAll("");
Allows accessing multiple databases, without making DSN static member.
In multithreaded environment only one thread will have access to the static method.
More object oriented: you can add interfaces, base classes and generics easier that way.