Adding Comments to Parameter in DLL - c#

I had created a DLL in .NET ,which includes several function.Now I am suing this DLL in another App
I want that whenever the client uses my DLL,somesort of comments must be shown that shows return type,Parameters etc.like this
i see people this using XML files.Is there any alternative way?
Thanks in meekness

You need to use XML documentation specified in comments before the member declaration.
/// <summary>Some stuff here</summary>
/// <remarks>Some remarks</remarks>
/// <param name="foo">The foo to gronk</param>
Then go into your project properties and enable building an XML file alongside your library in the "Build" tab. Distribute that along with your DLL, and Visual Studio will display your content.

/// <summary>
/// This method does something.
/// </summary>
/// <param name="zain">Zain to be processed.</param>
/// <returns>True if it went okay, false otherwise.</returns>

Use /// at the start of the method declarations:
/// <summary>
/// This method does something.
/// </summary>
/// <param name="foo">Foo value to be processed.</param>
/// <returns>True if it went okay, false otherwise.</returns>
public bool DoSomething(int foo)
{
if (foo > 0)
return true;
else
return false;
}

As has been stated, you can add XML documentation at the beginning of each public member:
/// <summary>
/// This is the summary for your method.
/// </summary>
public void MyMethod()
{
/// your code here...
}
There are a host of tools to aide in the process. Check out GhostDoc for generating comments and Sandcastle for creating help files or web pages from it.

Related

Not Able To Use PixConverter.ToPix Leptonica C#

I wanted to convert a bitmap to Leptonica.Pix.. So after I did a search I found someone who had the same problem here:
Tesseract .NET Process image from memory object
So the solution to this problem was to use PixConverter.ToPix() method.
My problem here is that I can't find this method in the latest installed Leptonica Package. I tried to remove the and reinstall the lateset version thought Nuget but the method is still not not there.
What should I do to be able to use PixConverter.ToPix()?. Thanks in advance.
EDIT: I forgot to mention that i'm using the latest Tessercat pacakge too.
You need to use the version "3.0.2" for this (PixConverter.ToPix()) to work.
So your .csproj file should have this exact match in version:
<PackageReference Include="Tesseract" Version="3.0.2" />
Hope it helps.
In Tesseract 4 there is a new way to convert this using the following syntax:
var pixFromByteArray = Pix.LoadFromMemory(byteArray);
var pixFromFile = Pix.LoadFromFile(fileName);
It lives in Tesseract namespace, more information can be found here https://github.com/charlesw/tesseract
namespace Tesseract
{
/// <summary>
/// Handles converting between different image formats supported by DotNet.
/// </summary>
public static class PixConverter
{
private static readonly BitmapToPixConverter bitmapConverter = new BitmapToPixConverter();
private static readonly PixToBitmapConverter pixConverter = new PixToBitmapConverter();
/// <summary>
/// Converts the specified <paramref name="pix"/> to a Bitmap.
/// </summary>
/// <param name="pix">The source image to be converted.</param>
/// <returns>The converted pix as a <see cref="Bitmap"/>.</returns>
public static Bitmap ToBitmap(Pix pix)
{
return pixConverter.Convert(pix);
}
/// <summary>
/// Converts the specified <paramref name="img"/> to a Pix.
/// </summary>
/// <param name="img">The source image to be converted.</param>
/// <returns>The converted bitmap image as a <see cref="Pix"/>.</returns>
public static Pix ToPix(Bitmap img)
{
return bitmapConverter.Convert(img);
}
}
}
As per the sites landing page
Add the Tesseract NuGet Package by running Install-Package Tesseract from the Package Manager Console.
Also, its worth while reading the site thoroughly.
Disclaimer, i have never used this library before, just looked up the information
Update
Just to make sure i wasn't giving you bad information, I created a new project, downloaded the latest Tesseract nuget. And was able to do the following.
using Tesseract;
...
PixConverter.ToPix()
Update2
The problem you are noticing is because you are using
https://www.nuget.org/packages/tesseract.net/
apposed to
https://www.nuget.org/packages/Tesseract/
Now 'im not sure what one you actually want. However that method dosnt not exist in the former

ReSharper Documentation Tags Formatting One Per Line

