VS2010 VB.NET XML Comments for class field not showing - vb.net

In VB.NET project in VS2010 I try to add XML comments (''') to fields of class. There is a problem with displaying comments: only full comments for class methods are displayed, when I placed mouse cursor over members names in Main() sub.
In project compile options "Generate XML documentation file" checkbox is turned on; full comments are normally displayed in intellisense list (when I type period after object name).
Is that by design or can be changed in preferences?
Minimal code sample placed below.
''' <summary>
''' Test class
''' </summary>
''' <remarks></remarks>
Public Class TestClass
''' <summary>
''' Test field
''' </summary>
''' <remarks></remarks>
Public s As String
''' <summary>
''' Test method
''' </summary>
''' <remarks></remarks>
Public Sub Method()
End Sub
End Class
Sub Main()
Dim c = New TestClass() ' "Class TestClass \ Test class" displayed
c.s = "abc" ' Only "Public s As String" displayed!
c.Method() ' "Public s As String \ Test method" displayed
End Sub

It appears that XML comments don't show up when you hover on fields. If you change
Public s As String
to this:
Public Property s As String
It will work. Generally, you should not expose variables directly through Public and use properties instead. You will get better integration into .NET this way (such as DataBinding).
Looks like this problem is specific to VB, because C# counterpart works with no issues:
/// <summary>
/// Test class
/// </summary>
/// <remarks></remarks>
class TestClass
{
/// <summary>
/// Test field
/// </summary>
/// <remarks></remarks>
public String s;
/// <summary>
/// Test method
/// </summary>
/// <remarks></remarks>
public void Method() {}
static void Main(string[] args)
{
TestClass c = new TestClass();
c.s = "abc"; //not a property, but help shows on hover
c.Method();
}
}

FYI: Fixed in VS 2012; VB.Net shows summary for fields, now.

Related

XML comments for objects using WithEvents not showing

XML comments do not show up when an object instance is defined using WithEvents; however, comments will show up for everything else. How do I resolve this?
EDIT
''' <summary>
''' Represents a <see cref="System.Windows.Forms.Button"/> control that when clicked displays the associated <see cref="System.Windows.Forms.CheckBox"/> controls which the user can use to toggle elements.
''' </summary>
Public WithEvents DropDownButton As New System.Windows.Forms.Button
Source Image:
Image from new project using the code:

Custom NUnit Constraint in VB.net - Cannot Override ApplyTo

I'm trying to write a custom contrain for nunit (3) in vb.net Simplest example (following the docs) would be:
Namespace MYConstraints
Public Class MyConstraint
Inherits NUnit.Framework.Constraints.Constraint
Public Overrides Function ApplyTo(Of TActual)(actual As TActual) As NUnit.Framework.Constraints.ConstraintResult
Throw New NotImplementedException()
End Function
End Class
End Namespace
(The ApplyTo definition was added by Visual Studio automatically even, when I inherited the nunit Constraint class)
Problem is, it won't compile!
I get two errors:
BC30518 Overload resolution failed because no accessible 'That' can be
called with these arguments:
'Public Shared Overloads Sub That(Of TActual)(del As ActualValueDelegate(Of TActual), expr As IResolveConstraint)':
Type parameter 'TActual' cannot be inferred.
'Public Shared Overloads Sub That(Of TActual)(actual As TActual, expression As IResolveConstraint)':
Type parameter 'TActual' cannot be
inferred.
And
BC30935 Member 'Public MustOverride Overloads Function ApplyTo(Of
TActual)(actual As TActual) As ConstraintResult' that matches this
signature cannot be overridden because the class 'Constraint' contains
multiple members with this same name and signature:
'Public MustOverride Overloads Function ApplyTo(Of TActual)(actual As
TActual) As ConstraintResult'
'Public Overridable Overloads Function ApplyTo(Of TActual)(ByRef actual As TActual) As ConstraintResult'
Looking at the nunit source for the Constain class I see that they have defined two variants with the same signature:
/// <summary>
/// Applies the constraint to an actual value, returning a ConstraintResult.
/// </summary>
/// <param name="actual">The value to be tested</param>
/// <returns>A ConstraintResult</returns>
public abstract ConstraintResult ApplyTo<TActual>(TActual actual);
/// <summary>
/// Applies the constraint to an ActualValueDelegate that returns
/// the value to be tested. The default implementation simply evaluates
/// the delegate but derived classes may override it to provide for
/// delayed processing.
/// </summary>
/// <param name="del">An ActualValueDelegate</param>
/// <returns>A ConstraintResult</returns>
public virtual ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> del)
{
#if ASYNC
if (AsyncInvocationRegion.IsAsyncOperation(del))
using (var region = AsyncInvocationRegion.Create(del))
return ApplyTo(region.WaitForPendingOperationsToComplete(del()));
#endif
return ApplyTo(GetTestObject(del));
}
One is abstract with a pass-by-value parameter and the other is virtual with a reference param, but that's surely not enough to distinguish them when calling?
The tooltip error in Visual Studio (VS 2015 Professional if it makes a difference) is:
So it looks like it's interpreting the ActualValueDelegate<TActual> as a ByRef TActual in vb.net
So, two questions:
How is this possible? (Is this allowed in C# but not vb.net? or
have I misunderstood something?) - this is just that I am curious :)
How should I write a custom constrain in vb.net? (Does anyone have
an example?) This is my main question :)
I'm increasingly convinced this is a bug - something valid in C# that doesn't translate to vb.net maybe. Have created a bug at https://github.com/nunit/nunit/issues/2263
It seems to be confirmed as a bug in nunit. See https://github.com/nunit/nunit/issues/2263

