小编Sha*_*ane的帖子

如何使Application.Properties.Settings公开并保持这种方式

我正在将我的应用程序设置集中到一个位置,我选择使用公共库中的Settings集合来执行此操作.

我已将所有这些设置移动到他们自己的文件中,该文件使用配置源被拉入我的app.config:

<Common.Properties.Settings configSource="config\Common.Properties.Settings.config" />
Run Code Online (Sandbox Code Playgroud)

这允许我使用Visual Studio的"添加链接"功能来覆盖我的Web和测试应用程序中导入的配置文件的默认库设置.

现在,我希望能够从我的其他库中访问所有这些出色的设置值,并且发现我只需将生成的类设为public即可:

文件:Common.Properties.Settings

public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
Run Code Online (Sandbox Code Playgroud)

这使我可以访问Common.Properties.Settings.Default.MySettingWeb应用程序或单元测试中的内容.但是,问题是无论何时添加新设置,Visual Studio都会重新生成Setting.settings文件,并将Settings类翻转回内部:

internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,是否有人知道一种方法来覆盖它,或者可能建议使用宏方法或其他方法来确保在重建Settings.settings文件之后,将此类设置为public.

谢谢!

c# configuration visual-studio-2010

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

为什么Web.config在项目文件夹而不是bin中查找configSource?

我已经定义了我的configSource来查找名为config的子目录中的配置文件,如下所示:

<connectionStrings configSource="config\ConnectionStrings.config" />
Run Code Online (Sandbox Code Playgroud)

我将配置文件定义为链接文件,因此当构建发生时,它会被复制到我的bin\config文件夹中.

但是,我的Web应用程序项目正在查看开发项目配置文件夹而不是部署 bin\config文件夹.我用Process Monitor证实了这一点.

所以我有几个问题:

  1. 为什么它看起来而不是bin\config - 我错过了某个地方的相对路径设置吗?
  2. 链接文件不会复制到那里,只能复制到bin.我的理解是这是正确的行为.这是正确的假设还是应该复制到两个位置?如果是这样,启用该设置的设置是什么?
  3. 将子文件夹用于链接文件是不错的做法,还是应该将它们留在项目根目录中?

非常感谢!

更新:我正在使用此处描述的方法:http://consultingblogs.emc.com/jamesdawson/archive/2008/06/03/using-linked-files-with-web-application-projects.aspx 以确保配置文件被复制,做了一些实验我回答了问题#2.不,它不是Visual Studio中的默认行为,但这种解决方法可确保将文件复制到两个位置.

asp.net configuration web-config visual-studio-2010

7
推荐指数
1
解决办法
2129
查看次数

TSQL按特定值排序

我需要订购我的结果,以便状态列为特定值的所有项目首先出现,然后按日期出现.

我试过这个:

SELECT Id, Status, CreatedAt FROM Table
ORDER BY (Status=1) DESC, CreatedAt
Run Code Online (Sandbox Code Playgroud)

我想我会得到一个bool值(Status = 1),所以DESC命令将true(1)值放在顶部.

但是我收到了语法错误.这是可能的,如果是这样,正确的语法是什么?

谢谢!

t-sql sql-server

4
推荐指数
2
解决办法
8171
查看次数

接口实现莫名其妙地将List <T>转换为List <Libary.T> C#

我无法实现此功能,因为它是从C#.NET Core 2.0.1中的通用方法派生的,如下所示:

接口

public interface IListable 
{
    List<T> AsList<T>();
}
Run Code Online (Sandbox Code Playgroud)

履行

public class PwActivityTypeCollection : IListable 
{
    public List<PwActivityType> user;
    public List<PwActivityType> system;
    public List<PwActivityType> AsList<PwActivityType>() 
    {
      return user.Concat (system).ToList();
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,在我尝试实现接口之前,这样可以正常工作.该Concat代码返回List<PwActivityType>预期:

public List<PwActivityType> AsList() 
{
    return user.Concat(system).ToList();
}
Run Code Online (Sandbox Code Playgroud)

错误:

PwActivityType.cs(16,14):错误CS0029:无法将类型'System.Collections.Generic.List <Library.PwActivityType>'隐式转换为'System.Collections.Generic.List <PwActivityType>'[/ Users/shanekenyon/Documents /git/gls_int_prosperworks/library/library.csproj]

c# .net-core

0
推荐指数
1
解决办法
53
查看次数