我试图通过继承StreamReader创建一个解密的文件流阅读器(DFSR)类,这样我就可以将带有encrpyted信息的文件名传递给它的(DFSR)构造函数,并返回我可以调用StreamReader的ReadLine方法的streamReader.
我知道如何做到如下,但我不知道如何将它折射成一个StreamReader作为父类的类.
using (Rijndael rijAlg = Rijndael.Create())
{
rijAlg.Key = DX_KEY_32;
rijAlg.IV = DX_IV_16;
// Create a decrytor to perform the stream transform.
using (FileStream fs = File.Open("test.crypt", FileMode.Open))
{
using (CryptoStream cs = new CryptoStream(fs, rijAlg.CreateDecryptor(), CryptoStreamMode.Read))
{
using (StreamReader sr = new StreamReader(cs))
{
string line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) IDictionary<string, string> map = str.Split('|')
.ToDictionary(s => s.Split('@')[0], s => s.Split('@')[1]);
Run Code Online (Sandbox Code Playgroud)
以上陈述有效.但是我想把它改成通用的IDictionary
public class CSVMap <TKey, TValue>
{
public IDictionary<TKey, TValue> func (string str)
{
IDictionary<TKey, TValue> map = str.Split('|').ToDictionary (ConvertValue<TKey>(s => s.Split('@')[0]), ConvertValue<TValue>(s => s.Split('@')[1]));
}
public static T ConvertValue<T>(string value)
{
return (T)Convert.ChangeType(value, typeof(T));
}
Run Code Online (Sandbox Code Playgroud)
并将ConvertValue拆分字符串转换为TKey和的类型TValue.
但我得到了这些ConvertValue部分的错误:
错误CS1660:无法将lambda表达式转换为类型'string',因为它不是委托类型
错误CS1660:无法将lambda表达式转换为类型'string',因为它不是委托类型
我不确定错误是什么意思或如何解决这个问题.