cureos / shim

Shim expands the ability to create Portable Class Libraries by providing reduced or dummy implementations of .NET Framework classes that are not represented in PCL.
https://www.nuget.org/packages/shim
GNU Lesser General Public License v3.0
27 stars 6 forks source link

Add Entity Framework Attributes to CSShim #61

Open Kirenenko opened 7 years ago

Kirenenko commented 7 years ago

I am trying to mock some attributes included on Entity Framework(MaxLength, NotMapped, Index, etc). I've downloaded the complete csshim project to debbug the code. I am al little confused with the fact that csshim library is a Shared Project instead of a PCL.

But leaving that on a side, the problem I am facing is that when I reference any attribute from .Net, it throws a compile time error(RangeAttribute for example): The Type RangeAttribute exists on "...Xamarin.Model" and on "System.CompomentModel.DataAnnotations". So, does it have something to do with NuGet(Because it works when I download the NuGet package instead of the raw code)? In that case, how can I make it work without NuGet, or what is the way to go with NuGet(if essential)?

anders9ustafsson commented 7 years ago

@Kirenenko Shim is built separately for each platform, and the so called bate-and-switch technique is used to ensure that the most relevant Shim instance is picked from the NuGet package when building an application for a specific platform. When a specific type is available on a platform, the Shim package for that particular platform does not include any additional implementation of that type, instead type forwarding is used to indicate that the type is already available. Source code that is common to most or all platforms are contained in the shared project, which in turn is referenced in each platform-specific project.

If you want to add new (attribute) types to Shim, you need to identify on which platforms these types are already available. On the platforms where the types are not already available, you should include your own implementations. On the platforms where the types are available, use type forwarding instead.

Even if a particular type is available on a particular platform, you should still use type forwarding, to keep the sync between the PCL instances of Shim and the platform-specific instances.

Kirenenko commented 7 years ago

Thanks @anders9ustafsson, I've finally understanded the bait and switch technique. I'll try to modify shim, test it and maybe create a PR.