-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into #264_nuget_spec_deprecation_fix
- Loading branch information
Showing
232 changed files
with
7,441 additions
and
2,820 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Globalization; | ||
using System.Linq; | ||
|
||
namespace GoogleTestAdapter.Common | ||
{ | ||
public abstract class EnumConverterBase<TEnum> : EnumConverter | ||
{ | ||
private readonly IDictionary<TEnum, string> _stringMap; | ||
|
||
protected EnumConverterBase(IDictionary<TEnum, string> stringMap) : base(typeof(TEnum)) | ||
{ | ||
if (stringMap == null) | ||
throw new ArgumentNullException(nameof(stringMap)); | ||
|
||
if (stringMap.Count != Enum.GetValues(typeof(TEnum)).Length) | ||
throw new ArgumentException(nameof(stringMap), "Map must have the same size as the enum"); | ||
|
||
if (stringMap.Values.Distinct().Count() != stringMap.Values.Count) | ||
throw new ArgumentException(nameof(stringMap), "Values of map must be pairwise distinct strings"); | ||
|
||
_stringMap = stringMap; | ||
} | ||
|
||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) | ||
{ | ||
return sourceType == typeof(TEnum) || | ||
base.CanConvertFrom(context, sourceType); | ||
} | ||
|
||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) | ||
{ | ||
return destinationType == typeof(string) || | ||
base.CanConvertTo(context, destinationType); | ||
} | ||
|
||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) | ||
{ | ||
if (value is string valueString) | ||
{ | ||
foreach (KeyValuePair<TEnum, string> kvp in _stringMap) | ||
{ | ||
if (kvp.Value == valueString) | ||
return kvp.Key; | ||
} | ||
} | ||
|
||
return base.ConvertFrom(context, culture, value); | ||
} | ||
|
||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) | ||
{ | ||
if (!(value is TEnum enumLiteral) || destinationType != typeof(string)) | ||
return base.ConvertTo(context, culture, value, destinationType); | ||
|
||
if (_stringMap.TryGetValue(enumLiteral, out string stringValue)) | ||
return stringValue; | ||
|
||
return base.ConvertTo(context, culture, value, destinationType); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
|
||
namespace GoogleTestAdapter.Common | ||
{ | ||
[TypeConverter(typeof(SummaryModeConverter))] | ||
public enum SummaryMode | ||
{ | ||
Never, | ||
Error, | ||
WarningOrError | ||
} | ||
|
||
public class SummaryModeConverter : EnumConverterBase<SummaryMode> | ||
{ | ||
public const string Never = "Never"; | ||
public const string Error = "If errors occured"; | ||
public const string WarningOrError = "If warnings or errors occured"; | ||
|
||
public SummaryModeConverter() : base(new Dictionary<SummaryMode, string> | ||
{ | ||
{ SummaryMode.Never, Never}, | ||
{ SummaryMode.Error, Error}, | ||
{ SummaryMode.WarningOrError, WarningOrError}, | ||
}) {} | ||
} | ||
|
||
} |
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,2 +1 @@ | ||
app.config | ||
Key.snk |
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.