我在这里链接我的类构造函数的动机是,我有一个默认构造函数供我的应用程序主流使用,第二个允许我注入一个mock和一个stub.
在":this(...)"调用中看起来有点丑陋的"新"事物并且反直觉地从默认构造函数中调用参数化构造函数,我想知道其他人会在这做什么?
(仅供参考 - > SystemWrapper)
using SystemWrapper;
public class MyDirectoryWorker{
// SystemWrapper interface allows for stub of sealed .Net class.
private IDirectoryInfoWrap dirInf;
private FileSystemWatcher watcher;
public MyDirectoryWorker()
: this(
new DirectoryInfoWrap(new DirectoryInfo(MyDirPath)),
new FileSystemWatcher()) { }
public MyDirectoryWorker(IDirectoryInfoWrap dirInf, FileSystemWatcher watcher)
{
this.dirInf = dirInf;
if(!dirInf.Exists){
dirInf.Create();
}
this.watcher = watcher;
watcher.Path = dirInf.FullName;
watcher.NotifyFilter = NotifyFilters.FileName;
watcher.Created += new FileSystemEventHandler(watcher_Created);
watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
watcher.Renamed += new RenamedEventHandler(watcher_Renamed);
watcher.EnableRaisingEvents = true;
}
public static string MyDirPath{get{return …Run Code Online (Sandbox Code Playgroud) 看着System.Windows.Threading.Dispatcher(由Reflector反编译)我遇到了;
[field: SecurityCritical]
public event DispatcherUnhandledExceptionFilterEventHandler UnhandledExceptionFilter;
Run Code Online (Sandbox Code Playgroud)
我不承认属性声明的'field'部分,它是什么?
编辑:
这是它在参考源中的显示方式:
public event DispatcherUnhandledExceptionFilterEventHandler UnhandledExceptionFilter
{
[SecurityCritical]
[UIPermissionAttribute(SecurityAction.LinkDemand,Unrestricted=true)]
add
{
_unhandledExceptionFilter += value;
}
[SecurityCritical]
[UIPermissionAttribute(SecurityAction.LinkDemand,Unrestricted=true)]
remove
{
_unhandledExceptionFilter -= value;
}
}
Run Code Online (Sandbox Code Playgroud) 在下面的XAML中,我使用带有Border的Rectangle作为ToggleButton的模板.我希望BorderBrush是一个不同的颜色来反映ToggleButton.IsChecked的变化值.不幸的是,我在DataTrigger中使用TemplateBinding的尝试不起作用.我需要做什么呢?
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<ControlTemplate x:Key="ButtonAsSwatchTemplate">
<Border BorderThickness="1">
<Border.Style>
<Style>
<Setter Property="BorderBrush" Value="Gainsboro" />
<Style.Triggers>
<!-- TemplateBinding doesn't work.-->
<DataTrigger
Binding={TemplateBinding Property=IsChecked}
Value="True">
<Setter Property="BorderBrush" Value="Black" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<Rectangle Fill="{TemplateBinding Property=Background}"
Width="15" Height="15" />
</Border>
</ControlTemplate>
</StackPanel.Resources>
<ToggleButton Template="{StaticResource ButtonAsSwatchTemplate}"
HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="2" Background="Red" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
编辑
当我构建并重新加载设计器时,我收到以下错误:
错误1属性"绑定"不支持"TemplateBindingExpression"类型的值.
解
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<ControlTemplate x:Key="ButtonAsSwatchTemplate">
<Border x:Name="SwatchBorder" BorderThickness="1">
<Rectangle Fill="{TemplateBinding Property=Background}" Width="15" Height="15" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="ToggleButton.IsChecked" Value="True">
<Setter TargetName="SwatchBorder" Property="BorderBrush" Value="Yellow" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate> …Run Code Online (Sandbox Code Playgroud) 我在前一天在我的网络驱动器(其中一个)上设置的SVN存储库中提交/更新提交时遇到了麻烦.
我是指使用url的存储库:
file://mynetworkdrive/Documents/subversion/code/sln/trunk/MyWebsite/trunk/Home
Run Code Online (Sandbox Code Playgroud)
当我从VS 2010的Solution上下文菜单中选择Update或Commit选项时,我会看到一个对话框窗口,显示如下所示的异常:

SharpSvn.SvnRepositoryIOException: Commit failed (details follow): ---> SharpSvn.SvnRepositoryIOException: Unable to connect to a repository at URL 'file://mynetworkdrive/Documents/subversion/code/sln/trunk/MyWebsite/trunk/Home' ---> SharpSvn.SvnRepositoryIOException: Unable to open an ra_local session to URL ---> SharpSvn.SvnRepositoryIOException: Unable to open repository 'file://mynetworkdrive/Documents/subversion/code/sln/trunk/MyWebsite/trunk/Home' ---> SharpSvn.SvnSystemException: Can't open file '\\mynetworkdrive\Documents\subversion\code\sln\trunk\MyWebsite\trunk\Home\format': Logon failure: unknown user name or bad password.
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
--- End …Run Code Online (Sandbox Code Playgroud) 我正在使用PropertyDescriptor和ICustomTypeDescriptor(仍然)尝试将WPF DataGrid绑定到一个对象,数据存储在一个Dictionary中.
因为如果你向WPF DataGrid传递一个Dictionary对象列表,它将根据字典的公共属性(Comparer,Count,Keys和Values)自动生成列,我的Person子类为Dictionary,并实现ICustomTypeDescriptor.
ICustomTypeDescriptor定义了一个返回PropertyDescriptorCollection的GetProperties方法.
PropertyDescriptor是抽象的,所以你必须将它子类化,我想我有一个构造函数,它接受Func和一个Action参数,它们委托字典中值的获取和设置.
然后我为字典中的每个Key创建一个PersonPropertyDescriptor,如下所示:
foreach (string s in this.Keys)
{
var descriptor = new PersonPropertyDescriptor(
s,
new Func<object>(() => { return this[s]; }),
new Action<object>(o => { this[s] = o; }));
propList.Add(descriptor);
}
Run Code Online (Sandbox Code Playgroud)
问题是每个属性得到它自己的Func和Action但它们都共享外部变量s所以尽管DataGrid自动生成"ID","FirstName","LastName","Age","Gender"的列,它们都得到了设置为"性别",这是foreach循环中s的最终静止值.
如何确保每个委托使用所需的字典密钥,即Func/Action实例化时的s值?
非常感谢.
这是我的其余想法,我只是在这里尝试这些不是'真正'的类......
// DataGrid binds to a People instance
public class People : List<Person>
{
public People()
{
this.Add(new Person());
}
}
public class Person : Dictionary<string, object>, ICustomTypeDescriptor
{
private static PropertyDescriptorCollection descriptors;
public Person() …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Grid.IsSharedSizeScope来排列由GridControl中第一列中某些控件旁边的ItemsControl显示的数据绑定控件.
问题是我不能阻止控制器不断垂直增长.
如何在不设置MaxHeight属性的情况下阻止他们这样做.我已尝试在不同的地方设置VerticalAlignment和VerticalContentAlignment的不同设置,但无法弄明白.
<Grid Grid.IsSharedSizeScope="True" >
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="RowOne" />
<RowDefinition SharedSizeGroup="RowTwo" />
<RowDefinition SharedSizeGroup="RowThree" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<SomeControl Grid.Row="0" Grid.Column="0" />
<SomeControl Grid.Row="1" Grid.Column="0" />
<ItemsControl Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" ItemsSource="{Binding Path=SomeSource}" ItemsPanel="{StaticResource MyHorizontalStackPanel}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="RowOne" />
<RowDefinition SharedSizeGroup="RowTwo" />
<RowDefinition SharedSizeGroup="RowThree" />
</Grid.RowDefinitions>
<SomeControl Grid.Row="0" />
<SomeControl Grid.Row="1" />
<SomeControl Grid.Row="2" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Run Code Online (Sandbox Code Playgroud) 有点愚蠢,但......
有没有办法阻止Visual Studio将.resx中的.jpg文件视为位图,以便我可以访问资源的byte []属性?
我只是想:
byte[] myImage = My.Resources.MyImage;
Run Code Online (Sandbox Code Playgroud) 我刚刚注册了名为"测试驱动开发"的Google小组,但它在2010年只有3个帖子,似乎充满了垃圾邮件.
有没有人知道一个好的TDD专注的地方,问那些可能不会受到欢迎的一般性的"主观"问题?
我想知道是否有人可以告诉我这种方法可以用其他任何方式编写,也许使用LINQ?
private static bool CompareManyFoos(ManyFoos expected, ManyFoos actual)
{
IEnumerator<Foo> expFooAtor = expected.GetEnumerator();
IEnumerator<Foo> actFooAtor = actual.GetEnumerator();
while (expFooAtor.MoveNext())
{
if (actFooAtor.MoveNext())
{
if (!FoosEqual(expFooAtor.Current, actFooAtor.Current)) return false;
}
else
{
MissingFoo(expFooAtor.Current);
return false;
}
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
编辑
我不得不修改我的示例代码,因为我犯了一些错误,对不起所有.这是原始方法,我改编了我的示例代码:
private static bool CompareXElementsChildXNodes(XElement expectedXElement, XElement actualXElement,
ref string message)
{
_itemLocator.LevelDown();
IEnumerator<XNode> expectedNodeRator = expectedXElement.Nodes().GetEnumerator();
IEnumerator<XNode> actualNodeRator = actualXElement.Nodes().GetEnumerator();
while (expectedNodeRator.MoveNext())
{
if (actualNodeRator.MoveNext())
{
if (CompareXNodes(expectedNodeRator.Current, actualNodeRator.Current, ref message))
{
_itemLocator.NextNode();
}
else
{
return false;
} …Run Code Online (Sandbox Code Playgroud) 我将需要处理一些存储事件.
window.addEventListener('storage', listener);
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用jasmine对我的代码进行单元测试.
简单地在测试中localStorage使用某些东西是setItem(key, value)行不通的,因为根据设计,不会为事件的发起者引发事件.
使用$(window).trigger('storage'...似乎是一个好主意,但我不认为这是正确的.
我看过帖子询问如何模拟本地存储,spyOn但我找不到任何处理事件.
有没有更好的方法来检查两个字符串数组是否具有相同的内容?
string[] first = new string[]{"cat","and","mouse"};
string[] second = new string[]{"cat","and","mouse"};
bool contentsEqual = true;
if(first.Length == second.Length){
foreach (string s in first)
{
contentsEqual &= second.Contains(s);
}
}
else{
contentsEqual = false;
}
Console.WriteLine(contentsEqual.ToString());// true
Run Code Online (Sandbox Code Playgroud) 我需要使用经典的asp页面修复服务器端脚本超时问题,该页面从数据库读取数千行并且鲁莽地连接字符串以创建一个庞大的html表.
我应该使用Response.Write还是使用COM来创建StringBuilder?
我不是一个经验丰富的Javascript应用程序开发人员,但是,我最近使用http://mean.io/#!/作为我的脚手架学习了一些MEAN .
我可以看到开箱即用的资产列在:
/server/config/assets.json
Run Code Online (Sandbox Code Playgroud)
当应用程序运行时,引用的资产将合并到客户端文件中:
/modules/aggregated.css
/modules/aggregated.js
Run Code Online (Sandbox Code Playgroud)
当我使用MEAN.IO的CLI创建包时:
mean package myPackage;
Run Code Online (Sandbox Code Playgroud)
并且开始在这个包中包含css或脚本,可能是将包资产放入应用程序的assets.json中是不好的做法,因为这些包应该是可重用的模块,可以添加到其他人的MEAN应用程序中.
什么是引用新包资产的正确位置,以便将它们添加到聚合过程中?
c# ×6
wpf ×2
ankhsvn ×1
asp-classic ×1
commit ×1
datatrigger ×1
enumeration ×1
javascript ×1
lambda ×1
layout ×1
mean.io ×1
performance ×1
resx ×1
tdd ×1
unit-testing ×1
wpfdatagrid ×1
xaml ×1