/// <summary> /// Returns the {@link String} representation of this channel. The returned /// string contains the {@linkplain #hashCode()} ID}, {@linkplain #localAddress() local address}, /// and {@linkplain #remoteAddress() remote address} of this channel for /// easier identification. /// </summary> public override string ToString() { bool active = this.Active; if (this.strValActive == active && this.strVal != null) { return(this.strVal); } EndPoint remoteAddr = this.RemoteAddress; EndPoint localAddr = this.LocalAddress; if (remoteAddr != null) { EndPoint srcAddr; EndPoint dstAddr; if (this.Parent == null) { srcAddr = localAddr; dstAddr = remoteAddr; } else { srcAddr = remoteAddr; dstAddr = localAddr; } StringBuilder buf = new StringBuilder(96) .Append("[id: 0x") .Append(Id.AsShortText()) .Append(", ") .Append(srcAddr) .Append(active ? " => " : " :> ") .Append(dstAddr) .Append(']'); this.strVal = buf.ToString(); } else if (localAddr != null) { StringBuilder buf = new StringBuilder(64) .Append("[id: 0x") .Append(Id.AsShortText()) .Append(", ") .Append(localAddr) .Append(']'); this.strVal = buf.ToString(); } else { StringBuilder buf = new StringBuilder(16) .Append("[id: 0x") .Append(Id.AsShortText()) .Append(']'); this.strVal = buf.ToString(); } this.strValActive = active; return(this.strVal); }
/// <summary> /// Returns the string representation of this channel. The returned string contains a hex dump of the /// <see cref="IChannelId"/>, the <see cref="LocalAddress"/>, and the <see cref="RemoteAddress"/> of this /// channel for easier identification. /// </summary> public override string ToString() { bool active = IsActive; if (_strValActive == active && _strVal is object) { return(_strVal); } EndPoint remoteAddr = RemoteAddress; EndPoint localAddr = LocalAddress; if (remoteAddr is object) { var buf = StringBuilderCache.Acquire(96) .Append("[id: 0x") .Append(Id.AsShortText()) .Append(", L:") .Append(localAddr) .Append(active ? " - " : " ! ") .Append("R:") .Append(remoteAddr) .Append(']'); _strVal = StringBuilderCache.GetStringAndRelease(buf); } else if (localAddr is object) { var buf = StringBuilderCache.Acquire(64) .Append("[id: 0x") .Append(Id.AsShortText()) .Append(", L:") .Append(localAddr) .Append(']'); _strVal = StringBuilderCache.GetStringAndRelease(buf); } else { var buf = StringBuilderCache.Acquire(16) .Append("[id: 0x") .Append(Id.AsShortText()) .Append(']'); _strVal = StringBuilderCache.GetStringAndRelease(buf); } _strValActive = active; return(_strVal); }