SignalR not invoking server-side method if it has an overload which expects an instance of a class

I have this method at my Hub:
Public Sub SaveFields(ByVal changeSignal As String)
Dim foo As Integer = 5
End Sub
If I call it from client-side like this:
testHub.server.saveFields("abc");
then SaveFields is called successfully. However, if I have a Class like this:
Public Class WOChangeSignal
Public WOID As Integer
Public FieldUpdates As Dictionary(Of String, String)
End Class
and add an overload for SaveFields like this:
Public Sub SaveFields(ByVal changeSignal As WOChangeSignal)
Dim foo As Integer = 5
End Sub
Public Sub SaveFields(ByVal changeSignal As String)
Dim foo As Integer = 5
End Sub
then my call of
testHub.server.saveFields("abc");
will be unsuccssful, just like my call of
testHub.server.saveFields({
WOID: 1234,
FieldUpdates: [
{Key: 2, Value: 4},
{Key: 3, Value: 5}
]
});
as none of these tries are actually invoking the server-side method. As a consequence, I assume that the problem is the overload which expects an instance of a Class. So, my question is as follows: why is SignalR not invoking none of the overloads if I add an overload expecting WOChangeSignal parameter?
It turns out that this is the cause:
/// <summary>
/// Searches the specified <paramref name="hub">Hub</paramref> for the specified <paramref name="method"/>.
/// </summary>
/// <remarks>
/// In the case that there are multiple overloads of the specified <paramref name="method"/>, the <paramref name="parameters">parameter set</paramref> helps determine exactly which instance of the overload should be resolved.
/// If there are multiple overloads found with the same number of matching parameters, none of the methods will be returned because it is not possible to determine which overload of the method was intended to be resolved.
/// </remarks>
/// <param name="hub">Hub to search for the specified <paramref name="method"/> on.</param>
/// <param name="method">The method name to search for.</param>
/// <param name="descriptor">If successful, the <see cref="MethodDescriptor"/> that was resolved.</param>
/// <param name="parameters">The set of parameters that will be used to help locate a specific overload of the specified <paramref name="method"/>.</param>
/// <returns>True if the method matching the name/parameter set is found on the hub, otherwise false.</returns>
public bool TryGetMethod(HubDescriptor hub, string method, out MethodDescriptor descriptor, IList<IJsonValue> parameters)
{
string hubMethodKey = BuildHubExecutableMethodCacheKey(hub, method, parameters);
if (!_executableMethods.TryGetValue(hubMethodKey, out descriptor))
{
IEnumerable<MethodDescriptor> overloads;
if (FetchMethodsFor(hub).TryGetValue(method, out overloads))
{
var matches = overloads.Where(o => o.Matches(parameters)).ToList();
// If only one match is found, that is the "executable" version, otherwise none of the methods can be returned because we don't know which one was actually being targeted
descriptor = matches.Count == 1 ? matches[0] : null;
}
else
{
descriptor = null;
}
// If an executable method was found, cache it for future lookups (NOTE: we don't cache null instances because it could be a surface area for DoS attack by supplying random method names to flood the cache)
if (descriptor != null)
{
_executableMethods.TryAdd(hubMethodKey, descriptor);
}
}
return descriptor != null;
}
As we can see, if there is not exactly a single match, then descriptor will be null. It turns out that this is by design and the reason given is as follows:
If only one match is found, that is the "executable" version,
otherwise none of the methods can be returned because we don't know
which one was actually being targeted

