AFAIK,ngen将MSIL转换为本机代码(也称为JIT之前的版本),但是我从未对它的启动性能影响给予太多关注.Ngen'd应用程序仍然需要.NET 基类库(运行时).
由于基类库具有.NET程序集所需的所有内容(正确吗?),是否可以使用我的ngen'd应用程序发布框架的DLL,以便它不需要安装运行时?(例如,大多数Windows XP计算机的方案)
哦,请不要再提及Remotesoft的Salamander Linker或Xenocode 的Postbuild.它们不适用于我(和许多人)目前的预算(他们似乎只是简单地将框架捆绑在一个虚拟化的环境中,这意味着我相信大的下载大小和慢启动时间)
编辑:
我现在知道,ngen并没有按照我的想法去做.
但是可以在不使用VM的情况下将.NET文件与应用程序捆绑在一起吗?
我问这个是因为看起来像使用Object似乎是一个解决某些问题的简单方法,比如"我没有特定的类型,所以使用Object"等.
这也让我感到好奇的原因是因为我的一位同事告诉我,如果.NET是一个真正的面向对象的平台,那么它就不必拥有像Object这样的所有类型.
因此,如果.NET没有Object类型,那么解决发生问题的替代方法是什么才能使其功能相同?
另外需要注意的是,这不是打击.NET,因为我每天都在工作中使用它.只想了解更多信息.
编辑:我记得的另一个注意事项是因为Object类型存在,它的影响遍及整个.NET.像IEnumerable一样存在但IEnumerable <T>.在许多情况下,您必须实现通用和非通用版本的事物等.
一个例子是:
XNamespace ns = "my namespace"
Run Code Online (Sandbox Code Playgroud)
为什么不?:
XNamespace ns = new XNamespace ( "my namespace" )
Run Code Online (Sandbox Code Playgroud)
使用隐式/显式转换而不是构造函数背后的想法是什么?方便?
有这方面的指导方针吗?
我想创建单元可测试的代码来模拟对.Net System.IO类的调用,所以我可以真正进行单元测试,而不是依赖于文件系统.我正在使用SystemWrapper类来包装BCL类.
我试图找一个简单的例子来查看文件是否存在.
我遇到的问题是在类中注入依赖项不起作用,因为实例化依赖项(通过StructureMap)需要知道要传递的构造函数参数,这在当时是不可用的,也没有默认构造函数.
示例代码:
// don't want to create dependency here like so
//IFileInfoWrap fileInfoWrap = new FileInfoWrap(filename);
// using service locator (anti-pattern?!) since it can't be
// injected in this class
var fileInfoWrap = ObjectFactory.GetInstance<IFileInfoWrap>(
new ExplicitArguments(new Dictionary<string, object>
{
{"fileName", filename}
}));
Console.WriteLine("File exists? {0}", fileInfoWrap.Exists);
Run Code Online (Sandbox Code Playgroud)
我不喜欢的是没有注入依赖项,ObjectFactory不应该在这里(但我没有看到其他创建方法).ExplicitArguments使它变得混乱,参数名称是一个魔术字符串.
让我开始工作StructureMap配置类需要知道我要使用哪个构造函数(我刚开始使用StructureMap所以这可能不是正确的设置方式):
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.AssembliesFromPath(".");
scan.RegisterConcreteTypesAgainstTheFirstInterface();
scan.WithDefaultConventions();
});
// use the correct constructor (string instead of FileInfo)
x.SelectConstructor(() => new FileInfoWrap(null as string)); …Run Code Online (Sandbox Code Playgroud) c# tdd dependency-injection inversion-of-control base-class-library
在F#中,您可以first按如下方式定义函数:
let first (x, y) = x
你可以这样称呼它:
first (1, 2)
您还可以根据BCL Tuple类型定义相同的功能:
let first (t:Tuple<_, _ >) = t.Item1
但是,您无法使用先前的语法调用它,否则您将收到以下错误:
error FS0001: The type ''c * 'd' is not compatible with the type 'Tuple<'a,'b>'
相反,您必须执行以下操作:
first (Tuple<_,_>(1, 2))
这很奇怪,因为Tuple在任何一种情况下,编译的F#代码似乎都用来表示它的参数.那么为什么F#编译器告诉我类型不兼容?
为什么这有关系?好吧,基本上我想编写一个带有重载的方法来支持任意长度的元组.使用F#的语法元组是不可能的,因为必须提前知道参数的确切数量.但是,它似乎可以通过使用BCL Tuple类型,因为那些使用TRest技巧来允许任意长度的元组.不幸的是,如果我以这种方式编写我的重载,那么它们将无法使用F#语法元组,这是最终目标.
所以我的问题是:为什么语法元组和BCL元组不兼容?而且,是否有任何编写函数和/或方法的例子在F#中对任意长度的元组进行操作?
具体的应用程序处理我正在编写的基于类型推断的二进制解析库.您可以在此处查看代码.你可以看到我对元组的许多重载,但我不想将它们扩展到一些神奇的数字.
我听说.NET System.Collections.Immutable集合是作为平衡二叉树实现的,以便Dictionary通过使用整数值GetHashCode作为排序键来满足它们的不变性约束,甚至传统上模拟散列表的集合.
如果我有一个类型,它是便宜生成一个散列码,以及对于便宜的比较(如string或int),我不关心我收集整理的烦躁,这将是有意义的喜欢ImmutableSortedDictionary,因为底层数据结构是否仍然排序?
我考虑将我的System.ValueTuple参考文献从4.4.0 更新到(当前)4.5.0。
为了避免回归,我想找出这两个版本之间的变化。该的NuGet页说:
发行说明
链接到.NET Core github存储库。
“发行说明”链接是否损坏,或者.NET Core github存储库是否实际上包含其更改日志System.ValueTuple?如果是后者,它到底在哪里?我尝试在System.ValueTuple存储库中进行搜索,这会产生一些结果,但是并没有帮助我找到4.4.0和4.5.0版本之间的更改。
我有一个VB.NET应用程序崩溃与以下错误:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Threading.Tasks, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Threading.Tasks, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
我正在尝试使用Microsoft.Bcl.Async库.我通过Nuget在实际使用Async/Await调用的项目和引用它的项目上安装了它.一切都在我的计算机上完美运行,但是当我在另一台计算机上发布和测试时,当我尝试使用其中使用Async/Await的部分时,我的程序崩溃了.
在Copy Local设置为true的两个项目中引用System.Threading.Tasks.在Copy Local设置为true的两个项目中引用Microsoft.Threading.Tasks.我已经看到了关于这个的另一个线程,它已安装在相关项目中.这些是我的app.config文件中包含的行:
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
设置这个我错过了什么?如果您需要更多信息,请告诉我.谢谢!
我遇到了一个似乎非常奇怪的错误ImmutableArray<>(使用BCL Immutable集合v1.0.12.0,运行时.NET 4.5):
我在同一名称空间下的同一源文件中完全具有以下两个相同的结构:
public struct WeightedComponent {
public readonly IComponent Component;
public readonly decimal Weight;
public WeightedComponent(IComponent component, decimal weight) {
this.Component = component;
this.Weight = weight;
}
}
public struct WeightedComponent2 {
public readonly IComponent Component;
public readonly decimal Weight;
public WeightedComponent2(IComponent component, decimal weight) {
this.Component = component;
this.Weight = weight;
}
}
Run Code Online (Sandbox Code Playgroud)
以下将抛出异常:
var elements1 = new[] { 1, 2, 3 }.Select(wc => new WeightedComponent(null, 0)).ToImmutableArray();
var foo = elements1.Select((e1, i1) => elements1.Select((e2, i2) …Run Code Online (Sandbox Code Playgroud) .Net中有ShadowCopy功能,可通过复制程序集来保护文件锁定.有两个属性:
AppDomain.ShadowCopyFiles 使用AppDomainSetupAppDomainSetup.ShadowCopyFiles 将其存储在内部 string[]AppDomainSetup有string Value[]字段,用于存储配置.对我来说奇怪的是,这AppDomainSetup.ShadowCopyFiles是一个字符串属性,我们需要设置"true"或"false"代替实际bool类型.
以下是该属性的实现AppDomainSetup:
public string ShadowCopyFiles
{
get
{
return this.Value[8];
}
set
{
if (value != null && string.Compare(value, "true", StringComparison.OrdinalIgnoreCase) == 0)
this.Value[8] = value;
else
this.Value[8] = (string) null;
}
}
Run Code Online (Sandbox Code Playgroud)
这是AppDomain.ShadowCopyFiles的实现:
public bool ShadowCopyFiles
{
get {
String s = FusionStore.ShadowCopyFiles;
if((s != null) &&
(String.Compare(s, "true", StringComparison.OrdinalIgnoreCase) == 0))
return true;
else
return false;
}
} …Run Code Online (Sandbox Code Playgroud) .net ×7
c# ×7
asynchronous ×1
c#-7.0 ×1
constructor ×1
deployment ×1
f# ×1
immutability ×1
linq ×1
ngen ×1
runtime ×1
shadow-copy ×1
tdd ×1
type-systems ×1
types ×1
valuetuple ×1
vb.net ×1