Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 523
Yaser Moradi Avatar asked May 31 '14 06:05

Yaser Moradi


1 Answers

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.

like image 94
Daniel Plaisted Avatar answered Nov 09 '22 20:11

Daniel Plaisted