Skip to content

Commit

Permalink
Merge pull request #47 from RonnChyran/master
Browse files Browse the repository at this point in the history
[BREAKING] Implement RangeMax and RangeMin for IConfigurationFlag (#45)
  • Loading branch information
chyyran committed Feb 1, 2015
2 parents a9cdd52 + 026edae commit e488318
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Snowflake.API/Emulator/Configuration/IConfigurationFlag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public interface IConfigurationFlag
/// </summary>
IReadOnlyDictionary<string, string> SelectValues { get; }
/// <summary>
/// The minimum value permitted if this is an INT_FLAG type
/// 0 if no minimum or not INT_FLAG
/// </summary>
int RangeMin { get; }
/// <summary>
/// The maximum value permitted if this is an INT_FLAG type
/// 0 if no maximum or not INT_FLAG
/// </summary>
int RangeMax { get; }
/// <summary>
/// The type of configuration flag
/// </summary>
ConfigurationFlagTypes Type { get; }
Expand Down
24 changes: 18 additions & 6 deletions Snowflake/Emulator/Configuration/ConfigurationFlag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ public class ConfigurationFlag : Snowflake.Emulator.Configuration.IConfiguration
public ConfigurationFlagTypes Type { get; private set; }
public string DefaultValue { get; private set; }
public string Description { get; private set; }
public int RangeMin { get; private set; }
public int RangeMax { get; private set; }
public IReadOnlyDictionary<string, string> SelectValues { get; private set; }
public ConfigurationFlag(string key, ConfigurationFlagTypes type, string defaultValue, string description, IDictionary<string, string> selectValues = null)

public ConfigurationFlag(string key, ConfigurationFlagTypes type, string defaultValue, string description, int rangeMin = 0, int rangeMax = 0, IDictionary<string, string> selectValues = null)
{
this.Key = key;
this.Type = type;
this.DefaultValue = defaultValue;
this.Description = description;
this.RangeMin = rangeMin;
this.RangeMax = rangeMax;
if (selectValues != null)
{
this.SelectValues = selectValues.AsReadOnly();
Expand All @@ -38,17 +43,24 @@ public ConfigurationFlag(string key, ConfigurationFlagTypes type, string default
throw new ArgumentException("type can be one of BOOLEAN_FLAG, INTEGER_FLAG, SELECT_FLAG. Fix your emulator plugin.");
string description = protoTemplate["description"];
string defaultValue = protoTemplate["default"].ToString();
dynamic max = 0;
dynamic min = 0;
dynamic selectTypes;
protoTemplate.TryGetValue("max", out max);
protoTemplate.TryGetValue("min", out min);
protoTemplate.TryGetValue("values", out selectTypes);
try
{
IDictionary<string, string> selectTypes = protoTemplate["values"].ToObject(typeof(IDictionary<string, string>));
return new ConfigurationFlag(key, type, defaultValue, description, selectTypes);

selectTypes.ToObject(typeof(IDictionary<string, string>));
}
catch (KeyNotFoundException)
catch (NullReferenceException)
{
return new ConfigurationFlag(key, type, defaultValue, description);
selectTypes = null;

}

return new ConfigurationFlag(key, type, defaultValue, description, max, min, selectTypes);

}
}
}

0 comments on commit e488318

Please sign in to comment.