我基本上有这样的事情:
void Foo(Type ty)
{
var result = serializer.Deserialize<ty>(inputContent);
}
Foo(typeof(Person));
Run Code Online (Sandbox Code Playgroud)
这Deserialize<ty>不起作用,因为它期望Deserialize<Person>.我该如何解决这个问题?
我也想了解泛型如何工作以及它为什么不接受ty哪些是typeof(Person).
编辑:我应该提到这是一个人为的例子.我实际上无法更改函数的签名,因为它实现了一个接口.
编辑:序列化程序是一个JavascriptSerializer并在此处实现为动作过滤器.它被称为:
[JsonFilter(Param="test", JsonDataType=typeof(Person))]
Run Code Online (Sandbox Code Playgroud)
根据Marc和Anton的答案:
var result = typeof(JavaScriptSerializer).GetMethod("Deserialize")
.MakeGenericMethod(JsonDataType)
.Invoke(serializer, new object[] { inputContent });
Run Code Online (Sandbox Code Playgroud) 这个问题可能会让人微笑,真的,硬盘驱动器的空间和今天的垃圾一样便宜.但是,由于互联网连接速度极慢(世界主要地区仍然存在这种情况),从不同的分支机构转移备份可能是后面的真正痛苦.
那么,您对如何将数据库文件大小减少到最低限度有任何想法吗?绝对欢迎任何想法.
我正在尝试更新我的一个项目,但我没有管理.当我尝试时,我得到了错误
'Synchronizing CVS' has encountered a problem.
Problems reported while synchronizing CVS Workspace. 0 of 1 resources were synchronized.
Details:
Problems reported while synchronizing CVS Workspace. 0 of 1 resources were synchronized.
An error occurred synchronizing /<Project name>: The server reported an error while performing the "cvs update" command.
The server reported an error while performing the "cvs update" command.
<project name>: The server did not provide any additional information.
Run Code Online (Sandbox Code Playgroud)
我应该关心这个错误吗?它看起来一切都很好,但它困扰我.
谢谢你的阅读
更新
我发现有一个文件已更新,但结果未更新.我正在做的另一个错误是我在项目级别同步,在这些情况下我认为最好在文件夹级别同步并打开CVS控制台.要打开CVS控制台,请按窗口>打开视图>控制台.然后在控制台视图中有一个需要按下的shell图标,然后按CVS.像CVS输出一样,它显示出来并且它有助于更多.
我目前正在尝试实现一种算法来选择唯一的(16位)标识符.挑战是以不使用太多内存的快速方式执行此操作.当前使用的标识符列表是通过一系列SPI事务扫描外部闪存设备来确定的,因此是一个相对较慢的过程.此外,该算法将在小型微控制器上运行,因此我不能真正将所有条目读入RAM并在那里处理它们.
到目前为止我的想法是:
目前,我正准备使用第二个或第五个,但我有兴趣知道是否有人有任何其他想法.我想认为有一种类似于CRC的算法,可以用来依次处理每个数字,并给出一个尚未使用的数字的公平概念,但我不知道这可能是怎样的工作.
我想从网页中提取所有网址,我怎么能用nokogiri呢?
例:
<div class="heat"> <a href='http://example.org/site/1/'>site 1</a> <a href='http://example.org/site/2/'>site 2</a> <a href='http://example.org/site/3/'>site 3</a> </diV>
结果应该是一个列表:
l = ['http://example.org/site/1/', 'http://example.org/site/2/', 'http://example.org/site/3/' 如果从TableX获取colA的值,从TableY获取colB值,从TableZ获取colC,如何编写INSERT语句?
例如:INSERT INTO TableA(colA,colB,colC)VALUES(?,?,?)
任何想法,如果有可能吗?
我正在使用旧的ASP代码,我不确定语义on error goto 0和error resume next构造.
你能推荐一些有用的资源或者直接给我看看吗?
我有一个 Visual C++ 项目,但我无法刷新窗口并重绘自身。我用过
RedrawWindow();
m_ProgressDlg->RedrawWindow();
Run Code Online (Sandbox Code Playgroud)
并且
UpdateData(false);
m_ProgressDlg->UpdateData(false);
Run Code Online (Sandbox Code Playgroud)
但似乎永远不会顺利。
我能怎么做?
我有一个creaky属性映射的接口:
interface IPropertyMap
{
bool Exists(string key);
int GetInt(string key);
string GetString(string key);
//etc..
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个像这样的扩展方法:
public static T GetOrDefault<T>(this IPropertyMap map, string key, T defaultValue)
{
if (!map.Exists(key))
return defaultValue;
else
{
if (typeof(T) == typeof(int)) return (T)map.GetInt(key);
//etc..
}
}
Run Code Online (Sandbox Code Playgroud)
但编译器不会让我转向T.我尝试添加,where T : struct但似乎没有帮助.
我错过了什么?
我需要使用条件API复制以下工作HQL查询.
session.CreateQuery(
"select c " +
"from Parent p " +
"inner join p.Children c " +
"where p.Id = 9 " +
"and c.Id = 33")
.SetMaxResults(3)
.List();
Run Code Online (Sandbox Code Playgroud)
该查询选择满足属于满足其他条件的父项的特定条件的所有子项.在我的例子中,两个标准都是简单的Id等式,但它们可以是任何东西.
由于某种原因,等效标准API查询返回具有正确数量的项目的列表,但这些项目都为空.
session.CreateCriteria(typeof (Parent))
.Add(Restrictions.Eq("Id", 9))
.CreateCriteria("Children")
.Add(Restrictions.Eq("Id", 33))
.SetProjection(Projections.Property("Children"))
.SetMaxResults(3)
.List();
Run Code Online (Sandbox Code Playgroud)
为什么这两个查询不会返回相同的结果?
以下是HQL查询生成的SQL:
SELECT TOP 3 childid7_,
name7_
FROM (SELECT children1_.childid AS childid7_,
children1_.name AS name7_,
Row_number()
OVER(ORDER BY current_timestamp) AS __hibernate_sort_row
FROM dbo.parent parent0_
LEFT OUTER JOIN dbo.child children1_
ON parent0_.parentid = children1_.parentid
WHERE (parent0_.parentid = 9)
AND (children1_.childid …Run Code Online (Sandbox Code Playgroud)