This is a migrated thread and some comments may be shown as answers.

Create Class from Parameters

2 Answers 44 Views
Refactorings
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 21 Jul 2011, 03:31 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Stefan Avramov
Telerik team
answered on 22 Jul 2011, 03:33 PM
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!

0
Stuart Hemming
Top achievements
Rank 2
answered on 22 Jul 2011, 08:24 PM
Nice one.

-- 
Stuart
Tags
Refactorings
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Stefan Avramov
Telerik team
Stuart Hemming
Top achievements
Rank 2
Share this question
or