robotdotnet / WPILib

DotNet implementation of WPILib for FIRST Robotics Competition (FRC)
27 stars 8 forks source link

Attributed command model #44

Closed jkoritzinsky closed 9 years ago

jkoritzinsky commented 9 years ago

As an addition to WPILib.Extras, a new way to create a Command-Based Robot that removes most of the common boilerplate code required by the built-in Command-Based Robot framework by having teams use .NET Attributes (metadata) and the robot class will automatically hook everything up.

ThadHouse commented 9 years ago

I'm fine with this, other then I've always used Resharper to generate the equality commands, and it usually checks a few more things when checking for equals, like making sure both objects are the same type.

public bool Equals(Joystick other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return m_port == other.m_port;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != this.GetType()) return false;
            return Equals(obj as Joystick);
        }

        public override int GetHashCode()
        {
            return m_port;
        }

Thats the one it generates for me in the joystick class.

ThadHouse commented 9 years ago

Also don't worry about the build failing. Its failing because AppVeyor is not liking the unsafe code. I'm going to contact them and see if there is a way around that.

ThadHouse commented 9 years ago

In RobotInit(), is GetExecutingAssembly() going to work correctly? Don't you need to be loading the user code assembly, and not the WPILib.Extras assembly, right? I guess I don't understand command base, because we come from LabVIEW, and we wouldn't use it even when we switch.

jkoritzinsky commented 9 years ago

You're right. Good catch with GetExecutingAssembly. I'll change the code and update the pull request.

jkoritzinsky commented 9 years ago

The AttributedRobot will now load all exported assemblies and commands.