public void ApplyProperties_requires_at_least_one_argument() { var method = typeof(S).GetMethod("CInvalidNoArgs"); var expectedMessage = RuntimeFailure.ApplyPropertiesStaticMethodRequiresArg("method").Message; var ex = Record.Exception(() => method.ApplyProperties(new S(), Properties.Empty)); Assert.NotNull(ex); Assert.Equal(expectedMessage, ex.Message); }
public void ApplyProperties_requires_matching_argument_thisInstance_on_static_methods() { var method = typeof(S).GetMethod("CInvalid"); var expectedMessage = RuntimeFailure.ThisArgumentIncorrectType(typeof(S)).Message; var ex = Record.Exception(() => method.ApplyProperties(new S(), Properties.Empty)); Assert.NotNull(ex); Assert.Equal(expectedMessage, ex.Message); }
private static char UnescapeUnicode(string chars) { if (chars == null) { throw RuntimeFailure.IncompleteEscapeSequence(); } int unicodeValue = Convert.ToInt32(chars, 16); return(Convert.ToChar(unicodeValue)); }
public static char UnescapeHex(string chars) { if (chars == null) { throw RuntimeFailure.IncompleteEscapeSequence(); } int hexValue = Convert.ToInt32(chars, 16); return(Convert.ToChar(hexValue)); }
public override void Write(byte[] buffer, int offset, int count) { if (CanWrite) { BaseStream.Write(buffer, offset, count); } else { throw RuntimeFailure.CannotWriteToStream(); } }
public static T GetRequiredService <T>(this IServiceProvider serviceProvider) { if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } T t = (T)serviceProvider.GetService(typeof(T)); if (object.Equals(t, default(T))) { throw RuntimeFailure.ServiceNotFound(typeof(T)); } return(t); }
public override long Seek(long offset, SeekOrigin origin) { if (!BaseStream.CanSeek) { throw RuntimeFailure.SeekNotSupportedByBase(); } if (!(origin == SeekOrigin.Begin || origin == SeekOrigin.End || origin == SeekOrigin.Current)) { throw Failure.NotDefinedEnum("origin", origin); } if (offset < 0 && origin == SeekOrigin.Begin) { throw RuntimeFailure.SeekNegativeBegin("offset", offset); } // Do the seek on the base return(BaseStream.Seek(offset, origin)); }
internal static void VerifyLocalName(string argName, string value) { if (value == null) { throw new ArgumentNullException(argName); } if (value.Length == 0) { throw Failure.EmptyString(argName); } foreach (char c in value) { if (!IsValidChar(c)) { throw RuntimeFailure.NotValidLocalName(argName); } } }
internal static char UnescapeChar(IEnumerator <char> e) { char?c0 = e.RequireNext(); if (!c0.HasValue) { throw RuntimeFailure.IncompleteEscapeSequence(); } char c = c0.Value; switch (c) { case 'b': return('\b'); case 't': return('\t'); case 'n': return('\n'); case 'f': return('\f'); case 'r': return('\r'); case 'u': return(UnescapeUnicode(e.RequireNext(4))); case 'x': return(UnescapeHex(e.RequireNext(2))); case '0': return('\0'); default: return(c); } }
static Exception _TryParse(string text, IServiceProvider serviceProvider, out QualifiedName result) { serviceProvider = serviceProvider ?? ServiceProvider.Null; result = null; if (string.IsNullOrEmpty(text)) { throw Failure.NullOrEmptyString(nameof(text)); } // Remove decorations: [prefix:b] ==> prefix:b if (text[0] == '[' && text[text.Length - 1] == ']') { text = text.Substring(1, text.Length - 2); } else if (text[0] == '{') { int num = text.LastIndexOf('}'); if ((num <= 1) || (num == (text.Length - 1))) { return(Failure.NotParsable("text", typeof(QualifiedName))); } if (num - 1 == 0) { // The default namespace is used (as in '{} expandedName') result = NamespaceUri.Default.GetName(text.Trim()); return(null); } else { // Some other namespace is used string ns = text.Substring(1, num - 1); string localName = text.Substring(num + 1).Trim(); NamespaceUri nu = NamespaceUri._TryParse(ns, false); if (nu == null) { return(Failure.NotParsable("text", typeof(QualifiedName))); } result = nu.GetName(localName); return(null); } } if (!text.Contains(":")) { result = NamespaceUri.Default.GetName(text.Trim()); return(null); } var resolver = (IXmlNamespaceResolver)serviceProvider.GetService(typeof(IXmlNamespaceResolver)) ?? XmlNamespaceResolver.Global; int index = text.IndexOf(':'); string prefix = text.Substring(0, index); string name = text.Substring(index + 1); string fullNs = resolver.LookupNamespace(prefix); if (fullNs != null) { result = QualifiedName.Create(fullNs, name); return(null); } return(Failure.NotParsable("text", typeof(QualifiedName), RuntimeFailure.CannotExpandPrefixNotFound(prefix))); }
public override void SetLength(long value) { throw RuntimeFailure.CannotWriteToStream(); }