如何将字符列表转换为字符串?
换句话说,我该怎么扭转List.ofSeq "abcd"?
更新:new System.String (List.ofSeq "abcd" |> List.toArray) |> printfn "%A"似乎工作正常,有或没有new,但List.ofSeq "abcd" |> List.toArray) |> new System.String |> printfn "%A"失败.为什么?
我正在开发一个应该安装多个Windows服务的安装程序.我们经常制作新版本(使用新的.msi文件),并且我们使用主要升级使其易于安装在以前的安装中.
问题是我们需要更新服务文件而不覆盖服务配置(例如帐户用户名和密码).
我们使用ServiceInstall和ServiceControl保存该服务的组件内部exe文件.有没有办法使ServiceInstall条件的执行(使用类似条件REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE)所以升级时没有卸载服务(刚刚停止,所以我们可以升级文件)?
一种解决方案是使用自定义操作,但也许有更好的方法?
谢谢!
我已经使用Visual Studio作为我的主要IDE一段时间了(尽管我仍然使用Emacs进行一些个人项目).
我喜欢Emacs格式化C/C++代码的方式,我想说服Visual Studio对C#代码使用类似的约定.例如,在Emacs中,C函数调用如下所示:
functionName(argument1,
argument2,
argument3);
Run Code Online (Sandbox Code Playgroud)
在Visual Studio格式化的C#代码中,函数调用如下所示:
functionName(argument1,
argument2,
argument3);
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎更糟糕.
有没有办法调整Visual Studio代码格式规则?任何可以处理的插件?
非常感谢,
在Haskell中,通过简单地添加deriving Show到类型定义,很容易将代数类型/区分联合"可显示"作为字符串.
在F#中,我最终写出如下内容:
type Pos =
| Pos of int * int
override this.ToString() =
match this with
Pos(startp, endp) -> sprintf "Pos(%d, %d)" startp endp
Run Code Online (Sandbox Code Playgroud)
显然,对于更复杂的类型,它会变得更糟.
有什么办法得到像deriving ShowF#的东西?
Ocaml程序员可以使用所谓的"幻像类型"来使用类型系统强制执行某些约束.一个很好的例子可以在http://ocaml.janestreet.com/?q=node/11找到.
语法type readonly在F#中不起作用.它可以被定义为伪幻像类型type readonly = ReadOnlyDummyValue,以便在上述博客文章中实现技巧.
有没有更好的方法来定义F#中的幻像类型?
以下代码(打包在'Console Application'Visual Studio项目中):
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace TestReflection
{
class Program
{
static void Main(string[] args)
{
bool found = false;
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (assembly.GetType("System.Diagnostics.Process") != null)
{
found = true;
break;
}
}
Console.WriteLine(found);
Console.ReadKey();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在调试模式(F5)下运行时打印'True',但在没有调试器的情况下启动它时为'False'(Ctrl-F5).其他类显示类似的行为(System.Text.RegularExpressions.Regex),其他类在两种情况下都可以找到(System.IO.File).
我可能错过了一些明显的东西 - 为什么会这样?
(同样的事情发生在Visual Studio 2005和2008中).
找到的组件列表:
调试模式:
mscorlib
TestReflection
System
Microsoft.VisualStudio.HostingProcess.Utilities
System.Windows.Forms
Run Code Online (Sandbox Code Playgroud)
运行模式:
mscorlib
TestReflection
Run Code Online (Sandbox Code Playgroud)
正如答案所暗示的那样,在运行模式下,系统组件丢失(未加载).我的问题是我假设GetAssemblies()也返回未加载的程序集.
虽然这解释了行为System.Diagnostics.Process,为什么我的代码System.IO.File在运行和调试模式下都能找到?
谢谢!
我已经将代码更改为循环加载的程序集和当前程序集,收集这些程序集引用的程序集列表.如果迭代加载的程序集后我找不到我正在寻找的类型,我开始加载并检查引用的程序集.
看来即使我 …
我很困惑F#中的模式匹配是如何工作的let.我正在使用Visual Studio的'F#interactive'窗口,F#版本1.9.7.8.假设我们定义一个简单类型:
type Point = Point of int * int ;;
Run Code Online (Sandbox Code Playgroud)
并尝试模式匹配Point使用的值let.
let Point(x, y) = Point(1, 2) in x ;;
Run Code Online (Sandbox Code Playgroud)
失败了error FS0039: The value or constructor 'x' is not defined.一个人应该如何使用模式匹配let?
最奇怪的是:
let Point(x, y) as z = Point(1, 2) in x ;;
Run Code Online (Sandbox Code Playgroud)
按预期返回1.为什么?