我使用Resharper,当我制作几行代码时:
foreach (var posCombination in possibleCombinations)
{
if (posCombination .Count == combo.Count && posCombination .Select((l, i) => combo.Contains(l)).All(b => b))
{
return true;
}
}
return false;
Run Code Online (Sandbox Code Playgroud)
它会问我是否要将其转换为LINQ表达式:
return possibleCombinations.Any(possibleCombination =>
possibleCombination.Count == combo.Count
&& possibleCombination.Select((l, i) => combo.Contains(l)).All(b => b));
Run Code Online (Sandbox Code Playgroud)
我有很多人告诉我他们很难读懂LINQ语句中的内容......那么为什么我要将它转换为LINQ表达式,如果它使我的代码不那么可读?
假设我有两个类派生于另一个类:
动物和狗
public class Animal
{
public String Name { get; set; }
}
public class Dog : Animal
{
public Boolean HasSpots { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我将动物传递给索引视图
public ActionResult Index()
{
return View(new Dog() {Name = "Dog"});
}
Run Code Online (Sandbox Code Playgroud)
索引 - 我将传入的Animal转换为带有Dog的编辑器模板.
@model MvcApplication1.Models.Animal
@using (Html.BeginForm("About", "Home", FormMethod.Post, null))
{
@Html.EditorFor(x => x, "Dog", "Animal")
<input type="submit" value="Begin" />
}
Run Code Online (Sandbox Code Playgroud)
这样可以正常工作,但是当我尝试在我的控制器中显式转换回Dog时,我将它发布到About它将不会投射.我想象一下,我将不得不创建一个自定义模型绑定器,但我不知道如何做到这一点.或者,如果我完全错过了一些东西.没有包括接口的任何方式.
(使用它作为一个小测试示例,我的实际类更复杂一些)
有没有办法挂钩 Elixir 的 Mix 内置任务以在另一个任务完成后执行任务?
我知道你可以做类似的事情。
defmodule Mix.Tasks.Other.Get
use Mix.Task
@shortdoc "Other dependencies?"
def run(_) do
Mix.Task.run("deps.get")
end
end
Run Code Online (Sandbox Code Playgroud)
但我有点希望在mix deps.get考虑使用make包装最有意义的命令后立即运行任务。(即make deps这将同时运行mix deps.get然后mix other.get)
所以这就是我的清单.
[0], [1], [2], [3], [4]
Run Code Online (Sandbox Code Playgroud)
我希望能够遍历这些 - 但这里的诀窍是我想从一个偏移开始然后循环回到那个偏移量?
恩.
[0], [1], [2], [3], [4]
o-->
//Start at offset 1 then get 2, 3, 4 then loop back around to zero
Run Code Online (Sandbox Code Playgroud)
EX2.
[0], [1], [2], [3], [4]
o-->
//Start at offset 3 then get 4, then loop back around to zero, then 1, 2
Run Code Online (Sandbox Code Playgroud)
我考虑使用常规List<T>并尝试将此概念实现为for循环但我不确定我是否想要这样做,如果他们这样做更简洁的方式.
基本上不要从0开始并循环回到开始并通过元素返回到偏移量.
我的控制器中有两个操作结果.概述和关于.
public ActionResult Overview(int id)
{
return View(new OverviewModel() { Project = db.People.Find(id) });
}
public ActionResult About(int id)
{
return View(new AboutModel() { Project = db.People.Find(id) });
}
Run Code Online (Sandbox Code Playgroud)
我想记住传递给Overview的id,并在About上使用它作为默认值.当用户将标签从Overview切换到About时,我不知道如何保持此Id不变.
如何将这种复杂模型与包含多个对象的多个图层绑定?现在我将模型传递给视图 - (填充表单/复选框树),我想要准确的模型(SubjectSelectionModel),但它没有正确绑定.
任何人都可以详细说明我需要采取的过程,以便在我看来正确绑定这些过程吗?
查看型号:
public class SubjectSelectionModel
{
public IList<Subject> Subjects { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
学科分类:
public class Subject
{
public String Name { get; set; }
public IList<Bin> Bins { get; set; }
public Subject()
{
}
public Subject(IList<Course> courses)
{
}
}
Run Code Online (Sandbox Code Playgroud)
Bin类:
public class Bin
{
public Subject Subject { get; set; }
public int Amount { get; set; }
public IList<Foo> Foos { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Foo类:
public class Foo
{
public int …Run Code Online (Sandbox Code Playgroud)