基本上,如果我想做以下事情:
public class SomeClass
{
private static ConcurrentDictionary<..., ...> Cache { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是否让我避免lock在整个地方使用s?
public abstract class EntityBase { ... }
public interface IFoobar
{
void Foo<T>(int x)
where T : EntityBase, new();
}
public interface IFoobar<T>
where T : EntityBase, new()
{
void Foo(int x);
}
public class Foobar<T> : IFoobar, IFoobar<T>
where T : EntityBase, new()
{
public void Foo(int x) { ... }
void IFoobar.Foo<T>(int x) { Foo(x); }
}
Run Code Online (Sandbox Code Playgroud)
我收到编译器警告: Type parameter 'T' has the same name as the type parameter from outer type '...'
我尝试过:void IFoobar.Foo<U>(int x) { …
主题\ Generic.xaml:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="WPF Commons;component/Controls/Layout/Foo/FooItem.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
控制\布局\富\ FooItem.xaml:
<Style TargetType="{x:Type l:FooItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type l:FooItem}">
<Border>
<ContentPresenter ContentSource="Header" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
如果我将整个样式复制到我的usercontrol资源中,它可以正常工作.但是,如果我不这样做,则usercontrol显示为空.在Expression Blend 4中,我右键单击并选择Edit Template>,但它不会让我选择Edit a Copy...哪个让我相信某些内容严重错误并且Generic.xaml未正确加载.我认为它是Generic.xaml,因为如果我删除MergedDictionary调用并将xaml样式直接复制/粘贴到Generic.xaml中,它仍然无效.
在过去,当我想模拟一个抽象类时,我只是在扩展抽象类的代码中创建一个模拟类,然后在我的单元测试中使用该类...
public abstract class MyConverter : IValueConverter
{
public abstract Object Convert(...) { ... };
public virtual Object ConvertBack(...) { ... }
}
private sealed class MockedConverter : MyConverter { ... }
[TestMethod]
public void TestMethod1()
{
var mock = new MockedConverter();
var expected = ...;
var actual = mock.ConvertBack(...);
Assert.AreEqual(expected, actual);
}
Run Code Online (Sandbox Code Playgroud)
我想养成使用Moq的习惯.我不确定如何使用Moq来测试抽象类的默认返回值.有什么建议吗?
我只是想知道地区的意义.我想我不明白他们解决的问题.
例如,我看到很多人使用区域作为导航区域,但是为什么不只是将ItemsControl绑定到ObservableCollection而不是具有区域并将不同的导航元素加载到该区域?
一个现实世界的例子,它的使用/好处超过替代品将摇滚!
我在Jon Skeet的博客上看到了这篇文章,他谈到了字符串翻转.我想尝试他自己展示的例子,但它似乎有效...这让我相信我不知道如何创建一个包含代理对的字符串,这实际上会导致字符串反转失败.如何实际创建一个带有代理对的字符串,以便我自己可以看到失败?
基本上,我不明白这里的真正区别是什么:
TabItem的Microsoft代码使用:
<ContentPresenter ContentSource="Header" ... />
Run Code Online (Sandbox Code Playgroud)
那么,何时使用该Content属性而不是(或除此之外)ContentSource?
我在网上看到了两种不同的方法来增强IValueConverter.其中一个从MarkupExtension扩展了ValueConverter,另一个从DependencyObject扩展.我无法从两者延伸,所以我想知道是否有一个比另一个好?
我知道MVVM大量使用INotifyPropertyChanged,但我从未见过使用过任何INotifyPropertyChanging.有什么理由吗?
如果我确实想要使用它,那么将它集成到我的MVVM框架中的好方法是什么?我知道你不应该MessageBox在你的ViewModel 上使用,因为那时你无法对它进行单元测试.那么如何进行警报,然后继续使用PropertyChange(如果适用)?
我知道反思可能很昂贵.我有一个经常获取/设置属性的类,我想到的一种方法是以某种方式缓存反射.我不确定我是否应该缓存表达式或者在这里做什么.这就是我目前正在做的事情:
typeof(T).GetProperty(propName).SetValue(obj, value, null);
typeof(T).GetProperty(propName).GetValue(obj, null);
Run Code Online (Sandbox Code Playgroud)
那么......什么才能让这个更快?
c# ×7
wpf ×5
caching ×1
constraints ×1
generic.xaml ×1
generics ×1
interface ×1
locking ×1
mocking ×1
moq ×1
mvvm ×1
performance ×1
prism ×1
prism-4 ×1
properties ×1
reflection ×1
string ×1
unit-testing ×1
utf-16 ×1
utf-32 ×1
xaml ×1