Why no constant strings in T4MVC generated code? My guess would be compilation-time copying of constant values...
But adding constants to the generated code would allow T4MVC generated stuff to be used in attributes.
I think about something like this:
insert #line 400:
public const String ControllerNameCONST = #"<#=controller.ClassName #>";
insert #line 445:
[<#= GeneratedCode #>, DebuggerNonUserCode]
public static class ActionNamesCONST {
<#foreach (var method in controller.ActionMethodsWithUniqueNames) { #>
<# if (UseLowercaseRoutes) { #>
public const string <#=method.ActionName #> = (<#=method.ActionNameValueExpression #>).ToLowerInvariant();
<# } else { #>
public const string <#=method.ActionName #> = <#=method.ActionNameValueExpression #>;
<# }
} #>
}
So someone could use it like this:
[SomeAttribute(HomeController.ControllerNameCONST)]
//instead of
[SomeAttribute("Home")]
//or
[SomeAttribute(HomeController.ActionNamesCONST.SomeAction)]
//instead of
[SomeAttribute("SomeAction")]
Edit: used it as an autocomplete attribute on a model, so the "target" controller and action can be specified on the model. Although could rework the autocomplete attribute to take an ActionResult as parameter instead of controller+action names...
Update (12/7/2011): this issue is now fixed (in 2.6.65). See http://mvccontrib.codeplex.com/workitem/7177.
T4MVC does generate many constants. e.g.
For the controller name: MVC.Home.Name
For the action names: MVC.Home.ActionNames.About
For the view names: MVC.Home.Views.About
Related
Is there any way to use Strongly-Typed values in Examples table of the scenario? (or alternative solution)
I'd like to know if I made a typo in userType column already during the coding (not during running the test).
UPDATED
file.feature
Scenario Outline: Scenario123
Given Create new user of type "<userType>"
Examples:
| userType |
| PlatinumUser |
| CommonUser |
steps.cs
[Given(#"Create new user of type ""(.*)""")]
public void CreateNewUser(UserTypeEnum userType)
{
// some code like e.g.:
MyUser user = new MyUser(userType);
//...
}
enum UserTypeEnum { CommonUser, PlatinumUser, Spectre }
Looks like its a StepArgumentTransformation that you are after?
https://github.com/techtalk/SpecFlow/wiki/Step-Argument-Conversions
Used somehow along these lines:
[Binding]
public class Transforms
{
[StepArgumentTransformation]
public UserTypeEnum UserTypeTransform(string UserType)
{
// return the string converted into the required Enum
}
}
The step binding will see that it requires a UserTypeEnum as a parameter so it will search for all the available Step Argument Transformations within any classes with the Binding attribute and use this method to perform the conversion.
Specflow supports accepting strongly typed enum values.
Though, the scenario sends it as text (case insensitive).
example:
Scenario: Some enum test
When I send enum "Second"
Then I get the second enum
public enum ChosenOption
{
First,
Second,
Third,
}
[When(#"I send enum ""(.*)""")]
public void WhenISendEnum(ChosenOption option)
{
_scenarioContext.Set(option, nameof(ChosenOption));
}
[Then(#"I get the second enum")]
public void ThenIGetTheSecondEnum()
{
var chosen = _scenarioContext.Get<ChosenOption>(nameof(ChosenOption));
chosen.Should().Be(ChosenOption.Second);
}
Laravel:
ErrorException in Model.php line 2336: in_array() expects parameter 2
to be array, string given
class Student extends Model
{
protected $guarded = 'student_id';
//protected $fillable = ['full_name', 'current_grade','branch'];
}
should I use fillable ? because when I use guarded alone its throwing this error
You need to pass in an array even when you only have one item in guarded.
protected $guarded = ['student_id'];
How do I return values from a taglib that has been called in a controller action such that it automatically retains the full type structure of the values setup in the taglib?
I can use the out << approach but this returns strings or array of strings.
I have tried to use a [] mapping as used transfer a set of values at the end of an action to its view.
I have also tried a return statement again unsuccessfully - besides I need to return more than one set of values.
-mike
from the top of the documentation http://grails.org/doc/latest/guide/theWebLayer.html#tagReturnValue
class ObjectReturningTagLib {
static returnObjectForTags = ['content']
def content = { attrs, body ->
someValue()
}
}
I think this could solve your problem
package com.campaign
import java.util.*;
class UserDetailsTagLib {
def springSecurityService
static namespace = "jft"
#here we are defining that this getPrincipal and getArrayListAsObj tag used to return object
static returnObjectForTags = ['getPrincipal','getArrayListAsObj']
#this tag will return obj
def getPrincipal = {
return springSecurityService.principal
}
# this tag is used to return the array list of string
def getArrayListAsObj = { attrs , body ->
ArrayList arrayList = new ArrayList();
arrayList.add("C");
arrayList.add("A");
arrayList.add("E");
arrayList.add("B");
arrayList.add("D");
arrayList.add("F");
return arrayList
}
}
I understand your problem. If you want to have the Intellisense on the var you got from a taglib, the only thing you can have is this (it's a little redundant)
In a gsp for example, if you have a TagLib with namespace myTaglib:
First call the action of your taglib to set the value of a var:
<myTaglib:person var="currentUserFromTaglib" />
Where the person tag in the myTaglib is just for this purpose:
def person = { attrs ->
this.pageScope."$attrs.var" = new Person(name:'Giuseppe', surname:'Iacobucci')
}
After this, you need to write:
<g:set var="currentUser" value="${currentUserFromTaglib as Person}"/>
And include in you gsp:
<%# page import="your.package.Person" %>
After that, in the gsp currentUser is recognized as type Person.
In a controller, you simply call the myTaglib and cast the result like so:
def myvar = myTaglib.person() as Person
Obviously if you need more a complex object as I read from your comments, then create a plain UI object with all information you need inside and do the same trick.
Hey there! I'm trying to write a POCO class in proper F#... But something is wrong..
The C# code that I want to "translate" to proper F# is:
public class MyTest
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
}
The closest I can come to the above code in F# is something like:
type Mytest() =
let mutable _id : int = 0;
let mutable _name : string = null;
[<KeyAttribute>]
member x.ID
with public get() : int = _id
and public set(value) = _id <- value
member x.Name
with public get() : string = _name
and public set value = _name <- value
However when I try to access the properties of the F# version it just returns a compile error saying
"Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved."
The code thats trying to get the property is a part of my Repository (I'm using EF Code First).
module Databasethings =
let GetEntries =
let ctx = new SevenContext()
let mydbset = ctx.Set<MyTest>()
let entries = mydbset.Select(fun item -> item.Name).ToList() // This line comes up with a compile error at "item.Name" (the compile error is written above)
entries
What the hell is going on?
Thanks in advance!
Your class definition is fine, it's your LINQ that has a problem. The Select method is expecting an argument of type Expression<Func<MyTest,T>> but you're passing it a value of type FSharpFunc<MyTest,T> - or something similar to that anyway.
The point is you can't use F# lambda expressions directly with LINQ. You need to write your expression as an F# Quotation and then use the F# PowerPack to run the code against an IQueryable<> data source. Don Syme has a good overview of how this works.
Here is the domain class I have defined:
package mypackage
public enum UFModeType {
I(0),
O(1),
R(3)
Integer mode
public UserFileModeType(Integer mode) {
this.mode = mode;
}
static list() {
[I, O, R]
}
}
This is a property of another domain Parent where it is as follows:
package mypackage
class Parent {
String name
... ... ...
UFModeType uFMode
static mapping = {
table 'parent_table_with_ufMode_col_as_number'
version false
tablePerHierarchy false
id generator:'sequence', params:[sequence:'myseq']
columns {
id column:'parentid'
uFMode column: 'UFMODE'
}
}
static constraints = {
userFileMode(nullable: true)
}
}
The gsp call for this looks like this:
g:select name="uFMode" from="${mypackage.UFModeType?.list()}" value="${parentInstance?.uFMode?.name()}" /
I have tried a lot of variants of the above in the gsp call but I am getting error that the db insert fails saying the entry of ufmode is invalid number, thus this is not being passed as a number. I printed the params in the controllers save and it shows this:
Params in save=[uFMode:I ...
I am sure I may be missing some minor thing in syntax, but I have tried a lot of things without much success, so any inputs will be greatly appreciated.
Thanks!
Try changing
value="${parentInstance?.uFMode?.name()}
to
value="${parentInstance?.uFMode?.mode()}
From the definition of UFModeType you give you do not have a name attribute.