Error: member names cannot be the same at their enclosing type - asp.net-4.5

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.

Related

How to display comments as description paragraphs in Swagger in an ASP.NET Core API

I have a web api in asp.net-core and I wanted to know how to put paragraphs as descriptions on the end points? I tried \n \n , nothing works. I am putting the description in the "remarks" xml.
Thanks
First, you must configure Swashbuckle to use the documentation XML.
Then, use <summary> and <remarks> tags for operation summary and description.
/// <summary>
/// Summary for ActionWithSummaryAndRemarksTags
/// </summary>
/// <remarks>
/// Remarks for ActionWithSummaryAndRemarksTags
/// </remarks>
public ActionResult ActionWithSummaryAndRemarksTags()
You can use Markdown to construct more complex documents:
/// <summary>
/// This is a short summary
/// </summary>
/// <remarks>
/// ## Usage
/// ...
/// ```
/// <![CDATA[
/// {
/// "html": "<h1>escape HTML with CDATA blocks</h1><img src=\"https://unsplash.it/400/200\" />"
/// }
/// ]]>
/// ```
///
/// ### A title
/// A paragrapth with [a link](https://example.com).
///
/// ```html
/// <h1>hello world, this is a code block</h1>
/// <img src="data:image/jpg,base64;..." />
/// ```
/// This is an inline code `https://unsplash.it/200/100`.
///
/// This is a separate paragraph
/// </remarks>

WebApi HelpPage HttpResponseMessage SetActualResponseType

I am using the WebApi Help pages within an MVC4 project.
As per the following link, http://blogs.msdn.com/b/yaohuang1/archive/2012/10/13/asp-net-web-api-help-page-part-2-providing-custom-samples-on-the-help-page.aspx I have been setting the HelpPageConfig to set actual response types.
I have a controller that has two get methods on it
/// <summary>
/// Get the list of plans for a specified portfolio
/// </summary>
/// <param name="portfolioIdentifier">Portfolio Identifier (guid)</param>
/// <returns>
/// Returns a list of <see cref="RestDTOs.Plan"/> Plan objects
/// </returns>
public HttpResponseMessage Get(Guid portfolioIdentifier)
{
}
/// <summary>
/// Get full plan details.
/// </summary>
/// <param name="planIdentifier">Plan Identifier (guid)</param>
/// <returns>
/// Returns the <see cref="RestDTOs.Plan"/> Plan object
/// </returns>
[HttpGet]
public HttpResponseMessage Detail(Guid planIdentifier)
{
}
Within HelpPageConfig.cs i have added the following to try and set an example ResponseBody format
config.SetActualResponseType(typeof(Plan), "Plan", "GET");
This is working great on the Get method, but is not producing anything on the Detail method
What do I need to add to the HelpPageConfig so that the web api help will pick up and produce samples for the Detail method
MVC 5 has a built in attribute to set the response type.
More information here:
http://thesoftwaredudeblog.wordpress.com/2014/01/05/webapi-2-helppage-using-responsetype-attribute-instead-of-setactualresponsetype/
Just use:
ResponseType(typeof([Your_Class]))]
Try config.SetActualResponseType(typeof(Plan), "Plan", "Detail");...the second parameter here is expecting an action name...I see you are using Web API 1, so just FYI...in Web API 2, there is an attribute called ResponseType which you can use to decorate on an action to describe the actual response type for a given action..

WCF Data Service - Restrict visibility and logging queries

I have two questions related to WCF Data Service:
is there a way to restrict the entities visible to a user according to her privileges ? For instance user in role super-user should be able to query the full 'Contact' entity but user with less privileges would only be able to see specific properties of the 'Contact' entity.
whenever a user runs a query on the service, I would like this to be logged in a database for audit purpose. Is this possible ?
1) There is the concept of interceptors: http://msdn.microsoft.com/en-us/library/dd744842.aspx
But I think they won't satisfy you in your case:
With change interceptors you can handle requests which try to change a specific entity. This could help you to avoid users without certain privileges to add/change/delete contact entities. With QueryInterceptors you can handle GET-Requests. But they don't allow you to restrict certain properties of your contact entity.
You are not the first with such requirements -> WCF Dataservice - modify object before returning results?
Maybe you could use a combination of a (custom) ServiceOperation and a View to handle this.
2) Yes, you can do this for instance by handling the ProcessingRequest-Event:
public class YourService : DataService<Entities>
{
/// <summary>
/// The logger.
/// </summary>
private readonly LogWriter logger;
/// <summary>
/// Initializes a new instance of the <see cref="YourService"/> class.
/// </summary>
public YourService()
{
this.logger = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
this.ProcessingPipeline.ProcessingRequest += this.ProcessingPipelineProcessingRequest;
}
/// <summary>
/// OnProcessingRequest
/// </summary>
/// <param name="sender">source</param>
/// <param name="e">event args</param>
public void ProcessingPipelineProcessingRequest(object sender, DataServiceProcessingPipelineEventArgs e)
{
this.logger.Write(new LogEntry { Message = "SOP ProcessingPipelineProcessingRequest: Unauthorized Access", Severity = TraceEventType.Warning })
}
}
You can find all those ProcessingPipeline-Events here: http://msdn.microsoft.com/en-us/library/system.data.services.dataserviceprocessingpipeline(v=vs.103).aspx

VS2010 VB.NET XML Comments for class field not showing

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.

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.