C#SVN客户端获取授权用户名

C#SVN客户端获取授权用户名,c#,tortoisesvn,svn-client,C#,Tortoisesvn,Svn Client,我似乎找不到通过C#SvnClient获取用户名的方法 在命令行中,您可以在命令提示符下键入“svnauth”,并在那里显示用户名 然而,在C#SvnClient API中它并没有那么简单 API确实有一个“Authorization”属性——不幸的是,它没有直接的函数调用来获取用户名 有人知道怎么做吗?经过长时间的单独搜索,我发现这是可能的虽然不漂亮 var cachedItems = SvnClient.Authentication.GetCachedProperties(SvnAuthen

我似乎找不到通过C#SvnClient获取用户名的方法

在命令行中,您可以在命令提示符下键入“svnauth”,并在那里显示用户名

然而,在C#SvnClient API中它并没有那么简单

API确实有一个“Authorization”属性——不幸的是,它没有直接的函数调用来获取用户名


有人知道怎么做吗?

经过长时间的单独搜索,我发现这是可能的虽然不漂亮

var cachedItems = SvnClient.Authentication.GetCachedProperties(SvnAuthenticationCacheType.UserNamePassword)
不幸的是,这不会返回用户名或密码的任何公共字段。但是,它有一个名为“_filename”的私有字段,可用于获取用户名/密码。--可以使用反射来访问

foreach (var item in cachedItems)
{
    ///find the matching Uri to the repository you want
    if (item.RealmUri.AbsoluteUri == ...)
    {
        var type = item.GetType();
        var fields = type.GetFields();

        var filename = fields.First(x => x.Name == "_filename").GetValue(item);

        ///Now just need to parse the file
        using (var streamReader = new StreamReader(new FileStream(filename, FileMode.Open)))
        {
            while (streamReader.ReadLine() != "username") {}
            streamReader.ReadLine(); ///There is 1 garbage line after username before the actual username
            return streamReader.ReadLine();
        }
    }
}

你是说来自SharpSvn库的
SvnClient
类吗?