You can find the tasks.json file below to build these solutions separately.
You can run the task by
- pressing CTRL+SHIFT+P
- selecting Run Task
- choosing the appropriate option
A blog about .NET development and software architecture.
Unable to locate SecretManager >= 1.0.0-beta4-10173There is an easy fix: you can remove the last part of the version identifier.
"dependencies": {Files to be changed:
"SecretManager": "1.0.0-beta4-*"
},
Package path: | %UserProfile%\.dnx\packages\SecretManager\1.0.0-beta4\app\project.json |
Cache path: | %UserProfile%\.dnx\bin\packages\SecretManager\1.0.0-beta4\app\project.json |
Type 'System.String[]' with data contract name 'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.It seems RouteValueDictionary cannot manage IEnumerable or String[] as a parameter. The solution is simple, it's a well-known issue:
http://stackoverflow.com/questions/19960420/adding-array-of-complex-types-to-routevaluedictionary
Html.RenderAction(ActionName,
ControllerName,new RouteValueDictionary(new{ usual properties here }));
Partial apply by Wikipedia:
In computer science, partial application (or partial function application) refers to the process of fixing a number of arguments to a function, producing another function of smaller arity. Given a function , we might fix (or 'bind') the first argument, producing a function of type . Evaluation of this function might be represented as . Note that the result of partial function application in this case is a function that takes two arguments.
In short, that means you define (bind) some of the possible arguments and leave some to be filled in later (free).
def sum(a:Int, b:Int, c:Int):Int = a+b+c //> sum: (a: Int, b: Int, c: Int)Int sum(1,2,3) //> res11: Int = 6 def sum1 = sum(1, _:Int, _:Int) //> sum1: => (Int, Int) => Int sum1(2,3) //> res12: Int = 6 def sum2 = sum(_:Int, 2, _:Int) //> sum2: => (Int, Int) => Int sum2(1,3) //> res13: Int = 6
sum1 binds the first parameter but the other two parameters are free. As you can see from the result it gets translated to a lambda with two parameters.
sum2 binds the second parameter. The result is the same, a lambda with two parameters.
C# has no built-in operator for applying a function, so we have to write the lambdas directly.
readonly Funcsum = (x, y, z) => x + y + z; [Fact] public void Sum() { var result = sum(1, 2, 3); Assert.Equal(6, result); } [Fact] public void Sum_PartialApply_FirstParam() { Func sum1 = (y, z) => sum(1, y, z); var result = sum1(2, 3); Assert.Equal(6, result); } [Fact] public void Sum_PartialApply_SecondParam() { Func sum2 = (x, z) => sum(x, 2, z); var result = sum2(1, 3); Assert.Equal(6, result); }
There is a pattern is Scala called loan pattern. You open a resource, “loan” the resource to another function, and the loaner closes the resource.
This function expects a file a function. When it's called it creates the resource, executes the function and closes the resource.
def withPrintWriter(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close() } }
This is how it's called:
withPrintWriter( new File("date.txt"), writer => writer.println(new java.util.Date) )
Now I extended the definition with currying:
readonly Func, string>> openFile = path => handler => { var reader = new StreamReader(path); try { return handler(reader); } finally { reader.Close(); Console.WriteLine("Stream closed"); } };
Here are two examples on calling the function above:
readonly FuncreadAllLines = input => input.ReadToEnd(); readonly Func readSingleLine = input => input.ReadLine(); [Fact] public void LoanPattern_AllText() { var result = openFile("TextFile1.txt")(readAllLines); Assert.Equal("This is the test content.\r\nThis is a second line.", result); } [Fact] public void LoanPattern_ReadSingleLine() { var result = openFile("TextFile1.txt")(readSingleLine); Assert.Equal("This is the test content.", result); }
Now the code calling the function (openFile) is much simpler and there is no need for error handling in the caller. Furthermore thanks to currying, even the resource name can be bound in the constructor, hiding the resource initialization as well.