public void Insert(int index, Block item) { if (item == null) { ThrowHelper.ArgumentNullException_item(); } if (item.Parent != null) { ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)"); } if ((uint)index > (uint)Count) { ThrowHelper.ArgumentOutOfRangeException_index(); } if (Count == children.Length) { EnsureCapacity(Count + 1); } if (index < Count) { Array.Copy(children, index, children, index + 1, Count - index); } children[index] = item; Count++; item.Parent = this; }
public void Insert(int index, Block item) { if (item is null) { ThrowHelper.ArgumentNullException_item(); } if (item.Parent != null) { ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)"); } if ((uint)index > (uint)Count) { ThrowHelper.ArgumentOutOfRangeException_index(); } if (Count == _children.Length) { Grow(); } if (index < Count) { Array.Copy(_children, index, _children, index + 1, Count - index); } _children[index] = new BlockWrapper(item); Count++; item.Parent = this; }
/// <summary> /// Inserts the specified inline after this instance. /// </summary> /// <param name="next">The inline to insert after this instance.</param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.ArgumentException">Inline has already a parent</exception> public void InsertAfter(Inline next) { if (next == null) { ThrowHelper.ArgumentNullException(nameof(next)); } if (next.Parent != null) { ThrowHelper.ArgumentException("Inline has already a parent", nameof(next)); } var previousNext = NextSibling; if (previousNext != null) { previousNext.PreviousSibling = next; } next.PreviousSibling = this; next.NextSibling = previousNext; NextSibling = next; if (Parent != null) { Parent.OnChildInsert(next); next.Parent = Parent; } }
/// <summary> /// Inserts the specified inline before this instance. /// </summary> /// <param name="previous">The inline previous to insert before this instance.</param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.ArgumentException">Inline has already a parent</exception> public void InsertBefore(Inline previous) { if (previous == null) { ThrowHelper.ArgumentNullException(nameof(previous)); } if (previous.Parent != null) { ThrowHelper.ArgumentException("Inline has already a parent", nameof(previous)); } var previousSibling = PreviousSibling; if (previousSibling != null) { previousSibling.NextSibling = previous; } PreviousSibling = previous; previous.NextSibling = this; if (Parent != null) { Parent.OnChildInsert(previous); previous.Parent = Parent; } }
/// <summary> /// Opens the specified block. /// </summary> /// <param name="block">The block.</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException">The block must be opened</exception> public void Open(Block block) { if (block == null) { ThrowHelper.ArgumentNullException(nameof(block)); } if (!block.IsOpen) { ThrowHelper.ArgumentException("The block must be opened", nameof(block)); } OpenedBlocks.Add(block); }
public Variable64(byte[] bytes, int index, int count) { ThrowHelper.ArgumentNull((bytes == null), nameof(bytes)); ThrowHelper.ArgumentException((count != sizeof(Int64)), SR.Variable64_Exception_SizeUnexpected, nameof(count)); unsafe { fixed(byte *point = bytes) { this._value = *((Int64 *)(point + index)); } } }
/// <summary> /// Create a <see cref="IHostProvider"/> with delegate handler. /// </summary> /// <param name="hostPrefix">Prefix of host that can be handled.</param> /// <param name="handler">Handler that generate iframe url, if uri cannot be handled, it can return <see langword="null"/>.</param> /// <param name="allowFullScreen">Should the generated iframe has allowfullscreen attribute.</param> /// <param name="iframeClass">"class" attribute of generated iframe.</param> /// <returns>A <see cref="IHostProvider"/> with delegate handler.</returns> public static IHostProvider Create(string hostPrefix, Func <Uri, string?> handler, bool allowFullScreen = true, string?iframeClass = null) { if (string.IsNullOrEmpty(hostPrefix)) { ThrowHelper.ArgumentException("hostPrefix is null or empty.", nameof(hostPrefix)); } if (handler is null) { ThrowHelper.ArgumentNullException(nameof(handler)); } return(new DelegateProvider(hostPrefix, handler, allowFullScreen, iframeClass)); }
public static byte[] FromHexString(string text, bool ignoreSpace = false) { ThrowHelper.ArgumentNull((text == null), nameof(text)); string value = ignoreSpace ? Regex.Replace(text, @"\s", "") : text; ThrowHelper.ArgumentException(((value.Length % 2) != 0), SR.Bytes_Exception_InvalidHexText, nameof(value)); byte[] buffer = new byte[value.Length / 2]; for (int i = 0; i < value.Length; i += 2) { byte b = Calculator.GetHexValue(value[i], value[i + 1]); buffer[i / 2] = b; } return(buffer); }
public MD5Code(byte[] codes) { ThrowHelper.ArgumentNull((codes == null), nameof(codes)); ThrowHelper.ArgumentException((codes.Length != MD5Code.ByteLength), SR.MD5Code_Exception_InvalidBytes, nameof(codes)); unsafe { fixed(MD5Code *p = &this) { byte *pointer = (byte *)p; for (int i = 0; i < MD5Code.ByteLength; i++) { *(pointer + i) = codes[i]; } } } }
/// <summary> /// Initializes a new instance of the <see cref="SelfPipelineExtension"/> class. /// </summary> /// <param name="tag">The matching start tag.</param> /// <param name="defaultExtensions">The default extensions.</param> /// <exception cref="ArgumentException">Tag cannot contain angle brackets</exception> public SelfPipelineExtension(string tag = null, string defaultExtensions = null) { tag = tag?.Trim(); tag = string.IsNullOrEmpty(tag) ? DefaultTag : tag; if (tag.AsSpan().IndexOfAny('<', '>') >= 0) { ThrowHelper.ArgumentException("Tag cannot contain `<` or `>` characters", nameof(tag)); } if (defaultExtensions != null) { // Check that this default pipeline is supported // Will throw an ArgumentInvalidException if not new MarkdownPipelineBuilder().Configure(defaultExtensions); } DefaultExtensions = defaultExtensions; SelfPipelineHintTagStart = "<!--" + tag + ":"; }
public static byte[] AesDecode(byte[] cipher, byte[] key, byte[] iv) { // Validate parameter ThrowHelper.ArgumentNull((cipher == null), nameof(cipher)); ThrowHelper.ArgumentNull((key == null), nameof(key)); ThrowHelper.ArgumentException((key.Length != (128 / Meision.Algorithms.UnitTable.ByteToBit)), SR.Cryptography_Exceiption_InvalidKey, nameof(key)); ThrowHelper.ArgumentNull((iv == null), nameof(iv)); ThrowHelper.ArgumentException((iv.Length != (128 / Meision.Algorithms.UnitTable.ByteToBit)), SR.Cryptography_Exceiption_InvalidIV, nameof(iv)); using (System.IO.MemoryStream memory = new System.IO.MemoryStream()) using (RijndaelManaged aes = new RijndaelManaged()) using (ICryptoTransform transform = aes.CreateDecryptor(key, iv)) using (CryptoStream stream = new CryptoStream(memory, transform, CryptoStreamMode.Write)) { stream.Write(cipher, 0, cipher.Length); stream.FlushFinalBlock(); return(memory.ToArray()); } }
public MD5Code(string value) { ThrowHelper.ArgumentNull((value == null), nameof(value)); ThrowHelper.ArgumentException((value.Length != MD5Code.ByteLength * Meision.Algorithms.UnitTable.HexTextCountPerByte), SR.MD5Code_Exception_InvalidText, nameof(value)); ThrowHelper.ArgumentException((!Regex.IsMatch(value, "^" + RegularExpression + "$")), SR.MD5Code_Exception_InvalidText, nameof(value)); unsafe { fixed(MD5Code *p = &this) { byte *pointer = (byte *)p; for (int i = 0; i < value.Length; i += 2) { *(pointer + i / 2) = Calculator.GetHexValue(value[i], value[i + 1]); } } } }
public static long GetSize(string path, SearchOption option) { // Validate parameter(s). ThrowHelper.ArgumentNull((path == null), nameof(path)); ThrowHelper.ArgumentException((!PathManager.IsFileSystem(path)), SR.Path_Invalid); if (System.IO.File.Exists(path)) { FileInfo file = new FileInfo(path); return(file.Length); } else if (System.IO.Directory.Exists(path)) { return(DirectoryManager.GetTotalSize(path, option)); } else { throw new ArgumentException(SR.Path_Invalid); } }
public static byte[] DesEncode(byte[] clear, byte[] key, byte[] iv) { // Validate parameter ThrowHelper.ArgumentNull((clear == null), nameof(clear)); ThrowHelper.ArgumentNull((key == null), nameof(key)); ThrowHelper.ArgumentException((key.Length != (64 / Meision.Algorithms.UnitTable.ByteToBit)), SR.Cryptography_Exceiption_InvalidKey, nameof(key)); ThrowHelper.ArgumentNull((iv == null), nameof(iv)); ThrowHelper.ArgumentException((iv.Length != (64 / Meision.Algorithms.UnitTable.ByteToBit)), SR.Cryptography_Exceiption_InvalidIV, nameof(iv)); using (System.IO.MemoryStream memory = new System.IO.MemoryStream()) using (DES des = DESCryptoServiceProvider.Create()) using (ICryptoTransform transform = des.CreateEncryptor(key, iv)) using (CryptoStream stream = new CryptoStream(memory, transform, CryptoStreamMode.Write)) { stream.Write(clear, 0, clear.Length); stream.FlushFinalBlock(); return(memory.ToArray()); } }
public static string[] ConvertToStringArray(byte[] buffer) { ThrowHelper.ArgumentNull((buffer == null), nameof(buffer)); ThrowHelper.ArgumentException((((buffer.Length % 2) != 0) || (buffer[buffer.Length - 2] != 0) || (buffer[buffer.Length - 1] != 0)), SR.Bytes_ConvertToStringArray_Exception_InvalidByteArray); List <string> items = new List <string>(); unsafe { fixed(byte *pByte = buffer) { for (int index = 0; index < buffer.Length;) { string item = new string((char *)(pByte + index)); index += ((item.Length + 1) * sizeof(char)); items.Add(item); } } } return(items.ToArray()); }
public void Add(Block item) { if (item == null) { ThrowHelper.ArgumentNullException_item(); } if (item.Parent != null) { ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)"); } if (Count == children.Length) { EnsureCapacity(Count + 1); } children[Count++] = item; item.Parent = this; UpdateSpanEnd(item.Span.End); }
public Block this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var array = _children; if ((uint)index >= (uint)array.Length || index >= Count) { ThrowHelper.ThrowIndexOutOfRangeException(); return(null); } return(array[index].Block); } set { if ((uint)index >= (uint)Count) { ThrowHelper.ThrowIndexOutOfRangeException(); } if (value is null) { ThrowHelper.ArgumentNullException_item(); } if (value.Parent != null) { ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)"); } var existingChild = _children[index].Block; if (existingChild != null) { existingChild.Parent = null; } value.Parent = this; _children[index] = new BlockWrapper(value); } }
public Block this[int index] { get { var array = children; if ((uint)index >= (uint)array.Length || index >= Count) { ThrowHelper.ThrowIndexOutOfRangeException(); return(null); } return(array[index]); } set { if ((uint)index >= (uint)Count) { ThrowHelper.ThrowIndexOutOfRangeException(); } if (value == null) { ThrowHelper.ArgumentNullException_item(); } if (value.Parent != null) { ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)"); } var existingChild = children[index]; if (existingChild != null) { existingChild.Parent = null; } value.Parent = this; children[index] = value; } }
public void Add(Block item) { if (item is null) { ThrowHelper.ArgumentNullException_item(); } if (item.Parent != null) { ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)"); } if (Count == _children.Length) { Grow(); } _children[Count] = new BlockWrapper(item); Count++; item.Parent = this; UpdateSpanEnd(item.Span.End); }
/// <summary> /// Appends a child to this container. /// </summary> /// <param name="child">The child to append to this container..</param> /// <returns>This instance</returns> /// <exception cref="ArgumentNullException">If child is null</exception> /// <exception cref="ArgumentException">Inline has already a parent</exception> public virtual ContainerInline AppendChild(Inline child) { if (child == null) { ThrowHelper.ArgumentNullException(nameof(child)); } if (child.Parent != null) { ThrowHelper.ArgumentException("Inline has already a parent", nameof(child)); } if (FirstChild == null) { FirstChild = child; LastChild = child; child.Parent = this; } else { LastChild.InsertAfter(child); } return(this); }