Create Class from Parameters

3 posts, 1 answers
  1. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 21 Jul 2011 Link to this post

    I've a bit of an issue with this.

    Say I have this ...
            void MyMethod(bool CanDoThis, bool CanDoThat, bool CanDoTheOther)
            {
                bool x = CanDoThis;
                bool y = CanDoThat;
                bool z = CanDoTheOther;
            }
    This option generates code a bit like this...
    public class MyMethodParameters
    {
        private readonly bool CanDoThat;
        private readonly bool CanDoTheOther;
        private readonly bool CanDoThis;
     
        public MyMethodParameters(bool CanDoThis, bool CanDoThat, bool CanDoTheOther)
        {
            this.CanDoThis = CanDoThis;
            this.CanDoThat = CanDoThat;
            this.CanDoTheOther = CanDoTheOther;
        }
     
        public bool PCanDoThat
        {
            get
            {
                return CanDoThat;
            }
        }
        public bool PCanDoTheOther
        {
            get
            {
                return CanDoTheOther;
            }
        }
        public bool PCanDoThis
        {
            get
            {
                return CanDoThis;
            }
        }
    }
    Meaning my code in MyMethod changes to look like this...
    void MyMethod(MyMethodParameters myMethodParameters)
    {
                bool x = myMethodParameters.PCanDoThis;
                bool y = myMethodParameters.PCanDoThat;
                bool z = myMethodParameters.PCanDoTheOther;
    }

    Now, call me old-fashioned, but would the code above look better if it read...
    void MyMethod(MyMethodParameters myMethodParameters)
    {
                bool x = myMethodParameters.CanDoThis;
                bool y = myMethodParameters.CanDoThat;
                bool z = myMethodParameters.CanDoTheOther;
    }

    And whilst I'm having a moan, it would be nice to at least have the option of having the created class local (and private) to my current class rather than having it exposed to the wider world (I understand that this might be something I would need for a public method, but not for a private one).

    -- 
    Stuart
  2. Answer
    Stefan Avramov
    Admin
    Stefan Avramov avatar
    41 posts

    Posted 22 Jul 2011 Link to this post

    Hello Stuart Hemming,

    Thanks a lot for writing to us about that. Both issues will be fixed for our next release.

    All the best,
    Stefan Avramov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. DevCraft banner
  4. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 22 Jul 2011 Link to this post

    Nice one.

    -- 
    Stuart
Back to Top