简体   繁体   中英

Use System.ComponentModel.DataAnnotations in PCL with WinPhone as like as “microsoft bcl portability pack”?

I've a portable class library which targets followings:

.NET + Silverlight + WinRT + WinPhone + Android + iOS

The "System.ComponentModel.DataAnnotations" namesapce does not exists in WinPhone

So I've no access to that namespace in my codes

How can I solve this problem as like as "microsoft bcl portability pack"

This package provides access to attributes and classes such as "CallerMemberNameAttribute" but at runtime it will map those classes to their equivalent implementation if exists.

from " http://www.nuget.org/packages/Microsoft.Bcl/ ":

These types are "unified" to their later version equivalent. For example, when running on .NET Framework 4.5, IProgress from this package will be seen by the runtime as the same type as the one already available in the platform.

You should be able to do this using the "Bait and Switch" PCL technique .

In this case you would create a portable implementation of the data annotation attributes, and on platforms that support the "real" versions, "switch" to a library that type-forwards to those versions. See also this answer: https://stackoverflow.com/a/16046668/1509

If you do this, it would be great if you could publish it as an OSS project and a package on NuGet so that others can benefit from it. This is a fairly common request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM