/// Property should have the value indicated by the argument
        public CypherMatchBuilder PropertyIs <T>(Expression <Func <T, object> > memberExpression, string argumentName)
        {
            var nodeProperty = ReflectionHelpers.GetCustomAttributeForMember <PropertyAttribute, T>(memberExpression);
            var propertyName = nodeProperty.GetName();

            _possibleValues.Add(propertyName, argumentName);

            return(this);
        }
示例#2
0
        public ArgumentUsageInfo(PropertyInfo toAutoGen)
            : this()
        {
            Property = toAutoGen;
            Name = "-" + NameTranslators.CombineByPascalCase(toAutoGen.Name, "-").ToLower();

            Aliases.Add("-" + Property.Name);
            if (Aliases.Count == 0)
            {
                Aliases.Add("-" + Name.ToLower());
            }
            var argAliases = Property.HasAttr<ArgAliasAttribute>() ? Property.Attr<ArgAliasAttribute>().Aliases : null;
            if(argAliases != null)
            {
                Aliases.AddRange(argAliases.Select(x=> "-" + NameTranslators.CombineByPascalCase(x, "-")));
            }
            Description = Property.HasAttr<ArgDescriptionAttribute>() ? Property.Attr<ArgDescriptionAttribute>().Description : "";
            Group = Property.HasAttr<ArgDescriptionAttribute>() ? Property.Attr<ArgDescriptionAttribute>().Group : "";

            if (Property.PropertyType.IsEnum)
            {
                foreach (var val in toAutoGen.PropertyType.GetFields().Where(v => v.IsSpecialName == false))
                {
                    var description = val.HasAttr<ArgDescriptionAttribute>() ? " - " + val.Attr<ArgDescriptionAttribute>().Description : "";
                    var valText = val.Name;
                    PossibleValues.Add(valText + description);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Generate a new info instance given a reflected property.
        /// </summary>
        /// <param name="toAutoGen">The property to use to seed the usage info</param>
        public ArgumentUsageInfo(CommandLineArgument toAutoGen)
            : this()
        {
            this.Argument = toAutoGen;
            Property      = toAutoGen.Source as PropertyInfo;
            Ignore        = false;
            IsAction      = toAutoGen.DefaultAlias == Constants.ActionPropertyConventionName;
            DefaultValue  = toAutoGen.DefaultValue;
            IsRequired    = toAutoGen.IsRequired;

            Name = "-" + toAutoGen.DefaultAlias;

            if (Name.EndsWith(Constants.ActionArgConventionSuffix))
            {
                Name = Name.Substring(0, Name.Length - Constants.ActionArgConventionSuffix.Length);
            }

            Aliases.AddRange(toAutoGen.Aliases.Skip(1).Select(a => "-" + a));

            Type = toAutoGen.FriendlyTypeName;

            Position    = toAutoGen.Position >= 0 ? new int?(toAutoGen.Position) : null;
            Description = toAutoGen.Description ?? "";

            if (toAutoGen.ArgumentType.IsEnum)
            {
                foreach (var val in toAutoGen.ArgumentType.GetFields().Where(v => v.IsSpecialName == false))
                {
                    var description = val.HasAttr <ArgDescription>() ? " - " + val.Attr <ArgDescription>().Description : "";
                    var valText     = val.Name;
                    PossibleValues.Add(valText + description);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Initiate a cell. Write arguments to instance attributes and create a set of possible values. Populate the set
        /// with values from range [1, max_value] if the cell is editable.
        /// </summary>
        /// <param name="row">Row parameter of a cell.</param>
        /// <param name="column">Column parameter of a cell.</param>
        /// <param name="maxValue">Maximum value that cell can get (sudoku size).</param>
        /// <param name="editable">Defines if object's value can be edited or is permanent. Defaults to True.</param>
        /// <param name="value">Value of the cell between 0 (empty) and MAX_VALUE. Defaults to 0.</param>
        /// <exception cref="ArgumentException">Throws if data given is incorrect:
        /// Cell is not editable and value is equal to 0;
        /// Value is below 0 or above maxValue;
        /// Row or column is below 1 or above maxValue.
        /// </exception>
        public Cell(byte row, byte column, byte maxValue, bool editable = true, byte value = 0)
        {
            if (!editable && value == 0)
            {
                throw new ArgumentException("Cell is not editable and no value was given");
            }
            else if (value < 0 || value > maxValue)
            {
                throw new ArgumentException($"Inorrect value ({value} is not in <0,{maxValue}>");
            }
            else if (!((0 <= row) && (row <= maxValue)) ||
                     !((0 <= column) && (column <= maxValue)))
            {
                throw new ArgumentException($"Incorrect row or column ({row},{column} not in <0,{maxValue}>");
            }

            Editable = editable;
            Row      = row;
            Column   = column;
            _Value   = value;

            if (editable)
            {
                for (byte i = 1; i <= maxValue; i++)
                {
                    PossibleValues.Add(i);
                }
            }
        }
示例#5
0
 /// <summary>
 /// Fill the set of possible values with full range [1, max_value].
 /// </summary>
 /// <param name="maxValue">Maximum possible value that can be written to the cell.</param>
 public void InitPossibleValues(byte maxValue)
 {
     for (byte i = 1; i <= maxValue; i++)
     {
         PossibleValues.Add(i);
     }
 }
示例#6
0
 public CellModel(CoreDispatcher dispatcher, SudokuCell cell) : base(dispatcher)
 {
     this.cell          = cell;
     cell.ValueChanged += Cell_ValueChanged;
     foreach (int x in new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 })
     {
         PossibleValues.Add(cell.IsPossible(x) ? Visibility.Visible : Visibility.Collapsed);
     }
 }
示例#7
0
        /// <summary>
        /// Generate a new info instance given a reflected property.
        /// </summary>
        /// <param name="toAutoGen">The property to use to seed the usage info</param>
        public ArgumentUsageInfo(CommandLineArgument toAutoGen)
            : this()
        {
            this.Argument = toAutoGen;
            Property      = toAutoGen.Source as PropertyInfo;
            Ignore        = false;
            IsAction      = toAutoGen.DefaultAlias == Constants.ActionPropertyConventionName;
            DefaultValue  = toAutoGen.DefaultValue;
            IsRequired    = toAutoGen.IsRequired;

            Name = "-" + toAutoGen.DefaultAlias;

            if (Name.EndsWith(Constants.ActionArgConventionSuffix))
            {
                Name = Name.Substring(0, Name.Length - Constants.ActionArgConventionSuffix.Length);
            }

            Aliases.AddRange(toAutoGen.Aliases.Skip(1).Select(a => "-" + a));
            if (Aliases.Count == 0)
            {
                //add shortcut alias
                Aliases.Add("-" + Name.ToLower());
            }
            Type = toAutoGen.ArgumentType.Name;
            if (KnownTypeMappings.ContainsKey(Type))
            {
                Type = KnownTypeMappings[Type];
            }
            else
            {
                Type = Type.ToLower();
            }

            Position    = toAutoGen.Position >= 0 ? new int?(toAutoGen.Position) : null;
            Description = toAutoGen.Description ?? "";
            Group       = Property.HasAttr <ArgDescription>() ? Property.Attr <ArgDescription>().Group : "";

            if (toAutoGen.ArgumentType.IsEnum)
            {
                foreach (var val in toAutoGen.ArgumentType.GetFields().Where(v => v.IsSpecialName == false))
                {
                    var description = val.HasAttr <ArgDescription>() ? " - " + val.Attr <ArgDescription>().Description : "";
                    var valText     = val.Name;
                    PossibleValues.Add(valText + description);
                }
            }
        }