Bug 6311 - Add Bundle.Add() methods
Summary: Add Bundle.Add() methods
Status: ASSIGNED
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 4.2.x
Hardware: PC Mac OS
: Low enhancement
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2012-07-27 15:24 UTC by Jonathan Pryor
Modified: 2016-09-02 21:13 UTC (History)
3 users (show)

Tags: XATriaged
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 6311 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
ASSIGNED

Description Jonathan Pryor 2012-07-27 15:24:11 UTC
The developer is supposed to create & fill Bundle instances:

    Bundle b = new Bundle ();
    b.PutString ("InputText", "text from client")

If Bundle provided Add() overloads, we could use collection initializers instead:

    var b = new Bundle () {
        { "InputText", "text from client" },
    };
Comment 1 Atsushi Eno 2012-08-07 05:02:16 UTC
I don't think it is good addition. This C# syntax makes use of collection initializer, and Bundle is not a mere collection of string. The first argument to PutString() is meant to be a key to the value, and does not accept more than two strings. And there are many other variants of the second argument. Collection initializer requires you to implement IEnumerable, but Bundle is not an IEnumerable of string.
Comment 2 Jonathan Pryor 2012-08-07 11:52:24 UTC
> Bundle is not a mere collection of string.

Correct, it's a collection of keys to values, just like Dictionary<TKey, TValue>, which does support collection initializers. Just provide an Add() method with all the required arguments:

> partial class Bundle {
>     public void Add (string key, string value)
>     {
>         PutString (key, value);
>     }
> 
>     public void Add (string key, short value)
>     {
>         PutShort (key, value);
>     }
>     // ...
> }

Just like Dictionary<TKey, TValue>, this would allow specifying both the key and the value in the initializer:

> var b = new Bundle () {
>     { "url", "https://example.com" },
>     { "port", (short) 80 },
> };

The Add() method can be overloaded to take all of value types as well.

As for implementing IEnumerable, yes that's required, but it's also fairly trivial to implement:

> partial class Bundle : IEnumerable {
>     public void IEnumerator GetEnumerator ()
>     {
>         foreach (var key in KeySet ())
>             yield return Get (key);
>     }
> }