Uri()。绝对路径"意外的符号'。'在约束力。" F#中的错误表达

时间:2015-01-01 18:41:23

标签: f# c#-to-f#

我在C#中有这样的陈述:

    private static string LogPath
    {
        get
        {
            string filePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
            return Path.GetDirectoryName(filePath) + "/cube_solver_log.txt";
        }
    }

当我尝试用F#写的时候;

static member LogPath() =
    let filePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath
    Path.GetDirectoryName(filePath) + "/cube_solver_log.txt"

我遇到一个例外:

  

意外的符号'。'在约束力。在此点或其他标记之前或之前的预期不完整结构化构造。

因为在F#中,我不知道为什么,系统库在我的代码中不接受。AbsolutePath

我该如何解决问题?

1 个答案:

答案 0 :(得分:2)

您需要在new表达式周围添加括号:

static member LogPath() =
    let filePath = (new Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath
    Path.GetDirectoryName(filePath) + "/cube_solver_log.txt"

实际上new关键字是可选的,因此您可以执行以下操作:

let  LogPath() =
    let filePath = Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath
    Path.GetDirectoryName(filePath) + "/cube_solver_log.txt"
相关问题