-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge with Game solution - Checkpoint #5 - FOV part 2
- Loading branch information
Showing
26 changed files
with
381 additions
and
936 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,52 @@ | ||
#region The MIT License - Copyright (C) 2012-2019 Pieter Geerkens | ||
///////////////////////////////////////////////////////////////////////////////////////// | ||
// PG Software Solutions - Hex-Grid Utilities | ||
///////////////////////////////////////////////////////////////////////////////////////// | ||
// The MIT License: | ||
// ---------------- | ||
// | ||
// Copyright (c) 2012-2019 Pieter Geerkens (email: pgeerkens@users.noreply.github.com) | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
// software and associated documentation files (the "Software"), to deal in the Software | ||
// without restriction, including without limitation the rights to use, copy, modify, | ||
// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to the following | ||
// conditions: | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
// OTHER DEALINGS IN THE SOFTWARE. | ||
///////////////////////////////////////////////////////////////////////////////////////// | ||
#region Copyright (c) 2012-2019 Pieter Geerkens (email: pgeerkens@users.noreply.github.com) | ||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
// THis software may be used under the terms of attached file License.md (The MIT License). | ||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
#endregion | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace PGNapoleonics.HexUtilities.Common { | ||
/// <summary>Type-safe extension methods for parsing Enums.</summary> | ||
public static partial class EnumExtensions{ | ||
#region Enum Parsing utilities | ||
/// <summary>Typesafe wrapper for <c>Enum.GetValues(typeof(TEnum).</c></summary> | ||
public static IList<TEnum> EnumGetValues<TEnum>() { | ||
return new List<TEnum>((TEnum[])(Enum.GetValues(typeof(TEnum)))).AsReadOnly(); | ||
} | ||
public static IList<TEnum> EnumGetValues<TEnum>() | ||
=> new List<TEnum>((TEnum[])(Enum.GetValues(typeof(TEnum)))).AsReadOnly(); | ||
|
||
/// <summary>TODO</summary> | ||
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] | ||
[SuppressMessage("Microsoft.Design","CA1004:GenericMethodsShouldProvideTypeParameter")] | ||
[Obsolete("Less useful or convenient than originally thought - just use Enum.GetNames({TEnum}).")] | ||
public static IList<string> EnumGetNames<TEnum>() where TEnum : struct { | ||
return new List<string>(Enum.GetNames(typeof(TEnum))).AsReadOnly(); | ||
} | ||
public static IList<string> EnumGetNames<TEnum>() where TEnum : struct | ||
=> new List<string>(Enum.GetNames(typeof(TEnum))).AsReadOnly(); | ||
|
||
/// <summary>Typesafe wrapper for <c>Enum.ParseEnum()</c> that automatically checks membership.</summary> | ||
public static TEnum ParseEnum<TEnum>(string value) where TEnum : struct { | ||
return ParseEnum<TEnum>(value,true,false); | ||
} | ||
public static TEnum ParseEnum<TEnum>(string value) where TEnum : struct | ||
=> ParseEnum<TEnum>(value,true,false); | ||
|
||
/// <summary>Typesafe wrapper for <c>Enum.ParseEnum()</c> that automatically checks membership.</summary> | ||
public static TEnum ParseEnum<TEnum>(string value, bool checkConstants, bool ignoreCase) where TEnum : struct { | ||
if(!TryParseEnum<TEnum>(value, ignoreCase, out var enumValue) && checkConstants) | ||
throw new ArgumentOutOfRangeException("value", value, "Enum type: " + typeof(TEnum).Name); | ||
public static TEnum ParseEnum<TEnum>(string value, bool checkConstants, bool ignoreCase) | ||
where TEnum : struct { | ||
if (!TryParseEnum<TEnum>(value,ignoreCase,out var enumValue) && checkConstants) | ||
throw new ArgumentOutOfRangeException("value",value,"Enum type: " + typeof(TEnum).Name); | ||
|
||
return enumValue; | ||
} | ||
|
||
/// <summary>Typesafe wrapper for <c>Enum.TryParseEnum()</c> that automatically checks membership.</summary> | ||
public static bool TryParseEnum<TEnum>(string value, out TEnum enumValue) where TEnum : struct { | ||
return TryParseEnum(value, false, out enumValue); | ||
} | ||
/// <summary>Typesafe wrapper for <c>Enum.TryParseEnum()</c> that automatically checks membership.</summary> | ||
public static bool TryParseEnum<TEnum>(string value, bool ignoreCase, out TEnum enumValue) where TEnum : struct { | ||
return Enum.TryParse(value, ignoreCase, out enumValue) | ||
&& Enum.IsDefined(typeof(TEnum),enumValue); | ||
} | ||
public static bool TryParseEnum<TEnum>(string value,bool ignoreCase,out TEnum enumValue) | ||
where TEnum : struct | ||
=> Enum.TryParse(value,ignoreCase,out enumValue) | ||
& Enum.IsDefined(typeof(TEnum),enumValue); | ||
|
||
/// <summary>Typesafe wrapper for <c>Enum.ToObject()</c>.</summary> | ||
/// <typeparam name="TEnum"></typeparam> | ||
public static TEnum EnumParse<TEnum>(char c, string lookup) { | ||
if (lookup==null) throw new ArgumentNullException("lookup"); | ||
var index = lookup.IndexOf(c); | ||
if (index == -1) throw new ArgumentOutOfRangeException("c",c,"Enum Type: " + typeof(TEnum).Name); | ||
|
||
return (TEnum) Enum.ToObject(typeof(TEnum), index); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.