小编Ber*_*ryl的帖子

visual studio不记得打开文档和启动项目

在过去的一周里,我的VS解决方案发生了一些变化,我还没有找到解决它的设置.

当我关闭解决方案并重新启动时:

  1. 启动项目恢复到与上次关闭时选择的不同的项目
  2. 我的项目heirarchy不是什么时候关闭 - 每个项目都扩展了
  3. 关闭时打开的文件全部关闭

在每种情况下,我希望解决方案看起来就像我最后关闭时一样.

我该如何做到这一点?

干杯,
Berryl

visual-studio-2010 visual-studio

95
推荐指数
12
解决办法
4万
查看次数

如何知道PropertyInfo是否是一个集合

下面是我用来获取IsDirty检查的类中所有公共属性的初始状态的一些代码.

查看属性是否为IEnumerable的最简单方法是什么?

干杯,
Berryl

  protected virtual Dictionary<string, object> _GetPropertyValues()
    {
        return _getPublicPropertiesWithSetters()
            .ToDictionary(pi => pi.Name, pi => pi.GetValue(this, null));
    }

    private IEnumerable<PropertyInfo> _getPublicPropertiesWithSetters()
    {
        return GetType().GetProperties().Where(pi => pi.CanWrite);
    }
Run Code Online (Sandbox Code Playgroud)

UPDATE

我最后做的是添加一些库扩展,如下所示

    public static bool IsNonStringEnumerable(this PropertyInfo pi) {
        return pi != null && pi.PropertyType.IsNonStringEnumerable();
    }

    public static bool IsNonStringEnumerable(this object instance) {
        return instance != null && instance.GetType().IsNonStringEnumerable();
    }

    public static bool IsNonStringEnumerable(this Type type) {
        if (type == null || type == typeof(string))
            return false;
        return typeof(IEnumerable).IsAssignableFrom(type);
    }
Run Code Online (Sandbox Code Playgroud)

c# reflection

58
推荐指数
3
解决办法
3万
查看次数

UriFormatException:无效的URI:指定的端口无效

Uri下面用作参数的程序集限定字符串在XAML中工作,但在代码中使用时会显示错误.

我尝试了各种各样的UriKind同样的结果.我怎样才能解决这个问题?

[Test]
public void LargeImageSource_IsKnown()
{
var uri = new Uri(
        "pack://application:,,,/" + 
        "MyAssembly.Core.Presentation.Wpf;component/" + 
        "Images/Delete.png", UriKind.RelativeOrAbsolute);

Assert.That(
        _pickerActivityCollectionVm.DeleteActivityCommand.LargeImageSource,
        Is.EqualTo(uri));
}

System.UriFormatException : Invalid URI: Invalid port specified.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
Run Code Online (Sandbox Code Playgroud)

UPDATE

基于Thomas的精湛答案以及我对可读性的评论,我在BaseTestFixture类中使用了以下内容.希望这有助于其他人.

    protected virtual void OnFixtureSetUp() {
        // logging, other one time setup stuff...

        const string scheme = "pack";
        if (!UriParser.IsKnownScheme(scheme)) {
            Assert.That(PackUriHelper.UriSchemePack, Is.EqualTo(scheme));
        }
    }
Run Code Online (Sandbox Code Playgroud)

wpf resources xaml uri

57
推荐指数
3
解决办法
2万
查看次数

WPF datagrid头文本绑定

由于某种原因,DataGrid的列标题不是FrameWork元素,因此您不能使用绑定来设置标题文本之类的内容.如果用.NET 4.0改变了(如果我现在使用的是CodePlex的最新WPFToolkit),请纠正我.

我正在尝试使用DataGrid进行时间表演示,其中日期应该是标题文本的一部分(即"Sun,Nov 01"),我在XAML中有以下内容:

        <dg:DataGrid.Columns>
        <dg:DataGridTextColumn Header="Description" Width="Auto" Binding="{Binding Description}" IsReadOnly="True"/>
        <dg:DataGridTextColumn Header="Mon" Width="50" Binding="{Binding Allocations[0].Amount}"  />
... every other day of the week ....
        <dg:DataGridTextColumn Header="Sun" Width="50" Binding="{Binding Allocations[6].Amount}"  />
        <dg:DataGridTextColumn Header="Total" MinWidth="50" Binding="{Binding TotalAllocatedAmount}" IsReadOnly="True" />
    </dg:DataGrid.Columns>
Run Code Online (Sandbox Code Playgroud)

