Is there any way I can implement IValidatableObject on Portable Class Library Project?

删除回忆录丶 提交于 2019-11-27 15:37:43

There's probably not an easy solution for this. You can create your own interface in a Portable Class Library with the same functionality. However that would be a different interface so other frameworks that use DataAnnotations (ASP.NET MVC and Entity Framework I think) wouldn't use your version.

To get around that problem, you could create a PCL with the interface with the exact same name and APIs as exist on the different platforms. Then create class libraries for .NET 4.0.3, SL4, and Windows Store with the exact same assembly identity (name, version, and strong name key), and in those assemblies just put a [assembly:TypeForwardedToAttribute(typeof(IValidatableObject))] attribute.

Then your PCLs can reference the PCL library with the interface, and in any apps that use the PCLs, reference the type-forwarding assembly for that platform, which will redirect the reference to the PCL version of the interface to the one that comes in the platform.

czesio

Here's longer description of solution which Daniel described: http://log.paulbetts.org/the-bait-and-switch-pcl-trick/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!