How VisitNamedDecl and VisitCXXRecordDecl are called by RecursiveASTVisitor? - clang

In RecursiveASTVisitors doc, there is are no virtual methods of name VisitNamedDecl, VisitCXXRecordDecl ..etc.
So how they are called automatically called ?

Related

In Grails can we access methods without creation of objects?

as I am new to grails but I am familiar with Java.In the following code I have Artist domain class and ArtistController class. In controller class the Artist accessing the findByName(...) directly I mean its not creating the object to access the method (or) is findByName(..) a static method so that it can be accessed using the className.staticMethodName as in Java.
class ArtistController {
def show() {
def artist = Artist.findByName(params.artistName)
// do whatever is appropriate with the artist...
}
}
You are referring to static methods. It has nothing to do with Grails vs Java, as static is present in Java also. You may want to check out the docs, but in a nutshell, a static method belongs to the class, and not an instance of that class, which is why you are able to invoke the method without a new object.

How to access instance properties of MvcApplication class inside request context?

Inside controller action you can:
MvcApplication app = this.HttpContext.ApplicationInstance as MvcApplication;
But this.HttpContext.ApplicationInstance only holds the superclass, not the derived class declared in Global.asax. Therefore any instance properties you declared there, are null;
Is there a way around this? Shouldn't there be a way to access the derived app class?
I'd like to have instances (of my helper classes), stored as instance properties inside the application instance, rather than having them as static classes.
Or do static helpers, hold no drawbacks?
There is a way around this and you've already written it:
MvcApplication app = this.HttpContext.ApplicationInstance as MvcApplication;
If you don't like that, try changing your MvcApplication class to:
public class MvcApplication : HttpApplication
{
public static MvcApplication Instance
{
get
{
// Current could be null, depending on the caller
return HttpContext.Current != null
? HttpContext.Current.ApplicationInstance
: null;
}
}
}
Then you can access your application as MvcApplication.Instance. Be cautious that Instance is not null.
Late answer (but for anyone in need of assistance).
I had this issue as well.
I think you can use the Application["myKey"] array, to set some values. Sure they aren't instance properties, but you can set a dependency injection container (like unity, who recommends this option in their code sample) , then access it from your controller with Application["myKey"].
From http://msdn.microsoft.com/en-us/library/ms178473%28VS.80%29.aspx
You should set only static data during application start. Do not set
any instance data because it will be available only to the first
instance of the HttpApplication class that is created.
There is no harm in using single static class, because your code becomes portable to non web project as well.
Ideally, instead of static properties, you can create MyApp class and wrap all app specific global data and other utility methods. And either you can create a static instance property and store instance of MyApp in HttpContext.Current.Application which is globally accessible in each request.
I think you are not aware that HttpApplication class is reused, and I suspect that your some handler is cleaning the properties.

base vs Previous in Virtual Path Provider

When you register a VirtualPathProvider, you still want the previous VPPs to work. I have seen this done in two ways: one is using base (e.g., if base.FileExists(virtualPath)) and the other is using Previous (e.g., if Previous.FileExists(virtualPath)). What is the difference between these, and is one preferred over the other?
It looks like, when you register a VirtualPathProvider with the HostingEnvironment, it provides the current VirtualPathProvider to the Initialize method of your VirtualPathProvider. This initialize method saves the provided VPP to the field _previous.
The virtual methods provided by the base class VirtualPathProvider use _previous in the following manner:
public virtual bool FileExists(string virtualPath)
{
return this._previous != null && this._previous.FileExists(virtualPath);
}
Each method checks to make sure that _previous is valued, then provides the relevant response. It seems like calling base is safer than calling Previous, because base will do all the null checking for you.

How to refresh my database

I was creating an mvc application and i had a model class with a dbcontext function the variables were in the same file. I added another field and changed the code in the edit create delete details and index views but i now get an error saying
"The model backing the 'GameDBContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data."
Imports System.Data.Entity
Public Class Game
Public Property ID() As Integer
Public Property Name() As String
Public Property Genre() As String
Public Property Price() As Decimal
Public Property Developer() As String
End Class
Public Class GameDBContext
Inherits DbContext
Public Property Games() As DbSet(Of Game)
End Class
you need to add a initializer method to the Application_Start method in Global.asax file. Ex:-
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<GameDBContext>());
Since it sounds like you're using a code first approach in developing your application, here are a couple of links that might help you:
code first development with entity framework 4
Code First/Entity Framework 4.1 Videos and Articles on MSDN
All of these can give you a better understanding of what is happening and how to work around having your database change on you.
In short, since you added another property, the entity framework table in your database is now longer in sync with your class. Since it's no longer in sync, you must manually delete this database in order to regenerate it, or you must create an initialization for the database. All of these concepts are better described in the links I have provided.
Good luck, and hope these help you some.

ASP.NET MVC: Criteria for controller's method to be an action?

I'm writing some unit tests to assert that all our controller action methods are marked with proper custom attributes, but I don't really know what the criteria is for determining whether a public method can act as MVC action or not.
I would assume that a criteria could be the return value type (it has to be ActionResult or a derivative). Is this true? What about static methods?
For a method to be considered an action, it has to meet the following criteria:
It must be public and not static
It must not have a "special" name in order to exclude constructors, events etc.
It must not be defined on System.Web.Mvc.Controller or any other base class in order to exclude .ToString() and family.
Generic methods will throw an exception, yet for some reason they are considered actions. As for the return type, it does not necessarily have to be an ActionResult, since you can return e.g. a string for text data.
I beleive all public methods in a controller are treated as actions - even one returning a string.
Determining the true list of actions on a controller is a tricky problem. The only correct answer is that it "depends"! The list that Saulius gave is pretty much correct - if you're using the default ControllerActionInvoker - which of course, most people use.
If you want to avoid duplicating the logic I would recommend using the ControllerActionInvoker itself to get the list of actions and then verify the contents of the list that it returns.
You'll have to write a class that derives from ControllerActionInvoker so that you can call the GetControllerDescriptor() method. The return value of that method is a ControllerDescriptor, which is an abstract descriptor of what the controller has. You can then call GetCanonicalActions(), which returns a list of ActionDescriptors. Each of those items represents what is typically and action method.
To hook it all up you'll need to:
Instantiate your controller
Set its ActionInvoker property to be an instance of your custom invoker
Create a ControllerContext instance that has its Controller instance set to your controller
Call a new public method on your invoker that in turn calls GetControllerDescriptor()
Then verify the results and you're done!
Of course, I haven't tried any of this but in theory it all works :)

Resources