本文整理汇总了C#中IEmployee.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IEmployee.GetType方法的具体用法?C# IEmployee.GetType怎么用?C# IEmployee.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEmployee
的用法示例。
在下文中一共展示了IEmployee.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getEmployee
/// <summary>
/// Checks the type of employee to get information on and queries from specific table.
/// </summary>
/// <param name="employee"></param>
/// <returns></returns>
public IEmployee getEmployee(IEmployee employee)
{
if (employee.GetType() == typeof(Director))
return getDirector(employee);
if (employee.GetType() == typeof(GroupManager))
return getManager(employee);
return getUser(employee);
}
示例2: CheckEmployeeIsManager
private static void CheckEmployeeIsManager(IEmployee employToCheck)
{
if (!(employToCheck is Manager))
{
string position = employToCheck.GetType().Name;
string realPosition = position[0].ToString();
for (int i = 1; i < position.Length; i++)
{
if (realPosition[i].ToString().ToUpper() == realPosition[i].ToString())
{
realPosition = " " + position[i];
}
else
{
realPosition += position[i];
}
}
throw new ArgumentException(String.Format("{0} {1} is not a manager (real position: {2})", employToCheck.FirstName, employToCheck.LastName, realPosition));
}
}
示例3: CheckEmployeeIsManager
private static void CheckEmployeeIsManager(IEmployee employeeToCheck)
{
if (!(employeeToCheck is Manager))
{
//string position = string.Empty;
//switch (employeeToCheck.GetType().Name)
//{
// case "ChiefTelephoneOfficer":
// position = "chief telephone officer";
// break;
// case "CleaningLady":
// position = "cleaning lady";
// break;
// case "RegularEmployee":
// position = "regular employee";
// break;
// default:
// position = employeeToCheck.GetType().Name;
// break;
//}
string position = employeeToCheck.GetType().Name;
string realPosition = position[0].ToString();
for (int i = 1; i < position.Length; i++)
{
if (realPosition[i].ToString().ToUpper() == realPosition[i].ToString())
{
realPosition += " " + position[i];
}
else
{
realPosition += position[i];
}
}
throw new ArgumentNullException($"{employeeToCheck.FirstName} {employeeToCheck.LastName} is not a manager (real position: {position})");
}
}
示例4: updateEmployee
public bool updateEmployee(IEmployee employee)
{
if (employee.GetType() == typeof(Director)) {
if (!isValidDirectorId(employee.ID))
throw new ArgumentException("Director does not exist. Did you mean to add a new Director instead?");
}
throw new System.NotImplementedException();
}
示例5: saveEmployee
public IEmployee saveEmployee(IEmployee employee)
{
if (!employee.isValid())
throw new ArgumentException("Please fill out all necessary information.");
if (employee.GetType() == typeof(Director)) {
Director d = (Director)employee;
DIRECTOR director = new DIRECTOR {
DIRECTOR_ID = d.ID,
START_DATE = d.StartDate,
END_DATE = null
};
return saveDirector(director);
}
if (employee.GetType() == typeof(GroupManager)) {
GroupManager m = (GroupManager)employee;
GROUP_MANAGER manager = new GROUP_MANAGER {
MANAGER_ID = m.ID,
GROUP_ID = (Int16)m.GroupID,
DIRECTOR_ID = m.DirectorID,
START_DATE = m.StartDate,
END_DATE = null
};
return saveManager(manager);
} else {
Employee e = (Employee)employee;
EMPLOYEE emp = new EMPLOYEE {
EMPLOYEE_ID = e.ID,
GROUP_MANAGER_START = e.GroupManagerID,
START_DATE = e.StartDate,
END_DATE = null
};
return saveUser(emp);
}
}
示例6: Visit
//通过反射和预定好饿方法命令规则动态执行
public void Visit(IEmployee employee)
{
string typeName = employee.GetType().Name;//获取employee的类型名
string methodName = "Visit" + typeName;//使用Visit+类型名拼接关联的方法名
MethodInfo method = this.GetType().GetMethod(methodName);//获取反射Visitor类的关联employee的方法
method.Invoke(this, new object[] { employee });//调用这个关联的方法,并把employee作为参数传入,这里实现了一个动态的调用
}