Having pulled this codebase:
https://github.com/RedRiverSoftware/FromHeaderAttribute
after reading this:
https://river.red/binding-to-and-validating-http-headers-with-web-api-2/
I am trying to change this:
public IHttpActionResult EchoHeaders([RedRiver.FromHead.FromHeader]StandardHeaders headers)
to this:
public IHttpActionResult EchoHeaders([FromHeader]StandardHeaders headers)
Obviously, I needed to add this to the top of the controller class:
using FromHeaderAttribute.Sample.Models;
But I am getting this error:
'FromHeaderAttribute' is not an attribute class.
However, looking at the code (which I have not changed) the 'FromHeaderAttribute' class clearly inherits 'ParameterBindingAttribute' which inherits 'System.Attribute'.
What am I missing to be able to define attributes which can be used as parameter attributes without specifying their whole namespace - just like attributes such as 'FromUri' and 'FromBody'?
Turns out that naming a class 'FromHeader' and trying to use it as a parameter attribute will not get recognised. I've tried this with a number of different combinations of file, class and namespace names and it just doesn't work. The attribute class name must be anything except FromHeader.
Related
Is there a way to check if a Class with a certain name exists in Parse?
In my db I am creating classes on the fly and want to check if a Class exists before querying it.
I know one way would be to store all the names of the class in a dedicated class just with the names of the created classes and then to query that. I am wondering if there is a more direct approach
I think there is not yet a method implemented to check if the class exist. What you can do, is do a query on the class name and if it returns an empty list of objects, it is fair to assume that the class does not exist.
You can make a get request on the "schema api" for the class whose existence you want to check.
If the class is not found then an error message is returned clearly stating that the class doesn't exist/ not found.
Here is the link showing how to make a fetch request on the class schema:
http://parseplatform.github.io/docs/rest/guide/#fetch-the-schema
Hope it helps!
I'm trying to create a base form using generics, so I could do sth like this:
public class GenericForm<T> : Form where T : IEntity
And then:
public class ManageCustomerForm : GenericForm<Customer>
But I'm not able to view ManageCustomerForm's designer. I understand it's because VS attempts to create an instance of GenericForm but doesn't know what type to use on T.
So I tried some solutions using TypeDescriptionProviders, cause it works for the case in which the base form class is abstract. But it doesn't work either. Is it possible?
One detail is I'd like to avoid to create an intermediate class like this:
public class GenericForm<T> : Form where T : IEntity
public class ManageCustomerIntermediateForm : GenericForm<Customer>
public class ManageCustomerForm : ManageCustomerIntermediateForm
I imagine that Customer is data for the form. Instead of binding the data to the form, use a separate data class for the Customer. DataBinding can be used to tie the user interface controls to the data source.
Another idea is to use the Model-View-Controller design pattern to separate the form (the view) from the model (the customer).
I have a Helper method that I need to use across multiple views. In an attempt to accomplish this, I tried to implement the approach shown by Scott Guthrie here: http://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3-and-the-helper-syntax-within-razor.aspx. For the sake of reference, my helper method looks like the following:
#helper MyMethod(string parameter)
{
MyNamespace.MyClass.HelperMethod(this.Request, parameter)
}
As you can see, I need to get access to the HttpRequestBase object associated with the view. The code works fine if I define the method at the top of _Layout.cshtml. However, I need to use it in other views. So, as mentioned, I used the approach highlighted by scottgu. Unfortunately, I get a runtime error now that says:
"CS0026: Keyword 'this' is not valid in a static property, static method, or static field initializer"
How can I get over this hump?
If it's the HttpRequestBase object you need, try passing in HttpContext.Current.Request instead of this.Request.
I want to set up a code snippet (in this case in C#) to create a property which is additionally initialized in the class constructor, which includes that code is not only inserted in the class body but also explicitly in the constructor. Is that possible with just one snipped, and if yes: how?
Thanks in advance!
I'm not sure i've completely understood your question, but you can use this tool :
http://snippeteditor.codeplex.com/
You can write a snippet for a class which contains one property set in the class constructor
Take a look at the class and prop or propfull snippets, it should help you
I want to extend CMFCRibbonPanel - but the constructor is protected (I get the following error: cannot access protected member declared in class 'CMFCRibbonPanel'). The only way to obtain a CMFCRibbonPanel instance is by calling "category->AddPanel", but this way I cannot extend the CMFCRibbonPanel class.
Any suggestions?
A protected constructor is accessible from within the derived class.
My guess is that your derived class CTor is protected, too.
If you make it public, that should work.