Reference with <code> tag a VB class beginning, VB class method and VB class ending
Hello,
Do you know if there is any trick with the <code source="" region=""> tag to reference three regions of a class: the class beginning including using directive, a class method and the class ending? See the example below.
The documentation is:
/// <summary>
/// Documentation for my example.
/// </summary>
/// <example>
/// <code lang="VB.NET">
/// <code source="C:\Dev\Project\Example.vb" region="ClassBeginning" />
/// <code source="C:\Dev\Project\Example.vb" region="Method1" />
/// <code source="C:\Dev\Project\Example.vb" region="ClassEnding" />
/// </code>
/// </example>
The example file that I have in mind is the following. However, it doesn't work to wrap the beginning and the end of the class inside regions.
C:\Dev\Project\Example.vb
#Region "ClassBeginning"
Imports System.Linq
Imports System.Collections.Generic
Public Class [MyClass]
#End Region
#Region "Method1"
Public Sub Method1()
' Do something Method1().
End Sub
#End Region
#Region "Method2"
Public Sub Method2()
' Do something Method2().
End Sub
#End Region
#Region "ClassEnding"
End Class
#End Region
Thank you very much for reading.
Best regards,
Nicolas
Are you having a problem with SHFB or the source file? Your source file is not valid since it's a mix of VB and C# so it obviously won't compile and will generate IntelliSense errors if opened in an editor. However, using it as a source for the example in the comments, it works as expected though the resulting example again is not valid C#.
Hello Eric,
Thank you for the quick answer.
Sorry, I confused everything. I updated my previous comment as you can see. I should have shown VB code. The problem occurs only with VB. There is IntelliSense errors in the editor.
If I use C#, I am able to wrap class beginning and class ending in regions:
#region "ClassBeginning"
using System;
using System.Linq;
using System.Collections.Generic;
public class MyClass
{
#endregion // "ClassBeginning"
#region "Method1"
public void Method1()
{
// Do something Method1().
}
#endregion // "Method1"
#region "Method2"
public void Method2()
{
// Do something Method2().
}
#endregion // "Method2"
#region "ClassEnding"
}
#endregion // "ClassEnding"
Although it is not a SHFB do you know if there is a way to do what I want in VB?
Best regards,
Nicolas
You can put the '#region' and '#endregion' like you do in the C# code inside a VB comment: '#region Method1 ' do something '#endregion
Thank you very much dwhearn.
I commented the VB '#Region and '#End Region.
Sandcastle detects it and is able to reference the regions in VB example source. So the code looks like:
C:\Dev\Project\Example.vb
'#Region "ClassBeginning"
Imports System.Linq
Imports System.Collections.Generic
Public Class [MyClass]
'#End Region
#Region "Method1"
Public Sub Method1()
' Do something Method1().
End Sub
#End Region
#Region "Method2"
Public Sub Method2()
' Do something Method2().
End Sub
#End Region
'#Region "ClassEnding"
End Class
'#End Region
It's a good workaround. If it's the only way to do what I want, I will consider it.
However, it doesn't behave like a real "region" parttern. I cannot expand and collapse the region in the source code.
Does anybody have another idea?
Best regards,
Nicolas
I think that's your only option. VB's more picky about placement of the region markers.
OK thank you guys for helping me. I will do that.
I close the "issue".
Have a nice day!