/// <summary> /// Initializes a new instance of the <see cref="ExplicitOutputDependencyAttribute"/> class. /// </summary> /// <param name="property">The name of the property the attributed property depends on.</param> public ExplicitOutputDependencyAttribute(string property) { ArgValidator.Create(property, "property").IsNotNull(); this.Property = property; }
public static T Resolve <T>(Type type) { ArgValidator.IsNotNull(type, "type"); return((T)_Container.Resolve(type)); }
public static T Resolve <T>(string name) { ArgValidator.IsNotEmpty(name, "name"); return(_Container.Resolve <T>(name)); }
/// <summary> /// Converts an integer to a hexidecimal string. /// </summary> /// <param name="value">The value to convert.</param> /// <returns>The string representation of the value that is used by XLIFF.</returns> string IValueConverter.Convert(object value) { ArgValidator.Create(value, "value").IsNotNull().IsOfType(typeof(int)); return(string.Format("{0:X}", value).PadLeft(4, '0')); }
/// <summary> /// Converts a hexidecimal string to an integer. /// </summary> /// <param name="value">The XLIFF string to convert.</param> /// <returns>The integer value of the string.</returns> object IValueConverter.ConvertBack(string value) { ArgValidator.Create(value, "value").IsNotNullOrWhitespace(); return(int.Parse(value, NumberStyles.HexNumber)); }
/// <summary> /// Adds an element or text member to the extension data. /// </summary> /// <param name="child">The child to add.</param> public void AddChild(ElementInfo child) { ArgValidator.Create(child, "child").IsNotNull(); this.children.Value.Add(child); }
/// <summary> /// Converts an XLIFF string to a dictionary whose key and value are strings. /// </summary> /// <param name="value">The XLIFF string to convert.</param> /// <returns>The native type of the data.</returns> public object ConvertBack(string value) { IDictionary <string, string> result; int start; int length; string key; ArgValidator.Create(value, "value").IsNotWhitespaceOnly(); result = new Dictionary <string, string>(); start = 0; length = 0; key = null; for (int i = 0; i < value.Length; i++) { char c; c = value[i]; if (c == SubFormatStyleConverter.CommaChar) { // Delimiting the key from the value. if (key == null) { try { key = value.Substring(start, length); XmlConvert.VerifyName(key); } catch (Exception e) { string message; message = string.Format(Properties.Resources.SubFormatStyleConverter_InvalidKey_Format, key); throw new FormatException(message, e); } start = i + 1; length = 0; } else { string message; message = string.Format(Properties.Resources.SubFormatStyleConverter_CommaInValue_Format, key); throw new FormatException(message); } } else if (c == SubFormatStyleConverter.BackslashChar) { if ((i < (value.Length - 1)) && ((string.Format("{0}{1}", c, value[i + 1]) == SubFormatStyleConverter.EscapedBackslash) || (string.Format("{0}{1}", c, value[i + 1]) == SubFormatStyleConverter.EscapedComma))) { i++; length += 2; } else if (key != null) { // Delimiting entries. Overwrite duplicates. result[key] = value.Substring(start, length); key = null; start = i + 1; length = 0; } else { throw new FormatException(Properties.Resources.SubFormatStyleConverter_BackslashInKey); } } else { length++; } } if (length > 0) { if (key == null) { string message; message = string.Format( Properties.Resources.SubFormatStyleConverter_KeyWithoutValue_Format, value.Substring(start, length)); throw new FormatException(message); } else { // Overwrite duplicates. result[key] = value.Substring(start, length); } } return(result); }
/// <summary> /// Converts a DateTime to a string. /// </summary> /// <param name="value">The value to convert.</param> /// <returns>The string representation of the value that is used by XLIFF.</returns> string IValueConverter.Convert(object value) { ArgValidator.Create(value, "value").IsNotNull().IsOfType(typeof(DateTime)); return(((DateTime)value).ToString("O")); }
/// <summary> /// Converts a string to a DateTime. /// </summary> /// <param name="value">The XLIFF string to convert.</param> /// <returns>The integer value of the string.</returns> object IValueConverter.ConvertBack(string value) { ArgValidator.Create(value, "value").IsNotNullOrWhitespace(); return(DateTime.Parse(value, null, DateTimeStyles.RoundtripKind)); }
/// <summary> /// Converts an integer to a string. /// </summary> /// <param name="value">The value to convert.</param> /// <returns>The string representation of the value that is used by XLIFF.</returns> string IValueConverter.Convert(object value) { ArgValidator.Create(value, "value").IsNotNull().IsOfType(typeof(int)); return(value.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="HasValueIndicatorAttribute"/> class. /// </summary> /// <param name="type">The type of the indicator class.</param> public HasValueIndicatorAttribute(Type type) { ArgValidator.Create(type, "type").IsNotNull(); this.TypeName = type.FullName; }
public void WhenArgNotGreaterThanTwo_ThrowException() { const int myArg = 1; Assert.Throws <ArgumentOutOfRangeException>(() => ArgValidator.GreaterThan(myArg, 2, nameof(myArg))); }
public void WhenArgGreaterThenTwo_ThenDoNotThrowException() { const int myArg = 3; Assert.DoesNotThrow(() => ArgValidator.GreaterThan(myArg, 2, nameof(myArg))); }
/// <summary> /// Converts a string to a float. /// </summary> /// <param name="value">The XLIFF string to convert.</param> /// <returns>The float value of the string.</returns> object IValueConverter.ConvertBack(string value) { ArgValidator.Create(value, "value").IsNotNullOrWhitespace(); return(float.Parse(value)); }
/// <summary> /// Initializes a new instance of the <see cref="XliffWriter"/> class. /// </summary> /// <param name="settings">The settings describing how to write content.</param> public XliffWriter(XliffWriterSettings settings) { ArgValidator.Create(settings, "settings").IsNotNull(); this.settings = settings; }
public void SetUp() { sut = new ArgValidator(); }
/// <summary> /// Adds an attribute member to the extension data. /// </summary> /// <param name="attribute">The attribute to add.</param> public void AddAttribute(IExtensionAttribute attribute) { ArgValidator.Create(attribute, "attribute").IsNotNull(); this.attributes.Value.Add(attribute); }
/// <summary> /// Selects an item matching the selection query. /// </summary> /// <param name="path">The selection query.</param> /// <returns>The object that was selected from the query path, or null if no match was found.</returns> /// <example>The value of <paramref name="path"/> might look something like "#g=group1/f=file1/u=unit1/n=note1" /// which is a relative path from the current object, not a full path from the document root.</example> public ISelectable Select(string path) { ArgValidator.Create(path, "path").IsNotNull().StartsWith(Utilities.Constants.SelectorPathIndictator); return(this.SelectElement(Utilities.RemoveSelectorIndicator(path))); }
/// <summary> /// Adds an element to this object as a child. /// </summary> /// <param name="element">The object to add.</param> public void AddChild(ElementInfo element) { ArgValidator.Create(element, "element").IsNotNull(); this.StoreChild(element); }
/// <summary> /// Initializes a new instance of the <see cref="ConverterAttribute"/> class. /// </summary> /// <param name="type">The type of the converter class.</param> public ConverterAttribute(Type type) { ArgValidator.Create(type, "type").IsNotNull(); this.TypeName = type.FullName; }