0

I'm creating my own handler method and I want to know how to implement a Bundle parameter that is optional.

In Android it would look like

public bool updateUI(int mode, Bundle... params)
{    
    switch (mode)
    {
      case 0: return doStuff(params.getString("Name"));
      default: break;
    }
}

This is not covered in the migration guide.

MLProgrammer-CiM
  • 17,231
  • 5
  • 42
  • 75

1 Answers1

3

How to use Named and Optional arguments in .NET Framework and in Windows Phone as well:
http://msdn.microsoft.com/en-us/library/dd264739.aspx
Or you can use the params keyword fore passing arbitrary number of arguments:
http://msdn.microsoft.com/en-us/library/w5zay9db(v=VS.100).aspx

Edit: not sure, how the Bundle actually works, but it looks like a generic container for data. You might try to use dynamic type and the ExpandoObject:
http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject(v=vs.95).aspx

dynamic d = new ExpandoObject();
d.Data = "data";
d.Result = 42;

return d.Data;

What are the true benefits of ExpandoObject?

Community
  • 1
  • 1
Martin Suchan
  • 10,600
  • 3
  • 36
  • 66
  • Upvote but no accept given because it only answers half the question. Despite bundle can be emulated using params object[] I don't think it is a good idea, and it doesn't provide the functionality Bundle gives. – MLProgrammer-CiM Dec 03 '12 at 12:01
  • Could you tell us why its not a good idea and what additional functionality Bundle provides ? – sam1589914 Dec 03 '12 at 12:48