Q:

Custom Controller.cs.t4 only works when wrong

I have copied the T4 scaffolding templates into my Visual Studio 2017 project so I can customize them. Mostly it's working fine.  But one line in Controller.cs.t4 is causing a headache.
This problematic line needs to be like this for scaffolding to work:
var entitySetVar = EntitySetVariable ?? (String.IsNullOrEmpty(entitySetName) ? entitySetName : (entitySetName.Substring(0, length:1).ToLowerInvariant() + entitySetName.Substring(1)));

And it has to be like this for the project to build:
var entitySetVar = EntitySetVariable ?? (String.IsNullOrEmpty(entitySetName) ? entitySetName : (entitySetName.Substring(0, length-1).ToLowerInvariant() + entitySetName.Substring(1)));

Note the difference: length:1  vs  length-1
With length:1 I get syntax errors immediately, but scaffolding works fine.
With length-1, no syntax errors, but scaffolding fails saying: "Compiling transformation: The name 'length' does not exist in the current context' at line number '54' and column number '127'"
Can someone explain what is going on and/or suggest a fix? Switching back and forth is getting old. 

A:

The solution was to use the Length property of the string like this:
var entitySetVar = EntitySetVariable ?? (String.IsNullOrEmpty(entitySetName) ? entitySetName : (entitySetName.Substring(0, entitySetName.Length-1).ToLowerInvariant() + entitySetName.Substring(1)));

