Hi I am just starting out with T4 templates and I need to generate a javascript file based on the actions in my controller.
I got the code all figured out forgetting the controllers and actions my only problem is that I am getting this error in the T4 template file and I do not understand it:
Compiling transformation: A namespace cannot directly contain members such as fields or methods
This is my code:
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="$(TargetPath)" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="eConnect.WebApi.Helpers.T4.ControllerDetails" #>
<#@ import namespace="System.Web.Http;"#>
<#@ output extension=".js" #>
define(['services/logger',
'services/jsonDataService',
'services/config',
'services/cachingService'],
function (logger, jsonDataService, config, cache) {
var dataService = { };
return dataService;
});
<#
var controllers = ControllersInfo.GetControllers();
foreach(var controller in controllers) {
Dictionary<string, ParameterInfo[]> actions = ControllersInfo.GetAllCustomActionsInController(controller, new HttpGetAttribute());
}
#>
There is also an external class that gets the controllers and actions but I do not think it's necesary for the current problem.
What am I doing wrong?
Error CS0116: A namespace cannot directly contain members such as fields or methods - Unity Forum.
A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.
The namespace keyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types.
You probably have this figured out by now but:
<#@ import namespace="System.Web.Http;"#>
Note the ';'
Instead write:
<#@ import namespace="System.Web.Http"#>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With