我想使用我用于数据的相同AllocationViewModel(即"{Binding Allocations [0] .Amount}"并将它的DisplayName属性绑定到标题文本.有人可以告诉我该怎么做吗?如果我有要使用静态资源,我如何在那里获取DataContext?

编辑----------------优先工作 - 周围

Josh Smith在一段时间后发布了一篇关于DataContextSpy的文章,这是我遇到这个问题时最干净的解决方法.这是让它工作的类:

/// <summary>
/// Workaround to enable <see cref="DataContext"/> bindings in situations where the DataContext is not redily available. 
/// </summary>
/// <remarks>http://blogs.infragistics.com/blogs/josh_smith/archive/2008/06/26/data-binding-the-isvisible-property-of-contextualtabgroup.aspx</remarks>
public class DataContextSpy : Freezable
{
    public DataContextSpy() …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf datagrid

27
推荐指数
5
解决办法
5万
查看次数

将文件从一个Visual Studio解决方案移动到另一个

我通常做的是在解决方案中创建一个新文件,我想使用它(同名),将类的内容从源解决方案复制并粘贴到目标,根据需要修复命名空间和导入.

我知道这样做的唯一另一种方法是在目标解决方案中打开源文件,然后将副本保存到该文件夹​​中,这可能会让一个解决方案中同名的两个文件打开混乱.

有没有人有更简单的方法来做到这一点?

projects-and-solutions visual-studio

27
推荐指数
2
解决办法
3万
查看次数

两个枚举之间的平等

我有两个具有完全相同的参考元素的枚举,并想知道为什么Equals不是真的.

作为一个附带问题,下面的代码比较每个元素的工作原理,但必须有一个更优雅的方式

var other = (ActivityService) obj;
if (!AllAccounts.Count().Equals(other.AllAccounts.Count())) return false;
for (int i = 0; i < AllAccounts.Count(); i++) {
    if (!AllAccounts.ElementAt(i).Equals(other.AllAccounts.ElementAt(i))) {
        return false;
    }
}
return true;
Run Code Online (Sandbox Code Playgroud)

c# linq ienumerable equality

23
推荐指数
2
解决办法
1万
查看次数

nuget包管理器不同步

我在Nuget 2.5.4.用于安装更新的"管理整个解决方案的软件包"功能会间歇性地显示"误报".

误报是指解决方案中的某些内容需要更新,但解决方案中的每个项目都已进行最新更新.至少我认为这是正在发生的事情.

例如(见下文),nuget提供帮助安装NUnit,但每个包都是灰色的.测试项目应该是灰色的,因为它们已经是最新版本.

没有NUnit的软件包也会变灰,我认为它们不应该是,所以解决方案管理员可以安装它们.所以不确定我的假阳性理论是否正确,但是某些东西是不同步的.

修复是什么?

干杯,

在此输入图像描述

在此输入图像描述

.net visual-studio-2010 nuget

20
推荐指数
3
解决办法
4465
查看次数

RoutedEventArgs vs EventArgs

我正在学习WPF/Silverlight并在MS视频播放中看到现在建议使用RoutedEventArgsEventArgs; 虽然它没有说明原因.

我有一个win表单应用程序,它使用"小部件"的接口,试图不依赖于特定的显示技术(在Presenters/ViewModels中),所以如果我的IButton Click事件现在需要采取RoutedEventArgs现在我想它不是有用.

有人可以解释我是否应该切换到RoutedEventArgs所有情况,为什么?

顺便说一句,其他人是否有关于使用界面小部件的经验/意见,因为我正在描述它们?

.net wpf events routed-events

18
推荐指数
1
解决办法
1万
查看次数

NHibernate Session.Flush&Evict vs Clear

在我想要持久化对象然后通过从db(而不是会话)中获取它来证明它是持久化的测试中,我注意到以下内容之间没有区别:

// save it
session.Clear()
// fetch it
Run Code Online (Sandbox Code Playgroud)

要么

// save it
session.Flush()
session.Evict(_instance)
// fetch it
Run Code Online (Sandbox Code Playgroud)

我这个懒惰的程序员倾向于超过两行.有没有什么理由让我更喜欢这两行呢?

nhibernate session

18
推荐指数
1
解决办法
2万
查看次数

访问代码wpf中的资源字典

同一组件中的相同代码行适用于一个测试夹具,但不适用于另一个.这是代码行:

var dic = new ResourceDictionary { Source = new Uri("pack://application:,,,/MyApp.Wpf;component/ImageResources.xaml") };
Run Code Online (Sandbox Code Playgroud)

我在另一个测试夹具中得到的错误是System.UriFormatException:无效的URI:指定的端口无效.

uri字符串也适用于xaml.有没有更好的方法在代码中加载资源字典?

干杯,
Berryl

===更新===

正如我在这篇文章中发现的那样,由于没有注册包方案,因此发生了无效端口,这可以通过以下代码完成:

if (!UriParser.IsKnownScheme("pack"))
     UriParser.Register(new GenericUriParser(GenericUriParserOptions.GenericAuthority), "pack", -1);
Run Code Online (Sandbox Code Playgroud)

我猜测能够使用pack方案加载字典而没有错误的测试夹具是因为SUT是用户控件,并且在创建用户控件的实例时以某种方式加载资源.

wpf uri resourcedictionary

16
推荐指数
1
解决办法
2万
查看次数