private void SelectNextCameraMode()
{
    World.Camera.CameraMode = 
     (CameraActionMode)GetNextEnum<cameraactionmode>(World.Camera.CameraMode);
    UpdateCameraModeLabel();
}
 
private void SelectNextMouseMode()
{
    this.mouseMode = (MouseMode)GetNextEnum<mousemode>(this.mouseMode);
    UpdateMouseModeLabel();
}
 
private Enum GetNextEnum<t>(object currentlySelectedEnum)
{
    Type enumList = typeof(T);
    if (!enumList.IsEnum)
        throw new InvalidOperationException("Object is not an Enum.");
 
    Array enums = Enum.GetValues(enumList);
    int index = Array.IndexOf(enums, currentlySelectedEnum);
    index = (index + 1) % enums.Length;
    return (Enum)enums.GetValue(index);
}
 
private Enum GetPreviousEnum<t>(object currentlySelectedEnum)
{
    Type enumList = typeof(T);
    if (!enumList.IsEnum)
        throw new InvalidOperationException("Object is not an Enum.");
 
    Array enums = Enum.GetValues(enumList);
    int index = Array.IndexOf(enums, currentlySelectedEnum);
    index = (((index == 0) ? enums.Length : index) - 1);
    return (Enum)enums.GetValue(index);
} 

 

 本文参考http://www.codeproject.com/Tips/244647/Passing-Enum-type-as-a-parameter

 

 

 

  

相关文章:

  • 2022-03-01
  • 2021-08-05
  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
猜你喜欢
  • 2021-06-16
  • 2021-07-06
  • 2021-06-15
  • 2021-08-03
  • 2022-03-03
  • 2022-12-23
相关资源
相似解决方案