Use System.ComponentModel.DataAnnotations in PCL with WinPhone, as a "microsoft bcl portability package"?

I have a portable class library that tracks the following:

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

The name settings "System.ComponentModel.DataAnnotations" do not exist in WinPhone

So, I do not have access to this namespace in my codes

How can I solve this problem just like the "microsoft bcl portability package"

This package provides access to attributes and classes, such as "CallerMemberNameAttribute", but at run time it maps these classes to their equivalent implementation, if one exists.

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

These types are "unified" for their later version. For example, when working on the .NET Framework 4.5, the IProgress from this package will be displayed by the runtime as the same type as the one that is already available on the platform.

+7
c # portable-class-library
source share
1 answer

You must do this using the "Bait and Switch", PCL method .

In this case, you will create a portable implementation of data annotation attributes, and on platforms that support "real" versions, "switch" to a library that inherits these versions. See also this answer: stack overflow

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

+4
source share

All Articles