Does anyone know how? I'm trying to make a method that the intellisense shows another name instead of the name you ta the method. example:
The code looks like this:
Public Shared Sub Anything(ByVal blablabla....)
(...)
End Sub
And I want to auto-complete the VisualStudio menu be like:
Async
Alalala
Anymethod
Anything - Like these
Basic
On mouse hover:
instead of...
Public Shared Sub Namespace.Anything(ByVal blablablbal....)
This is the summary...
put it:
Anything <expression>
This is the summary...
-or-
Sub Anything
This is the summary...
Any ideas? thx...
I believe you're talking about XML Comments. Without comments:
With comments:
And Intellisense then also displays the parameter information as you get to each parameter:
Sooooo, I hope my answer isn't too vague. I'd love to help you igure it out either way.
Basically - you have to override the XML Documentation that Intellisense uses, in order to MAP a new MethodName to a Differently-Named method within your assembly.
Intellisense uses an XML Skeleton to define the different properties of what you see. That Skeleton typically looks something like this:
<CodeElement type="Function">
<Template>
<summary/>
<param/>
<returns/>
<remarks/>
</Template>
<CompletionList>
<exception cref=""/>
<include file="" path=""/>
<param name=""/>
<remarks/>
<returns/>
<summary/>
</CompletionList>
</CodeElement>
You can use this template to generate the Intellisense data you're looking for. In real-life application, this would look something like this:
''' <summary>
'''
''' </summary>
''' <param name="str"></praram>
''' <returns></returns>
''' <remarks></remarks>
Function Anything(ByVal str As String) As String
Try
...
Now, this template is Editable
The Visual Basic compiler generates an XML document for your assembly with all the XML comments defined in the code. The compiler will also resolve symbols used in cref, permission, and name attributes, as well as file references in include elements.
The generated file doesn't show your commented members hierarchically. Rather, it is a flat list. It includes a unique ID string for each definition that allows the comments to be mapped back to their definitions in code (see Code Snippet below).
In this case, the string is M:Namespace.Anything(System.String). M stands for method, Namespace specifies the path, System.String the parameter type.
THIS is where you would override the NAME of the Method that INTELLISENSE sees, without effecting the actual Method itself.
<?xml version="1.0" ?>
<doc>
<assembly>
<name>AnyLib</name>
</assembly>
<members>
...
<member name="M:Namespace.Anything(System.String)">
<summary>Does something</summary>
<param name="str">str to pass into method</param>
<returns>A string</returns>
</member>
...
</members>
</doc>
You can generate the XML documentation file using either the command-line compiler or through the Visual Studio interface. If you are compiling with the command-line compiler, use options /doc or /doc+. That will generate an XML file by the same name and in the same path as the assembly. To specify a different file name, use /doc:file.
If you are using the Visual Studio interface, there's a setting that controls whether the XML documentation file is generated. To set it, double-click My Project in Solution Explorer to open the Project Designer. Navigate to the Compile tab. Find "Generate XML documentation file" at the bottom of the window, and make sure it is checked. By default this setting is on. It generates an XML file using the same name and path as the assembly
In short - yes, it is possible, but very cumbersome and makes re-using your code very difficult. Check this link for a more detailed overview:
https://msdn.microsoft.com/en-us/magazine/dd722812.aspx
Related
I use NSwag in an ASP.Net WebAPI project to generate a swagger interface - which works great.
Say I have a method I want to add some explanations to - how can I do that?
By comment I mean something that when a user of the API is looking at the documentation will see.
I have googled, binged and ... ducked? - but was unable to find anything about it. Maybe I am using wrong terms.
To use annotation-based documentation with NSwag you must install the package NSwag.Annotations.
Then you can use annotations like that:
[SwaggerResponse(HttpStatusCode.OK, typeof(MyResponseType), Description = "Returns the object containing data ...")]
You can use Document comments to achieve your goal. For example
/// <summary>This method changes the point's location by
/// the given x- and y-offsets.
/// <example>For example:
/// <code>
/// Point p = new Point(3,5);
/// p.Translate(-1,3);
/// </code>
/// results in <c>p</c>'s having the value (2,8).
/// </example>
/// </summary>
public void Translate(int xor, int yor) {
X += xor;
Y += yor;
}
Translate is your API method and you've added proper documentation comments NSwag will pick those up and show them when you explore the API via the API explorer. If that doesn't work add the following in your .csproj
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
Alternatively to the XML approach posted in another answer you can use the Swashbuckle.AspNetCore.Annotations package as well if you prefer an attribute-based approach.
I defined a structure MY_STRUCTURE using typdef in .h file and created an instance MY_STRUCTURE MyStruct in .c file. I use Doxygen to output xml file.
My question is in the index.xml file, it only shows the structure instance name without showing its type.
<member refid="d6/d68/test_8c_1a89a9f154447f0a42e64c961660b4dd34" kind="variable"><name>MyStruct</name></member>
Without this info, I cannot link the structure instance name "MyStruct" with its type "MY_STRUCTURE".
Does anyone know how to link these two info in the output xml file?
Thanks
I can't find any option to add that info to the index file, so I don't think that is possible. You can however look up the type using the refid.
So given a member definition:
<member refid="main_8c_1ad514631b0d3cf856a07ef28509ad007a" kind="variable"><name>testStruct</name></member>
You can lookup in the file main_8c.xml(Should be d6/d86/test_8c.xml for you) the memberdef by matching id:
<sectiondef kind="var">
<memberdef kind="variable" id="main_8c_1ad514631b0d3cf856a07ef28509ad007a" prot="public" static="no" mutable="no">
<type><ref refid="structMY__STRUCTURE" kindref="compound">MY_STRUCTURE</ref></type>
<definition>MY_STRUCTURE testStruct</definition>
I have solution with few projects included.
One of project is common library project which contain mostly reusable code and functions which shares all other projects under solution and which is referenced to all included projects.
In that project I also have resources like are images and icons and I can access those resources from other projects like that:
Me.Icon = myCommonDll.My.Resources.backup__add__16x16
Question is:
Can it be done somehow that those common resources in myCommonDll will be actual resources for other projects in solution so when I click to "Image" or "Icon" in properties window in designer I get listed images or icons which are present in myCommonDll.My.Resources and how to do that?
EDIT: This is primarily for VS versions prior to VS2008 which did NOT allow you to change the access level modifier for REsources. Other alternatives were external tools or Reflection, but still did not expose resources to the designer.
DLL resources are available at runtime fairly easily but not in the designer. You need to write a small broker in the DLL to fetch images by name. DLL:
Public Class ResMgr
' depending on what else is in the DLL, can just add to an existing class
Public Function GetImage(imgName As String) As Image
Return My.Resources.ResourceManager.GetObject(imgName)
End Function
'' alternatively declare it SHARED eg
''Public Shared Function/Property GetImage As Image
End Class
App:
MyRM = New ResMgr
thisImg = New Image
thisImg = MyRM.GetImage(userImg)
If you construct it as Shared method, it is just:
thisImg = ResMgr.GetImage(userImg)
If you want, you can expose an Enum in the DLL to act as a resource manifest:
Public Enum ResImg
Image1 ' use the names of the images
Backup52
Flag_FR
Flag_RUS
...
End Enum
The DLL function can either act on ResImg and use a big case statement, or you can use [Enum].GetNames to convert/get an array of image resource names.
Edit your .vbproj file and update the two statements below by adding the common directory path of your shared resource files. Good Luck!
<Compile Include="<common Dir>\My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="<common Dir>\My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
</EmbeddedResource>
The msbuild contains output tag. It has avialable attributes: TaskParameter and PropertyName, ItemName.
How they can be used? What are they containing?
Please, can you help me to understand and give an example? For example you can use xmlpeek task with output tag inside.
(I read documentation on msdn but I still don't get it. :( )
The question has been answered, but I will follow up with an example.
In the MSBuild community task Time, an output parameter Month can be set to a property called
CurrentMonth as follows:
<Time>
<Output TaskParameter="Month" PropertyName="CurrentMonth" />
</Time>
In the MSBuild Community task time source code the property Month inside the Time class looks like this:
[Output]
public string Month
{
get { return month; }
}
All properties mapped with an [Output] attribute can be set as a task parameter and
assigned a MSBuild property name as specified above.
To read more about the Time task, a CHM file is available in the MSI file available at the following URL: http://msbuildtasks.tigris.org/
These are a way of passing values back from the task to the MSBuild script. It is basically a way of mapping a property in the compiled task code that has been decorated with the [Output] attribute back to a property in your MSBuild file. This page gives you more details about it: MSDN: Output Element (MSBuild). This article also has a good example of it in action: How to auto-increment assembly version using a custom MSBuild task
is there a way to enable IntelliSense for XML literals in VB9 (VS 2008)?
The ideal source of IntelliSense is an XSD document, but I can use anything else format to do it.
Thanks
http://msdn.microsoft.com/en-us/library/bb531402.aspx
It works, I used it a few months back. If you have VS2k8 Docmentation installed, go to How to: Enable XML IntelliSense in Visual Basic at ms-help://MS.MSDNQTR.v90.en/dv_vbalr/html/af67d0ee-a4a6-4abf-9c07-5a8cfe80d111.htm, it has the example you need to get this working. The on-line documentation is lacking.
How to Use LINQ to XML
How to: Enable XML IntelliSense in Visual Basic
Shows how to add an XML schema to a Visual Basic project to provide XML IntelliSense that shows possible attributes, child elements, or descendant elements for XML literals.
Excerpt
To import an XML namespace in a code file
Identify the target namespace from your XSD schema.
At the beginning of the code file, add an Imports statement for the target XML namespace, as shown in the following example.
Imports <xmlns:ns="http://someNamespace">
To import an XML namespace as the default namespace, that is, the namespace that is applied to XML elements and attributes that do not have a namespace prefix, add an Imports statement for the target default XML namespace. Do not specify a namespace prefix. Following is an example of an Imports statement.
Dim phone2 As XElement = <phone type="home">206-555-0144</phone>
phone2.#owner = "Harris, Phyllis"
Console.WriteLine(phone2)
'Imports <xmlns="http://defaultNamespace">
I haven't seen any way of doing this. Please go rate or comment on this suggestion on the Microsoft Connect site.
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=490740