Refactoring Code

Im going mad with C#. Today is my 3rd day trying to refactor a SIMPLE snippet of code.

	private RebindableKey FindKeyByInputName(string inputName) {
		RebindableKey foundKey = null;
		RebindableData data = GamePicker.getRebindableData();

		foreach(RebindableKey key in data.GetCurrentKeys()) {
			if(key.inputName == inputName) {
				foundKey = key;
		return foundKey;

	private RebindableAxis FindAxisByInputName(string inputName) {
		RebindableAxis foundAxis = null;
		RebindableData data = GamePicker.getRebindableData();

		foreach(RebindableAxis key in data.GetCurrentAxes()) {
			if(key.axisName == inputName) {
				foundAxis = key;
		return foundAxis;

Please, i would really appreciate if someone could give me a light, those typing rules are driving me mad!
I would love if Unity could support a non-typed language.

love […] a non-typed language.

There’s your problem. I’m not saying there might not be a fabulous solution to this in Lisp. But doing fancy stuff with classes in C# pretty much requires you to think in strong types.

My first thought would have been that there’s going to be a big list of intermingled keys & axisis, at least displayed to the user. And no way am I building that with string and tape – there needs to be a common base class RebindableThing. Not because it’s cool, but because it will save time.

But, it takes a while to be even decent at this. Examples in books range from terrible to pointless. I’ve found the only way to learn is to waste a few months – make a design, use it, realize its junk; make a better one, realize that’s only slightly better junk… . Then, even the best design can become useless when you have to add this new, unexpected game feature.

Luckily, there’s a long tradition in games (and real programs) of just getting it to work. So, you have to duplicate every single function dealing with keyBinds and axisBinds. Game coders do much uglier things every day.

What you have is fine. Yes, it looks like a bit of repetitive code, but it’s neat, concise, and not worth spending 3 days over.

You should that think about the cost-benefit.
If you’re going to spend days refactoring, spend it refactoring the overall design.