UPDATE
我将这里的各种答案结合到一个新问题的"确定"答案中.
原始问题
在我的代码中,我有一个事件发布者,它在应用程序的整个生命周期中都存在(这里简化为基本要素):
public class Publisher
{
//ValueEventArgs<T> inherits from EventArgs
public event EventHandler<ValueEventArgs<bool>> EnabledChanged;
}
Run Code Online (Sandbox Code Playgroud)
因为这个发布者可以在所有地方使用,所以我对自己创建这个小帮助类非常满意,以避免在所有订阅者中重写处理代码:
public static class Linker
{
public static void Link(Publisher publisher, Control subscriber)
{
publisher.EnabledChanged += (s, e) => subscriber.Enabled = e.Value;
}
//(Non-lambda version, if you're not comfortable with lambdas)
public static void Link(Publisher publisher, Control subscriber)
{
publisher.EnabledChanged +=
delegate(object sender, ValueEventArgs<bool> e)
{
subscriber.Enabled = e.Value;
};
}
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,直到我开始在较小的机器上使用它,当我偶尔开始:
System.ComponentModel.Win32Exception
Not enough storage is available to process …Run Code Online (Sandbox Code Playgroud) 我已经设法让xUnit处理我的小样本组件.现在我想知道我是否也可以参加FsCheck.我的问题是,在为我的函数定义测试属性时,我很难过.
也许我只是没有一套好的样本函数,但是这些函数的测试属性是什么呢?
//transforms [1;2;3;4] into [(1,2);(3,4)]
pairs : 'a list -> ('a * 'a) list //'
//splits list into list of lists when predicate returns
// true for adjacent elements
splitOn : ('a -> 'a -> bool) -> 'a list -> 'a list list
//returns true if snd is bigger
sndBigger : ('a * 'a) -> bool (requires comparison)
Run Code Online (Sandbox Code Playgroud) 我有一个WPF ListBox,我添加了一些'FooBar'对象作为项目(通过代码).FooBars不是WPF对象,只是带有覆盖ToString()函数的哑类.
现在,当我更改影响ToString的属性时,我想让ListBox更新.
谢谢...
我的存储库中只有一个cs文件,Git似乎认为它是二进制文件.(在git gui,它只是说"二进制文件不同".)
如何向Git表明我的cs文件是文本文件?
重命名文件的问题是,如果您想利用Visual Studio重构,您确实需要从Visual Studio内部进行重构.
但是大多数(并非所有*)版本控制系统也希望成为重命名的人.
一种解决方案是使用集成的源代码控制,但这并不总是可用,并且在某些情况下非常笨重.
我个人更愿意在Visual Studio之外单独使用源代码控制,但我不知道如何管理这个文件重命名问题.
那么,对于那些使用Visual Studio的人,你使用哪个源代码控制?您是否使用VS集成(哪一个?),否则,您如何解决此重命名问题?
(*git非常聪明,可以自己解决)
在做一个时git tag,我并不总是很记得HEAD~6(例如)是包容性的还是排他性的.
鉴于我的大部分提交都以问题编号为前缀,我想知道是否有一些魔术命令用于从其部分消息中搜索提交SHA.
我知道git log从那里开始工作很容易,但我想要更容易:)
编辑:有人也提出了相反的问题:在Git中,有没有办法获得任意提交的"友好"名称?
我所有的搜索都让人们提出了相反的问题,但如果用行返回和缩进保存,我有一个文件增长了近50%.
这有什么办法吗?
编辑我不是在谈论打开文件,而是保存文件.此代码为我重现了'bug':
var path = @"C:\test.xml";
System.IO.File.WriteAllText(path, "<root>\r\n\t<line></line>\r\n\t<line></line>\r\n</root>");
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.PreserveWhitespace = false;
doc.Load(path);
doc.PreserveWhitespace = false; //just in case!
doc.Save(path);
Run Code Online (Sandbox Code Playgroud)
中间的断点显示doc.InnerXml是有效的<root><line></line><line></line></root>,正如预期的那样.但最后的内容test.xml是:
<root>
<line>
</line>
<line>
</line>
</root>
Run Code Online (Sandbox Code Playgroud) 如果我有一个C#类隐式转换为double,如下所示:
public class Parameter
{
private double _value;
public Parameter(double value) { _value = value }
public static implicit operator double(Parameter p) { return _value; }
}
Run Code Online (Sandbox Code Playgroud)
F#不喜欢我试图使用它,就好像它是float:
let a = Parameter(4.0)
let b = Parameter(2.0)
let c = a * Math.Sin(b) <-- 'expected float, here Parameter'
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点(我猜不会,基于这个问题/答案),如果没有,什么是一个体面的解决方法?
我正在尝试从F#开始一个进程,等到它完成,但还要逐步读取它的输出.
这是正确/最好的方式吗?(在我的情况下,我正在尝试执行git命令,但这与问题相关)
let gitexecute (logger:string->unit) cmd =
let procStartInfo = new ProcessStartInfo(@"C:\Program Files\Git\bin\git.exe", cmd)
// Redirect to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput <- true
procStartInfo.UseShellExecute <- false;
// Do not create the black window.
procStartInfo.CreateNoWindow <- true;
// Create a process, assign its ProcessStartInfo and start it
let proc = new Process();
proc.StartInfo <- procStartInfo;
proc.Start() |> ignore
// Get the output into a string
while not proc.StandardOutput.EndOfStream do
proc.StandardOutput.ReadLine() |> logger
Run Code Online (Sandbox Code Playgroud)
我不明白的是proc.Start()如何返回一个布尔值,也足够异步,让我逐步获得输出.
不幸的是,我目前没有足够大的存储库 - 或者足够慢的机器,以便能够分辨出事情的顺序......
UPDATE
我试过Brian的建议,它确实有效.
我的问题有点模糊.我的误解是,我假设的Process.Start()返回进程的成功作为一个整体,而不是仅仅的"开始",因此我看不出它如何能 …
继这个问题的情景之后,我正在表演git rebase -s recursive -X theirs etc...并且很惊讶地被以下类型的冲突所阻止:
这个策略有没有理由不应对这些?
(我不知道这是否重要,但是git不报告输出中的冲突,它只是说When you have resolved this problem run "git rebase --continue")
更新这里的脚本不能完全重现,但几乎:
git init
git symbolic-ref HEAD refs/heads/Branch1 #just to get the 'right' branch name
echo Added in A > DeletedByThem.txt
git add -A
git commit -m A
echo Modified in B >> DeletedByThem.txt
git add -A
git commit -m B
echo Modified in C >> DeletedByThem.txt
echo Added in C …Run Code Online (Sandbox Code Playgroud) .net ×3
c# ×3
f# ×3
git ×3
binary ×1
conflict ×1
fscheck ×1
listbox ×1
rebase ×1
renaming ×1
synchronous ×1
unit-testing ×1
wpf ×1
xmldocument ×1