我正在尝试读取这样的配置文件:
var dllPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.
GetExecutingAssembly().GetName().CodeBase);
dllPath = dllPath.Replace("file:\\", string.Empty);
var configPath = string.Format(@"{0}\..\contentFolders.config", dllPath);
var fileMap = new ExeConfigurationFileMap() {ExeConfigFilename = configPath};
var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap,
ConfigurationUserLevel.None);
var contentFolderConfig =
(ContentFolderSettings)config.GetSection("contentFolderConfiguration");
Run Code Online (Sandbox Code Playgroud)
我ContentFolderSettings在Corp.Common项目中定义了它继承自ConfigurationSection.这是以下内容contentFolders.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<section name="contentFolderConfiguration"
type="Corp.Common.ContentFolderSettings, Corp.Common"
requirePermission="false"/>
<contentFolderConfiguration>
<contentFolders>
<contentFolder key="ImagesFolder" path="content\images"/>
<contentFolder key="CssFolder" path="content\css"/>
...
</contentFolders>
</contentFolderConfiguration>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但线路呼叫config.GetSection()正在投入InvalidCastException:
Unable to cast object of type 'System.Configuration.DefaultSection' to type
'Corp.Common.ContentFolderSettings'.
Run Code Online (Sandbox Code Playgroud) 我有时看到过enum这样的事情:
public enum Color {
None, Black, Red, Blue
}
Run Code Online (Sandbox Code Playgroud)
代码如下:
Color color;
...
if (color == Color.None) ...
Run Code Online (Sandbox Code Playgroud)
我更喜欢使用可以为空的枚举并像这样编码:
public enum Color {
Black, Red, Blue
}
...
Color? color;
...
if (color == null) ...
Run Code Online (Sandbox Code Playgroud)
哪种款式首选?
我正在尝试tini在我的 Dockerfile 中使用,但出现错误。
我使用了tini自述文件中的代码示例。
# ... code which builds /app/foo
# Add Tini
ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ENTRYPOINT ["/tini", "--"]
# Run the program when the container starts
CMD ["/app/foo"]
Run Code Online (Sandbox Code Playgroud)
我希望我的程序可以在没有运行的情况下运行,PID=1但我得到:standard_init_linux.go:207: exec user process caused "no such file or directory"
编辑:
/app/foo在 Dockerfile 的开头创建。没有问题/app/foo。作为证明,如果我注释掉该ENTRYPOINT行(或删除所有tini相关代码),/app/foo除了它具有PID=1
我试图IComparer<object>使用代码调用一个期望参数类型的"排序"方法:
collection.Sort((IComparer<object>)Comparer<DateTime>.Default)
Run Code Online (Sandbox Code Playgroud)
它构建但在运行时我得到一个带有消息的InvalidCastException:
Unable to cast object of type
'System.Collections.Generic.GenericComparer`1[System.DateTime]'
to type 'System.Collections.Generic.IComparer`1[System.Object]'.
Run Code Online (Sandbox Code Playgroud)
怎么办?
我想要一个类似List <string>的东西,但每当我做一个"添加"时,它会保持列表的排序.有任何想法吗?
.NET是否与Perl数组类似,它们以数字方式编制索引,但会根据需要自动扩展?它会像这样工作:
var x = new DreamArray<string>();
x[6] = "foo"; // x automatically has 7 elements
x[10] = "bar"; // now it has 11
Run Code Online (Sandbox Code Playgroud) 当我运行这个:
use feature ':5.10';
$x=1;
given ($x) {
when(1) {
say '1';
$x = 2;
continue;
}
when (2) {
say '2';
}
}
Run Code Online (Sandbox Code Playgroud)
这应该打印1和2,但它只打印1.我错过了什么?
编辑:
我添加了$ x = 2,它仍然只打印"1"
我注意到,当我构建给定的 C# 或 VB.NET 源代码来生成 DLL 时,每次的二进制输出都不同。如果不是这种情况,这将对我们的构建/部署过程很有帮助。我能控制这个吗?
我看到一些使用浏览器缓存的静态页面的问题,这是不希望的。为了防止缓存,我正在设置
<clientCache cacheControlMode="DisableCache" />
Run Code Online (Sandbox Code Playgroud)
<location>在 web.config的相关标签中
如果我在 Firebug 中打开页面(在Net选项卡中),我会看到 Response 标头 Cache-Control: no-cache是正确的,但 Response 的状态是304 Not Modified!这不是矛盾吗?我怎样才能让它停止缓存(即总是发送一个 200 的内容)?
我记得看到一篇关于如何修复Visual Studio 2010错误的博客文章,每当你提起它时,查找对话框的宽度会增加,但是我没有绕过它,现在我不记得我在哪里看到了它.有谁有这个链接?