开发者

How do I make my library simple, yet target the different frameworks?

开发者 https://www.devze.com 2023-01-06 00:05 出处:网络
I created an API wrapper called Chargify.NET and I\'m starting to see a pattern develop that could potentially be solved by targeting .NET 4.

I created an API wrapper called Chargify.NET and I'm starting to see a pattern develop that could potentially be solved by targeting .NET 4.

The issue is that as they enhance the API, I need to create more and more overloaded functions to handle one specific action (Creating a subscription, in this case). Right now, I have MANY (I think too many) overloaded CreateSubscription functions, and it's getting hard to manage the different signatures.

IS it possible (and/or suggested) to build the library against .NET 4 and use optional parameters and hope that the users of the library can use the .NET 4 library? Or should I continue along the path I'm on with 3.5? Or somehow target bo开发者_高级运维th?

Need some discussion about this ..


Optional parameters have been fully supported by .NET well before 4.0. However, they have only recently gotten language support from C#. Remember that optional parameters are not required to be fully supported by a CLS compliant language - the compiler is allowed to ignore the default values you provide.


There's really no right answer. If you start using .NET 4 features, you'll probably want to just target .NET 4, since trying to target both will either limit you to older features (meaning no reason to upgrade) or require 2 code paths (bad for maintenance).

Using .NET 4 will limit your target market to those people using .NET 4. It's really up to you to decide whether the extra flexibility and power that comes with the new features, and whether the simplified API (ie: optional parameter capabilities) is worth limiting your audience.

If your audience is commercial shops, this may be a big issue - if your target users are small developers, or mainly other open source developers - chances are they'll be much more willing to upgrade to .NET 4 to use your wrapper if it's required.


Just so you know too, when the C# Compiler compiles your program and your program uses optional parameters, all the compiler does is substitute those optional parameters for overloaded functions. So you will gain no speed or code reduction benefit by switching to optional parameters.

0

精彩评论

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