public void DefaultNullableBool(BooleanMode booleanMode, bool hasDefaultValue, int expectedMin, int expectedMax) { var actual = ArgumentArity.Default(typeof(bool?), hasDefaultValue, booleanMode); var expected = new ArgumentArity(expectedMin, expectedMax); expected.Should().Be(actual); }
internal static BooleanMode?GetBooleanMode( this IArgumentDef argumentDef, BooleanMode defaultBooleanMode) { if (argumentDef.Type != typeof(bool) && argumentDef.Type != typeof(bool?)) { return(null); } if (argumentDef.CommandNodeType == CommandNodeType.Operand) { return(BooleanMode.Explicit); } OptionAttribute?optionAttr = argumentDef.GetCustomAttribute <OptionAttribute>(); if (optionAttr?.BooleanModeAsNullable == null) { return(defaultBooleanMode); } return(argumentDef.Type.GetUnderlyingType() == typeof(bool) ? optionAttr.BooleanMode : throw new InvalidConfigurationException( $"BooleanMode is set to `{optionAttr.BooleanMode}` for a non boolean type. {argumentDef}")); }
public void DefaultNullableBool(BooleanMode booleanMode, bool isOptional, bool hasDefault, int expectedMin, int expectedMax) { var actual = ArgumentArity.Default(typeof(bool?), isOptional, hasDefault, booleanMode); var expected = new ArgumentArity(expectedMin, expectedMax); actual.Should().Be(expected); }
public BooleanOP(SystemPanel _owner, BinaryReader src) : base(_owner, src) { channels = src.ReadInt32(); booleanOp = (BooleanMode)src.ReadInt32(); init(); }
/// <summary>Sets a Boolean value in the ini section, in the chosen boolean save mode.</summary> /// <param name="key">The name of the key</param> /// <param name="value">Value to write</param> /// <param name="booleanmode">The BooleanMode (True/False, Yes/No, 1/0, etc) to use for saving Booleans as String.</param> /// <param name="removeComments">True to remove any comments put behind the value. The default behaviour is to filter out the comment and paste it behind the new value</param> public void setBoolValue(String key, Boolean value, BooleanMode booleanmode, Boolean removeComments) { Boolean exists = true; String strValue = getStringValue(key, String.Empty, out exists); String comment = String.Empty; if (exists && removeComments) { comment = splitOffComment(strValue)[1]; } switch (booleanmode) { case BooleanMode.ONE_ZERO: strValue = (value ? "1" : "0"); break; case BooleanMode.YES_NO: strValue = (value ? "Yes" : "No"); break; case BooleanMode.ENABLED_DISABLED: strValue = (value ? "Enabled" : "Disabled"); break; case BooleanMode.ACTIVE_INACTIVE: strValue = (value ? "Active" : "Inactive"); break; case BooleanMode.AYE_NAY: strValue = (value ? "Aye" : "Nay"); break; default: // includes True/False strValue = value.ToString(); break; } strValue += comment; setStringValue(key, strValue); }
public void setBoolValue(String key, Boolean value, BooleanMode booleanmode, Boolean removeComments) { Boolean exists; String strValue = getStringValue(key, String.Empty, out exists); String comment = String.Empty; if (exists) { comment = (removeComments ? String.Empty : cutOffComment(ref strValue)); } switch (booleanmode) { case BooleanMode.ONEZERO: strValue = (value ? "1" : "0"); break; case BooleanMode.YESNO: strValue = (value ? "Yes" : "No"); break; case BooleanMode.ENABLEDDISABLED: strValue = (value ? "Enabled" : "Disabled"); break; case BooleanMode.AYENAY: strValue = (value ? "Aye" : "Nay"); break; default: // includes True/False strValue = value.ToString(); break; } strValue += comment; setStringValue(key, strValue); }
/// <summary> /// Creates an object for reading, editing and writing an ini file. /// </summary> /// <param name="filePath">Path of the file to read</param> /// <param name="initialCaps">Write back all ini keys with initial capital letter</param> /// <param name="textEncoding">Text encoding to use for reading (and writing) the file</param> /// <param name="booleanMode">Default true/false set to use when writing booleans to the ini file.</param> public IniFile(String filePath, Boolean initialCaps, BooleanMode booleanMode, Encoding textEncoding) { if (textEncoding == null) throw new ArgumentNullException("textEncoding"); if (filePath == null) throw new ArgumentNullException("filePath"); this.InitialCaps = initialCaps; this.BooleanMode = booleanMode; readIniFile(filePath, textEncoding); }
/// <summary> /// Creates an object for reading, editing and writing an ini file /// that doesn't necessarily exist yet. /// </summary> /// <param name="filePath">Path of the file to read</param> /// <param name="filecontents">String with the file contents in it</param> /// <param name="initialCaps">Write back all ini keys with initial capital letter</param> /// <param name="booleanModeDefault">The default behaviour for writing boolean strings</param> /// <param name="removeCommentsDefault">The default behaviour for handling the comments behind non-string values when writing a new value</param> /// <param name="textEncoding">Text encoding to use for reading (and writing) the file</param> public IniFile(String filePath, String filecontents, Boolean initialCaps, BooleanMode booleanModeDefault, Boolean removeCommentsDefault, Encoding textEncoding) { this.filePath = filePath; this._textEncoding = textEncoding; byte[] byteArray = Encoding.ASCII.GetBytes(filecontents); MemoryStream stream = new MemoryStream(byteArray); StreamReader reader = new StreamReader(stream, _textEncoding, false); this.booleanModeDefault = booleanModeDefault; this.iniSections = readIniContents(reader); }
/// <summary> /// Creates an object for reading, editing and writing an ini file /// that doesn't necessarily exist yet. /// </summary> /// <param name="filePath">Path of the file to read</param> /// <param name="filecontents">String with the file contents in it</param> /// <param name="initialCaps">Write back all ini keys with initial capital letter</param> /// <param name="booleanMode">Default true/false set to use when writing booleans to the ini file.</param> /// <param name="textEncoding">Text encoding to use for reading (and writing) the file</param> public IniFile(String filePath, String filecontents, Boolean initialCaps, BooleanMode booleanMode, Encoding textEncoding) { this.filePath = filePath; this.BooleanMode = booleanMode; this.InitialCaps = initialCaps; this.TextEncoding = textEncoding; byte[] byteArray = TextEncoding.GetBytes(filecontents); MemoryStream stream = new MemoryStream(byteArray); StreamReader reader = new StreamReader(stream, TextEncoding); readIniContents(reader); }
private static BooleanMode GetOptionBooleanMode( IArgumentDef argumentDef, BooleanMode defaultBooleanMode, OptionAttribute?optionAttr) { if (optionAttr?.BooleanModeAsNullable == null) { return(defaultBooleanMode); } return(argumentDef.Type.GetUnderlyingType() == typeof(bool) ? optionAttr.BooleanMode : throw new InvalidConfigurationException( $"BooleanMode is set to `{optionAttr.BooleanMode}` for a non boolean type. {argumentDef}")); }
private static BooleanMode GetOptionBooleanMode( IArgumentDef argumentDef, BooleanMode appBooleanMode, OptionAttribute optionAttr) { if (optionAttr == null || optionAttr.BooleanMode == BooleanMode.Unknown) { return(appBooleanMode); } return(argumentDef.Type.GetUnderlyingType() == typeof(bool) ? optionAttr.BooleanMode : throw new AppRunnerException( $"BooleanMode is set to `{optionAttr.BooleanMode}` for a non boolean type. {argumentDef}")); }
/// <summary> /// Creates an object for reading, editing and writing an ini file. /// </summary> /// <param name="filePath">Path of the file to read</param> /// <param name="initialCaps">Write back all ini keys with initial capital letter</param> /// <param name="textEncoding">Text encoding to use for reading (and writing) the file</param> /// <param name="booleanMode">Default true/false set to use when writing booleans to the ini file.</param> public IniFile(String filePath, Boolean initialCaps, BooleanMode booleanMode, Encoding textEncoding) { if (textEncoding == null) { throw new ArgumentNullException("textEncoding"); } if (filePath == null) { throw new ArgumentNullException("filePath"); } this.InitialCaps = initialCaps; this.BooleanMode = booleanMode; readIniFile(filePath, textEncoding); }
/// <summary> /// Creates an object for reading, editing and writing an ini file. /// </summary> /// <param name="filePath">Path of the file to read</param> /// <param name="initialCaps">Write back all ini keys with initial capital letter</param> /// <param name="booleanModeDefault">The default behaviour for writing boolean strings</param> /// <param name="removeCommentsDefault">The default behaviour for handling the comments behind non-string values when writing a new value</param> /// <param name="textEncoding">Text encoding to use for reading (and writing) the file</param> public IniFile(String filePath, Boolean initialCaps, BooleanMode booleanModeDefault, Boolean removeCommentsDefault, Encoding textEncoding) { if (textEncoding == null) { throw new ArgumentNullException("textEncoding"); } if (filePath == null) { throw new ArgumentNullException("filePath"); } this.initialCaps = initialCaps; this.removeCommentsDefault = removeCommentsDefault; this.booleanModeDefault = booleanModeDefault; readIniFile(filePath, textEncoding); }
/// <summary>Returns the default IArgumentArity for the given type</summary> public static IArgumentArity Default(Type type, bool hasDefaultValue, BooleanMode booleanMode) { if (type == typeof(bool) && booleanMode == BooleanMode.Unknown) { throw new ArgumentException($"{nameof(booleanMode)} cannot be {nameof(BooleanMode.Unknown)}"); } bool isRequired = !(hasDefaultValue || type.IsNullableType()); if (type != typeof(string) && type.IsEnumerable()) { return(isRequired ? OneOrMore : ZeroOrMore); } if (booleanMode == BooleanMode.Implicit && (type == typeof(bool) || type == typeof(bool?))) { return(Zero); } return(isRequired ? ExactlyOne : ZeroOrOne); }
/// <summary> /// Apply a boolean operation (Union, Difference, Intersection, or XOr) to two lists of Polygons. /// </summary> /// <param name="subjectPolygons">Polygons to clip</param> /// <param name="clippingPolygons">Polygons with which to clip</param> /// <param name="mode">The operation to apply: Union, Difference, Intersection, or XOr</param> /// <param name="tolerance">Optional override of the tolerance for determining if two polygons are identical.</param> private static IList <Polygon> BooleanTwoSets(IList <Polygon> subjectPolygons, IList <Polygon> clippingPolygons, BooleanMode mode, double tolerance = Vector3.EPSILON) { var subjectPaths = subjectPolygons.Select(s => s.ToClipperPath(tolerance)).ToList(); var clipPaths = clippingPolygons.Select(s => s.ToClipperPath(tolerance)).ToList(); Clipper clipper = new Clipper(); clipper.AddPaths(subjectPaths, PolyType.ptSubject, true); clipper.AddPaths(clipPaths, PolyType.ptClip, true); var solution = new List <List <IntPoint> >(); var executionMode = ClipType.ctDifference; switch (mode) { case BooleanMode.Difference: executionMode = ClipType.ctDifference; break; case BooleanMode.Union: executionMode = ClipType.ctUnion; break; case BooleanMode.Intersection: executionMode = ClipType.ctIntersection; break; case BooleanMode.XOr: executionMode = ClipType.ctXor; break; } clipper.Execute(executionMode, solution); if (solution.Count == 0) { return(null); } var polygons = new List <Polygon>(); foreach (List <IntPoint> path in solution) { polygons.Add(PolygonExtensions.ToPolygon(path, tolerance)); } return(polygons); }
/// <summary> /// Creates an object for reading, editing and writing an ini file /// that doesn't necessarily exist yet, /// set to write back all ini keys with initial capital letter, /// and with the default DOS U.S. ASCII-437 encoding. /// </summary> /// <param name="filePath">Path of the file to read</param> /// <param name="filecontents">String with the file contents in it</param> /// <param name="booleanMode">Default true/false set to use when writing booleans to the ini file.</param> public IniFile(String filePath, String filecontents, BooleanMode booleanMode) : this(filePath, filecontents, DEFAULT_INITIALCAPS, booleanMode, DEFAULT_ENCODING) { }
/// <summary>Sets a Boolean value in the ini section, in the chosen boolean save mode.</summary> /// <param name="key">The name of the key</param> /// <param name="value">Value to write</param> /// <param name="booleanmode">The BooleanMode (True/False, Yes/No, 1/0, etc) to use for saving Booleans as String.</param> /// <param name="removeComments">True to remove any comments put behind the value. The default behaviour is to filter out the comment and paste it behind the new value</param> public void setBoolValue(String key, Boolean value, BooleanMode booleanmode, Boolean removeComments) { Boolean exists = true; String strValue = getStringValue(key, String.Empty, out exists); String comment = String.Empty; if (exists && removeComments) comment = splitOffComment(strValue)[1]; switch (booleanmode) { case BooleanMode.ONE_ZERO: strValue = (value ? "1" : "0"); break; case BooleanMode.YES_NO: strValue = (value ? "Yes" : "No"); break; case BooleanMode.ENABLED_DISABLED: strValue = (value ? "Enabled" : "Disabled"); break; case BooleanMode.ACTIVE_INACTIVE: strValue = (value ? "Active" : "Inactive"); break; case BooleanMode.AYE_NAY: strValue = (value ? "Aye" : "Nay"); break; default: // includes True/False strValue = value.ToString(); break; } strValue += comment; setStringValue(key, strValue); }
/// <summary> /// Creates an object for reading, editing and writing an ini file /// that doesn't necessarily exist yet, /// set to write back all ini keys with initial capital letter. /// </summary> /// <param name="filePath">Path of the file to read</param> /// <param name="filecontents">String with the file contents in it</param> /// <param name="booleanMode">Default true/false set to use when writing booleans to the ini file.</param> /// <param name="textEncoding">Text encoding to use for reading (and writing) the file</param> public IniFile(String filePath, String filecontents, BooleanMode booleanMode, Encoding textEncoding) : this(filePath, filecontents, DEFAULT_INITIALCAPS, booleanMode, textEncoding) { }
/// <summary> /// Creates an object for reading, editing and writing an ini file, /// with the default DOS U.S. ASCII-437 encoding. /// </summary> /// <param name="filePath">Path of the file to read</param> /// <param name="initialCaps">Write back all ini keys with initial capital letter</param> /// <param name="booleanMode">Default true/false set to use when writing booleans to the ini file.</param> public IniFile(String filePath, Boolean initialCaps, BooleanMode booleanMode) : this(filePath, initialCaps, booleanMode, DEFAULT_ENCODING) { }
/// <summary>Sets a Boolean value in the ini file, in the chosen boolean save mode. /// This action does not save the file.</summary> /// <param name="sectionName">The name of the section the key should be in</param> /// <param name="key">The name of the key</param> /// <param name="value">Value to write</param> /// <param name="booleanmode">The BooleanMode (True/False, Yes/No, 1/0, etc) to use for saving Booleans as String.</param> /// <param name="removeComments">True to remove any comments put behind the value. The default behaviour is to filter out the comment and paste it behind the new value.</param> public void setBoolValue(String sectionName, String key, Boolean value, BooleanMode booleanmode, Boolean removeComments) { IniSection iniSection = getSection(sectionName,true); iniSection.setBoolValue(key, value, booleanmode, removeComments); }
/// <summary> /// Creates an object for reading, editing and writing an ini file /// that doesn't necessarily exist yet, /// with the default DOS U.S. ASCII-437 encoding. /// </summary> /// <param name="filePath">Path of the file to read</param> /// <param name="filecontents">String with the file contents in it</param> /// <param name="booleanMode">Default true/false set to use when writing booleans to the ini file.</param> /// <param name="initialCaps">Write back all ini keys with initial capital letter</param> public IniFile(String filePath, String filecontents, Boolean initialCaps, BooleanMode booleanMode) : this(filePath, filecontents, initialCaps, booleanMode, DEFAULT_ENCODING) { }
public void setBoolValue(String sectionName, String key, Boolean value, BooleanMode booleanmode, Boolean removeComments) { IniSection iniSection = getSection(sectionName, true); iniSection.setBoolValue(key, value, booleanmode, removeComments); }
public BooleanOP(BooleanMode _booleanOp, int _channels) : base() { booleanOp = _booleanOp; channels = _channels; init(); }