Advertisement
codeplanner

XSockets - return types on actionmethods and access props

Mar 21st, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. public class Person
  2. {
  3.     public string Name { get; set; }
  4.  
  5.     public int Age { get; set; }
  6. }
  7.  
  8. /// <summary>
  9. /// Example showing a new feature...
  10. /// You can access public getters/setters from javascript
  11. /// And you can now return stuff from actionmethods.
  12. /// The things you return will be sent back to the caller with the event of the method called.
  13. /// </summary>
  14. public class Example : XSocketController
  15. {
  16.     /// <summary>
  17.     /// Public getters/setters can be accessed...
  18.     ///
  19.     /// Set by calling: ws.trigger('set_Monkey',{value:'Sidney'});
  20.     ///
  21.     /// Get by binding: ws.bind('get_Monkey',function(d){console.log(d);});
  22.     /// Trigger get:    ws.trigger('get_Monkey',{});
  23.     ///
  24.     /// Note: For no access, set the [NoEvent] attr and public will not be exposed
  25.     /// </summary>
  26.     public string Monkey { get; set; }      
  27.  
  28.  
  29.     /// <summary>
  30.     /// Until now you could only use void on ActionMethods in XSockets.
  31.     /// Now we propose the following....
  32.     /// If you return something we will send it back to the caller with the event being the name of the method called.
  33.     /// You can ofcourse to send/sendtoall/sendto etc inside the methods as usual.
  34.     ///
  35.     /// Example:
  36.     /// Calling: ws.trigger('stringtest',{})
  37.     /// Would return a string "Zebras Are Nice" to...
  38.     /// ws.bind('stringtest',function(d){console.log(d);});
  39.     ///
  40.     /// See other tested examples below.
  41.     /// </summary>
  42.        
  43.     public string StringTest()
  44.     {
  45.         return "Zebras Are Nice";
  46.     }
  47.  
  48.     public int IntTest()
  49.     {
  50.         return 77;
  51.     }
  52.  
  53.     public Guid GuidTest()
  54.     {
  55.         return Guid.NewGuid();
  56.     }
  57.  
  58.     public Person PersonTest()
  59.     {
  60.         return new Person { Name = "Uffe", Age = 36 };
  61.     }
  62.  
  63.     public IList<Person> PersonListTest()
  64.     {
  65.         return new List<Person> { new Person { Name = "Uffe", Age = 36 }, new Person { Name = "Magnus", Age = 38 } };
  66.     }
  67.  
  68.     //Just tested, not sure why we would have this :)
  69.     public Func<Person> FuncTest()
  70.     {
  71.         return () => new Person { Name = "Uffe", Age = 36 };
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement