分享C#$ Windows和Silverlight的类库C之间$ C [英] Sharing C# code between Windows and Silverlight class libraries

查看:214
本文介绍了分享C#$ Windows和Silverlight的类库C之间$ C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们写道,实现了一些标准的类型(字符串最初)扩展方法一个小的Windows类库。我把这个库中,使我们的任何项目将能够通过简单地引用它,并使用XXX.Extensions增加利用它。

We wrote a small Windows class library that implements extension methods for some standard types (strings initially). I placed this in a library so that any of our projects would be able to make use of it by simply referencing it and adding using XXX.Extensions.

一个问题来了,当我们想使用一些在Silverlight这些方法。虽然所有的code是兼容的,在Windows库不能在Silverlight中引用的,所以我们创建了有联系的同一类文件,并把编译器指令到类,允许使用的声明和命名空间不同的一个Silverlight库。这工作得很好,直到今天,当我添加了一个新类的Windows扩展库,并意识到,我会记得该类链接到Silverlight的库了。

A problem came up when we wanted to use some of these methods in Silverlight. Although all the code was compatible, a Windows library can't be referenced in Silverlight so we created a Silverlight library that had links to the same class files and put compiler directives into the classes to allow different using declarations and namespaces. This worked fine until today when I added a new class to the Windows extensions library and realised that I would have to remember to link the class into the Silverlight library too.

这是不理想的,我想知道如果任何人可能有想法的共享扩展方法和Windows和Silverlight项目之间的其他帮手code更好的办法。

This isn't ideal and I wondered if anyone might have ideas for a better way of sharing extension methods and other helper code between Windows and Silverlight projects.

推荐答案

您不能设置从一个Silverlight装配到正规的.NET程序集的引用,但你可以这样做反过来。

You cannot set a reference from a Silverlight assembly to a regular .NET assembly but you can do so the other way round.

因此​​,创建一个共享的Silverlight程序集,并添加code到装配。现在,你可以设置一个基准来回两个常规的.NET和你其他Silverlight的组装到共享Silverlight的程序集。

So create a shared Silverlight assembly and add your code to that assembly. Now you can set a reference fro both your regular .NET and you other Silverlight assembly to the shared Silverlight assembly.

的限制是,你只能把code在那里,将在.NET和Silverlight CLR都工作,但就是没有从共享code不同。

The restriction is that you can only put code in there that would work on both the .NET and Silverlight CLR but that is no different from sharing code.

这篇关于分享C#$ Windows和Silverlight的类库C之间$ C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