Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-458901: Wrong qualifier binding in Move Instance Method

$
0
0
Reporter Alisa Afonina (alisa.afonina) Alisa Afonina (alisa.afonina)
Created May 24, 2016 2:44:22 PM
Updated Apr 11, 2018 11:09:55 PM
Resolved Apr 11, 2018 11:09:55 PM
Subsystem Refactorings
Assignee Alisa Afonina (alisa.afonina)
Priority Major
State Fixed
Type Bug
Fix version 2018.1
Affected versions No Affected versions
Fixed In Version ReSharper Undefined
VsVersion All Versions
Move method pay() to employee type

namespace RefactoringExamples.ReplaceConditionalWithPolymorphism
{
public class Employee
{
private EmployeeType _employeeType;
private readonly int _monthlySalary;
private readonly int _commission;
private readonly int _bonus;

public Employee(int type)
{
Type = type;
_monthlySalary = 100;
_commission = 10;
_bonus = 20;
}

public int Type
{
get { return _employeeType.TypeCode; }
set { _employeeType = EmployeeType.TypeFrom(value); }
}

public int PayAmount()
{
return Pay();
}

private int Pay()
{
switch (_employeeType.TypeCode)
{
case EmployeeType.Engineer:
return _monthlySalary;
case EmployeeType.Salesperson:
return _monthlySalary + _commission;
case EmployeeType.Manager:
return _monthlySalary + _bonus;
default:
throw new Exception("Incorrect Employee");
}
}
}
}

using System;

namespace RefactoringExamples.ReplaceConditionalWithPolymorphism
{
public abstract class EmployeeType
{
public abstract int TypeCode { get; }

public static EmployeeType TypeFrom(int value)
{
switch (value)
{
case Engineer:
return new Engineer();
case Salesperson:
return new Salesperson();
case Manager:
return new Manager();
default:
throw new Exception("Incorrect Employee Code");
}
}

public const int Engineer = 0;
public const int Salesperson = 1;
public const int Manager = 2;
}

class Engineer : EmployeeType
{
public override int TypeCode => Engineer;
}

class Salesperson : EmployeeType
{
public override int TypeCode => Salesperson;
}

class Manager : EmployeeType
{
public override int TypeCode => Manager;
}
}

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>