Error: member names cannot be the same at their enclosing type

I was using ASP.NET4.5 and visual studio 2013 to create a sample application Wingtip Toys. But when trying to display data item and details It showing error in the last line of code bellow which is-
protected global::System.Web.UI.WebControls.ListView ProductList;
ProductList: member names cannot be the same at their enclosing type.
namespace WingtipToys
{
public partial class ProductList
{
/// <summary>
/// ProductList control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.ListView ProductList;
}
}
The class ProductList cannot contain a field, property, or method named ProductList as well. Try using the following code instead:
public partial class ProductList
{
/// <summary>
/// ProductList control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.ListView Products;
}
Likewise, a namespace cannot contain a class with the same name as the namespace.

How do I copy from a const generic object?

I'm working on a generic circular buffer but have hit a stumbling block when it comes to the copy constructor (see the code example below).
using namespace System;
/// A generic circular buffer with a fixed-size internal buffer which allows the caller to push data onto the buffer, pop data back off again and provides direct indexed access to any element.
generic<typename T>
public ref class CircularBuffer
{
protected:
array<T, 1>^ m_buffer; /// The internal buffer used to store the data.
unsigned int m_resultsInBuffer; /// A counter which records the number of results currently held in the buffer
T m_nullValue; /// The value used to represent a null value within the buffer
public:
CircularBuffer(unsigned int size, T nullValue):
m_buffer(gcnew array<T, 1>(size)),
m_nullValue(nullValue),
m_resultsInBuffer(0)
{
}
/// <summary>
/// Copy constructor
/// </summary>
CircularBuffer(const CircularBuffer^& rhs)
{
CopyObject(rhs);
}
/// <summary>
/// Assignment operator.
/// </summary>
/// <param name="objectToCopy"> The Zph2CsvConverter object to assign from. </param>
/// <returns> This Zph2CsvConverter object following the assignment. </returns>
CircularBuffer% operator=(const CircularBuffer^& objectToCopy)
{
CopyObject(objectToCopy);
return *this;
}
protected:
/// <summary>
/// Copies the member variables from a Zph2CsvConverter object to this object.
/// </summary>
/// <param name="objectToBeCopied"> The Zph2CsvConverter to be copied. </param>
void CopyObject(const CircularBuffer^& objectToBeCopied)
{
m_buffer = safe_cast<array<T, 1>^>(objectToBeCopied->m_buffer->Clone());
m_nullValue = objectToBeCopied->m_nullValue; // <-- "error C2440: '=' : cannot convert from 'const T' to 'T'"
m_resultsInBuffer = objectToBeCopied->m_resultsInBuffer;
}
};
Compiling this gives me error C2440: '=' : cannot convert from 'const T' to 'T'
Typically I'd be using this with my own ref classes which include pointers to managed and unmanaged memory so the contents of the buffer would need to be deep copied if the entire buffer is duplicated.
What am I missing here? Why can't I copy from something of type const T to something of type T?
Another entry in the continuing saga of "C++/CLI doesn't really support const".
The copy constructor in C++/CLI is T(T%). The assignment operator is T% operator=(T%). No const and no ref.
A good place to see them used is vc/include/cliext, home of the STL/CLR implementation classes. Don't use them.