in Sharpmake/Options.cs [262:342]
private static bool SelectOptionImpl(bool throwIfNotFound, Configuration conf, OptionAction[] options)
{
// Get the type of current options and make sure they are all off the same type
Type optionType = null;
foreach (OptionAction optionAction in options)
{
if (optionType == null)
optionType = optionAction.Value.GetType();
else
if (optionType != optionAction.Value.GetType())
throw new Error("SelectOption may only be called of value of the same type");
}
if (optionType == null)
throw new Error();
FieldInfo[] optionTypeFields = optionType.GetFields();
// find the latest added option of this type
for (int i = conf.Options.Count - 1; i >= 0; i--)
{
object latestOption = conf.Options[i];
if (latestOption.GetType() == optionType)
{
foreach (FieldInfo field in optionTypeFields)
{
if (field.FieldType != optionType)
continue;
object fieldValue = field.GetValue(optionType);
if (fieldValue.Equals(latestOption))
{
object[] attributes = s_cachedDevEnvAttributes.GetOrAdd(field, fi => fi.GetCustomAttributes(typeof(Options.DevEnvVersion), true));
foreach (Options.DevEnvVersion version in attributes)
{
if (version.minimum > conf.Compiler)
throw new Error(optionType + " " + latestOption + " is not compatible with your DevEnv (" + conf.Compiler + ")");
}
break;
}
}
foreach (OptionAction optionAction in options)
{
if (optionAction.Value.Equals(latestOption))
{
optionAction.Action();
return true;
}
}
}
}
// find the default options
foreach (FieldInfo field in optionTypeFields)
{
object[] attributes = s_cachedDefaultAttributes.GetOrAdd(field, fi => fi.GetCustomAttributes(typeof(Options.Default), true));
foreach (Options.Default defaultOption in attributes)
{
if (defaultOption.DefaultTarget.HasFlag(conf.DefaultOption))
{
object fieldValue = field.GetValue(optionType);
foreach (OptionAction optionAction in options)
{
if (optionAction.Value.Equals(fieldValue))
{
optionAction.Action();
return true;
}
}
}
}
}
if (throwIfNotFound)
throw new Error("Not default value found for options: " + optionType.Name + " Default Options is " + conf.DefaultOption);
return false;
}