c# - CS1061 'IEnumerable<>' 不包含转储的定义
问题描述
我只想从我的软件 KeePass 中获取密码。
使用此处链接到问题的旧问题的代码后,我收到此错误消息:
S1061 'IEnumerable<<anonymous type: string Group, string Title, string Username, string Password>>' does not contain a definition for 'Dump' and no accessible extension method 'Dump' accepting a first argument of type 'IEnumerable<<anonymous type: string Group, string Title, string Username, string Password>>' could be found (are you missing a using directive or an assembly reference?) KeePasso C:\Users\prusinma\source\repos\KeePasso\KeePasso\Program.cs 36 Active
这是我使用的代码:
using System.Linq;
using KeePassLib;
using KeePassLib.Keys;
using KeePassLib.Serialization;
namespace KeePasso
{
class Program
{
static void Main()
{
var dbpath = @"\\xxx\Home_VIE\xxx\Desktop\KeePassDatabase\Database.kdbx";
var keypath = @"\\xxx\Home_VIE\xxx\Desktop\KeePassDatabase\Database.key";
var masterpw = "1234abcd";
var ioConnInfo = new IOConnectionInfo { Path = dbpath };
var compKey = new CompositeKey();
compKey.AddUserKey(new KcpPassword(masterpw));
compKey.AddUserKey(new KcpKeyFile(IOConnectionInfo.FromPath(keypath))); // Keyfile
var db = new PwDatabase();
db.Open(ioConnInfo, compKey, null);
var kpdata = from entry in db.RootGroup.GetEntries(true)
select new
{
Group = entry.ParentGroup.Name,
Title = entry.Strings.ReadSafe("Title"),
Username = entry.Strings.ReadSafe("UserName"),
Password = entry.Strings.ReadSafe("Password"),
};
kpdata.Dump(); // this is how Linqpad outputs stuff
db.Close();
}
}
}
在代码的最后一行中,在 处有一个红色下划线Dump
。它显示了我在上面共享的相同错误消息。
我已经在尝试找到类似的问题,并且在大多数问题中它们都与类型有关。但正如我所见,标题、用户名和密码中的所有数据/条目都是字符串。
如果有人可以在这里帮助我,将不胜感激。Id 也可以为其他解决方案打开如何从数据库中读出密码。
谢谢!
解决方案
由于kpdata
是匿名类型的集合,它已被覆盖ToString
(如果entry.Strings.ReadSafe
返回string
或某种具有“正确”覆盖ToString
方法的类型),您可以Console.WriteLine
在其上使用:
Console.WriteLine(string.Join(Environment.NewLine, kpdata));; // instead of kpdata.Dump();
否则,您将需要找到一种方法将 LINQPad 的Dump
方法导入您的项目,或者只使用一些 json 序列化库将对象转换为字符串。
推荐阅读
- regex - 正则表达式:如何在某个单词之后按字母顺序查找任意长度的单词
- java - 我的 res 文件夹不断收到一条错误消息:错误:R 类是公共的,应在名为 R.java 的文件中声明
- machine-learning - 10个epoch的训练和5个epoch的两次训练效果一样吗?
- javascript - 将本地存储数据填充到 HTML 表中?
- javascript - 如何在外部点击时关闭站点导航栏?
- java - 使用 compareTo 方法时遇到问题
- spring - EasyMock 不使用模拟方法
- typescript - React TS - 不允许手动更改状态
- android - 在嵌套的 RecyclerView 中居中焦点项目
- python-3.x - 如何从 target.com 产品页面抓取产品价格?