I'm trying to get ReSharper to behave properly when creating XML comments.
When I see the preview it looks exactly how I want it to look but when I actually document a method or a class it isn't formatting as per the preview.
I get this:
/// <summary>
/// The trace.
/// </summary>
/// <param name="level">
/// The level.
/// </param>
/// <param name="tag">
/// The tag.
/// </param>
/// <param name="message">
/// The message.
/// </param>
/// <param name="args">
/// The args.
/// </param>
When in fact the preview (and what I want) looks like this:
/// <summary> The trace. </summary>
/// <param name="level"> The level. </param>
/// <param name="tag"> The tag. </param>
/// <param name="message"> The message. </param>
/// <param name="args"> The args. </param>
I've tried saving these settings machine wide and as far as I can tell my solution settings match the global settings but still no joy.
How do I get this to function as I want? (I'm using ReSharper 7.1.3)
Turns out I was looking in all the wrong places. I was attempting to fix the comments layout by using the refactoring settings. The settings to format the XML comments at creation time are in the StyleCop settings here:

<example></example> XML comment tag: how to see it?

I use Microsoft Visual Studio 2012.
When I put code examples into XML comments of C# classes/methods, I wonder: how will user that references my assemblies see that code example?
I tried to reference my own assembly, and the only way I found was: to look at assembly.xml file.
Can I settle Visual Studio or anything else to see those code examples?
Here is what I put into comments:
/// <summary>
/// This is my method example
/// </summary>
/// <example>
/// <code>
/// // Here is my code example. Call my method like this:
/// const int a = 10;
/// MethodExample(a);
/// </code>
/// </example>
public static void MethodExample(int parameter)
{
}
Here is what I get in IntelliSense:
Here is what I get in Object Browser:
Here is what I get in assembly.xml file:
What I'd like to get: see code examples in Object Browser and IntelliSense.
A number of XML comment tags appear in IntelliSense only as child elements of other tags. These tags, known as ChildCompletionList tags, are: c, code, example, list, listheader, para, paramref, see and see also.
/// <summary>
/// MethodExample the function that does it all...
/// <example>
/// <code>
/// <para/>// Here is my code example. Call my method like this:
/// <para/>const int a = 10;
/// <para/>MethodExample(a);
/// </code>
/// </example>
/// </summary>
If your not seeing XML commments in IntelliSense or they're not updating after you edit them try:
Not seeing: be sure everything is enclosed in the <summary> element.
ref: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags
Not updating: close & reopen solution (this seems to work pretty consistently)
VS Ent 2019 (16.10.4)

WatiN - Switch to Browser windows based on element inside the browser say a Heading1 element

Has anyone implemented different methods to switch across browser windows in WatiN?
Current methods which are supported are :
browserType
Type: System..::.Type
The WatiN browser type to attach to.
constraint
Type: WatiN.Core.Constraints..::.Constraint
The Constraint of the browser window to find. Find.ByUrl(), Find.ByUri(), Find.ByTitle() and Find.By("hwnd", windowHandle) are supported.
I want to create a method which switches to a new popup either based on some element present inside the browser page or using hwnd which should be unique.
This method should ideally support both the browsers IE and Firefox.
Use Case:
Suppose I have one browser window open and after clicking a link and on a button it opens two new popup / browser windows. Both are having same title but the contents are different.
One window is having heading1 text as "My Heading One" and other is having heading2 text as "my Heading two".
Now I want to switch to second popup browser window which heading heading2 element.
Is it possible to use Browser.AttachTo(browser.getType(), Find.By.....); ??
As per your use case, once you click on a link, a new pop/window is opened. If you are sure that for Parent window there would be H1 elements (for verifying/attaching) and for child's window H2 elements (verifying/attaching). So you need to create H1 and H2 elements as shown below.
[ElementTag("h1")]
public class HeaderLevel1 : ElementContainer<HeaderLevel1>
{
/// <summary>
/// Initializes a new instance of the <see cref="Div"/> class.
/// Mainly used by WatiN internally.
/// </summary>
/// <param name="domContainer">The DOM container.</param>
/// <param name="htmlH1Element">The HTML h1 element.</param>
public HeaderLevel1(DomContainer domContainer, INativeElement htmlH1Element) : base(domContainer, htmlH1Element) { }
/// <summary>
/// Initializes a new instance of the <see cref="Div"/> class.
/// Mainly used by WatiN internally.
/// </summary>
/// <param name="domContainer">The DOM container.</param>
/// <param name="finder">The HTML h1 element.</param>
public HeaderLevel1(DomContainer domContainer, ElementFinder finder) : base(domContainer, finder) { }
/// <summary>
/// Gets the name of this Watin element.
/// </summary>
/// <returns></returns>
public string GetName()
{
return "HeaderLevel1";
}
}
Similarly for H2, you can do the same. For IE, you can use,
IECollection browsers = IE.InternetExplorers(),
which returns you the IE collection and for each, get the H2 elements count and then try to attach using the current title. I am not very sure how we can achieve this in FF, but there must be a way.
Thanks,
Sham_

Programmatically retrieve function header information

I have a function GetMainWindowAE, which contains the header information as shown below.
/// <summary>
/// Gets the main window automation element.
/// </summary>
/// <returns></returns>
public static AutomationElement GetMainWindowAE()
{
//Return automation element using window handle of that process
return AutomationElement.FromHandle(AppContext.ActiveApplication.Process.MainWindowHandle);
}
How can I programmatically get the data which is in header with comments using .net?
You can use Reflection to achieve this. The MethodInfo property of the method contains the XML comments associated with the method (AKA the header information).
See this blog entry for more information and code example.

Categories