NHibernate.IFutureValue>>序列化时包含 .Value
我正在使用 NHibernate 构建一个 ASP.NET(2.0,不,我无法更改它)站点,并且有一个自定义 JSON 转换器,因此我无法序列化我想要对客户端隐藏的属性。这让我只需返回对象,而不必担心它们的序列化值 - 它们始终是安全的。
不幸的是,如果我使用 query.FutureValue
,被序列化的对象首先是 NHibernate.Impl.FutureValue
而不是我的实体,这意味着如果我将它放入字典中并将其返回给客户端,我会得到如下所示的 JSON:
{key: { Value: { /* my serialized object properties */ } }
以前我发现我无法让任何接口在 ASP 的 JavaScriptConverter 实现中工作...只有常规或抽象类。因此,返回 typeof(IFutureValue
然后我发现 .Impl 中的 FutureValue 实现是程序集内部的,或者其他类似的废话,只会让我的 .NET 体验更加痛苦。所以我不能使用 typeof(FutureValue
有没有办法从程序集中获取类类型?或者让 ASP 相信接口确实有用途的方法?或者可能有一些我可以访问的超类可以让我解决整个问题?
帮助!我喜欢我的 Futures,它可以让我一次批量处理大量呼叫!
(如果有不清楚的地方,或者您想要更多代码,请务必询问!我可以发布很多内容。)
I'm building an ASP.NET (2.0, no, I can't change it) site with NHibernate, and have a custom JSON converter so I can not-serialize properties I want hidden from the client. This lets me just return the objects, and never have to worry about their serialized values - they're always secure.
Unfortunately, it appears that if I use query.FutureValue<class>()
, the object that gets serialized is first the NHibernate.Impl.FutureValue<class>
and not my entity, which means I get JSON that looks like this if I throw it in a dictionary and return it to the client:
{key: { Value: { /* my serialized object properties */ } }
Previously I discovered that I can't get any interfaces to work in ASP's JavaScriptConverter implementations... only regular or abstract classes. So returning typeof(IFutureValue<MyBaseClass>)
as a supported type means my converter is completely ignored. I can catch MyBaseClass, because I refactored things earlier to use an abstract base instead of an interface, but not the interface.
And then I discover that the FutureValue implementation in .Impl is internal to the assembly, or some other such nonsense that only serves to make my .NET experience even more painful. So I can't use typeof(FutureValue<MyBaseClass>)
to handle it all, because FutureValue exists only in my debugging sessions.
Is there a way to get the class type out of the assembly? Or a way to convince ASP that interfaces do in fact have uses? Or might there be some superclass I can access that would let me get around the whole issue?
Help! I like my Futures, it lets me batch a whole heck-ton of calls at once!
(if something isn't clear, or you want more code, by all means, ask! I can post quite a bit.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,你似乎把事情混在一起了。
听起来您正在尝试序列化
query.FutureValue()
的实例,这毫不奇怪地为您提供了:一个 JSON 对象,其中Value
字段具有代表您的实体的 JSON。对我来说,听起来您真的只想序列化
query.FutureValue().Value
。像这样使用 NHibernate future 给你带来的好处很少,所以你可能会想:
这有意义吗?
If I'm understanding you correctly, it seems you are mixing things a together a little bit.
It sounds like you're trying to serialize an instance of
query.FutureValue<class>()
, which unsurprisingly gives you just that: a JSON object where theValue
fields has JSON representing your entity.To me it sounds like you really want to just serialize
query.FutureValue<class>().Value
.Using NHibernate futures like this gives you little benefit though, so you're probably after something like:
Does that make sense?