Beispiel #1
0
 private void GetCombination(
     List <int> Flags,
     int NumInEachCombination,
     out FlagCombination FlagCombination)
 {
     FlagCombination = new FlagCombination();
     Flags.GetCombinations(
         FlagCombination.AddCombination,
         NumInEachCombination,
         false);
 }
Beispiel #2
0
        public Parameter(string Name, Type ValueType, object Value, bool IsTesting, Enum[] EnumeratedValues)
        {
            this.ParameterType = ParameterType.Discrete;

            this.Name           = Name;
            this.ParameterType  = ParameterType;
            this.ValueType      = ValueType;
            this.Value          = Value;
            this.IsTesting      = IsTesting;
            this.PossibleValues = new List <object>();

            if (ValueType.GetCustomAttributes(typeof(FlagsAttribute), false).Count() > 0)
            {
                List <int> values = new List <int>();

                for (int i = 0; i < EnumeratedValues.Length; i++)
                {
                    if (!Convert.ToInt32(EnumeratedValues[i]).Equals(0))
                    {
                        values.Add((int)Convert.ToInt32(EnumeratedValues[i]));
                    }
                }

                for (int i = values.Count; i > 0; i--)
                {
                    FlagCombination allCombinations = null;
                    GetCombination(values, i, out allCombinations);

                    if (allCombinations != null)
                    {
                        for (int combinationIndex = 0; combinationIndex < allCombinations.Combinations.Count; combinationIndex++)
                        {
                            IList <int> combination = allCombinations.Combinations[combinationIndex];

                            int combinedValue = 0;

                            foreach (int value in combination)
                            {
                                combinedValue ^= value;
                            }

                            if (!this.PossibleValues.Contains(combinedValue))
                            {
                                this.PossibleValues.Add(combinedValue);
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (Enum value in EnumeratedValues)
                {
                    ulong intValue = Convert.ToUInt64(value);
                    if (intValue != 0)
                    {
                        this.PossibleValues.Add(value);
                    }
                }
            }
        }