开发者

How to port a C#.net .dll to siverlight for more platform independence?

I have coded a dll library using the basic utilities of C#. But for platform independence, I want to port it to silverlight. Is it possible? If possible, then how to do it?

Or do you guys have any other su开发者_StackOverflow社区ggestion?


If you build your DLL for Silverlight4, it can be referenced from a .NET-project; but not the other way round. See Sharing Silverlight Assemblies with .NET Apps.


Another method of sharing source code between SL and .Net is to use Linked files.

In your .net solution, add a silverlight library project.

Add>Existing Item>browse to the source files in the .net project, select them, click the little down-arrow on the 'add' button and select 'add as link'.

In a lot of cases, no modifications are necessary. In the instance that there is a minor discrepancy, use build flags and conditionals in source. e.g.

#if SILVERLIGHT 

#else

#endif

This has worked out well for me, especially when I want to share a DTO library.


My suggestion is to create different project files (for .NET and SL). Then add the common files into each.

Many classes and methods are available on both .NET and SL, so it is possible to make the two projects share the same code.

This does not apply to all scenarios. For example, my open source project #SNMP uses UDP related classes, but SL does not have any UDP related things.

My personal choice is to limit the size of SL application and move necessary pieces into a backend WCF application.


What you need is a Portable Class Library: http://msdn.microsoft.com/en-us/library/gg597391.aspx

This way can share a project/DLL between .Net, Silverlight and Windows Phone projects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