本文整理汇总了C#中Builder.Append方法的典型用法代码示例。如果您正苦于以下问题:C# Builder.Append方法的具体用法?C# Builder.Append怎么用?C# Builder.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Builder
的用法示例。
在下文中一共展示了Builder.Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Append
public bool Append(Builder result, string separator)
{
result.Append(GetDisplayName());
result.Append(separator);
result.Append(Value);
return true;
}
示例2: ToByteArray
public override byte[] ToByteArray()
{
Builder<byte> b = new Builder<byte>();
b.Append(PacketID);
b.Append(Packet.PackString(Reason));
return b.ToArray();
}
示例3: GetBytes
public byte[] GetBytes()
{
Builder<Byte> builder = new Builder<Byte>();
builder.Append((byte[]) _Structure["Level"]["Blocks"].Payload);
builder.Append((byte[]) _Structure["Level"]["Data"].Payload);
builder.Append((byte[]) _Structure["Level"]["BlockLight"].Payload);
builder.Append((byte[]) _Structure["Level"]["SkyLight"].Payload);
return builder.ToArray();
}
示例4: AppendAsCollectionEntry
public bool AppendAsCollectionEntry(Builder result)
{
// Some BCL collections use [{key.ToString()}]: {value.ToString()} pattern to display collection entries.
// We want them to be printed initializer-style, i.e. { <key>, <value> }
if (HasKeyName())
{
result.AppendGroupOpening();
result.AppendCollectionItemSeparator(isFirst: true, inline: true);
result.Append(Name, 1, Name.Length - 2);
result.AppendCollectionItemSeparator(isFirst: false, inline: true);
result.Append(Value);
result.AppendGroupClosing(inline: true);
}
else
{
result.Append(Value);
}
return true;
}
示例5: ToByteArray
public override byte[] ToByteArray()
{
Builder<Byte> b = new Builder<byte>();
b.Append(PacketID);
b.Append(Packet.PackShort(X));
b.Append(Packet.PackShort(Y));
b.Append(Packet.PackShort(Z));
b.Append(Mode);
b.Append(Type);
return b.ToArray();
}
示例6: GetChunk
public Chunk GetChunk(int chunkX, int chunkZ)
{
Builder<byte> b = new Builder<byte>();
b.Append(BitConverter.GetBytes(chunkX));
b.Append(BitConverter.GetBytes(chunkZ));
long index = BitConverter.ToInt64(b.ToArray(), 0);
if (_Chunks.ContainsKey(index)) {
return _Chunks[index];
} else {
return _Chunks[index] = new Chunk(chunkX, chunkZ, this);
}
}
示例7: FormatWithEmbeddedExpressions
private Builder FormatWithEmbeddedExpressions(Builder result, string format, object obj)
{
int i = 0;
while (i < format.Length)
{
char c = format[i++];
if (c == '{')
{
if (i >= 2 && format[i - 2] == '\\')
{
result.Append('{');
}
else
{
int expressionEnd = format.IndexOf('}', i);
bool noQuotes, callableOnly;
string memberName;
if (expressionEnd == -1 || (memberName = ParseSimpleMemberName(format, i, expressionEnd, out noQuotes, out callableOnly)) == null)
{
// the expression isn't properly formatted
result.Append(format, i - 1, format.Length - i + 1);
break;
}
MemberInfo member = ResolveMember(obj, memberName, callableOnly);
if (member == null)
{
result.AppendFormat(callableOnly ? "!<Method '{0}' not found>" : "!<Member '{0}' not found>", memberName);
}
else
{
Exception exception;
object value = GetMemberValue(member, obj, out exception);
if (exception != null)
{
FormatException(result, exception);
}
else
{
MemberDisplayFormat oldMemberDisplayFormat = _memberDisplayFormat;
CommonPrimitiveFormatterOptions oldPrimitiveOptions = _primitiveOptions;
_memberDisplayFormat = MemberDisplayFormat.Hidden;
_primitiveOptions = new CommonPrimitiveFormatterOptions(
_primitiveOptions.NumberRadix,
_primitiveOptions.IncludeCharacterCodePoints,
quoteStringsAndCharacters: !noQuotes,
escapeNonPrintableCharacters: _primitiveOptions.EscapeNonPrintableCharacters,
cultureInfo: _primitiveOptions.CultureInfo);
string _;
FormatObjectRecursive(result, value, isRoot: false, debuggerDisplayName: out _);
_primitiveOptions = oldPrimitiveOptions;
_memberDisplayFormat = oldMemberDisplayFormat;
}
}
i = expressionEnd + 1;
}
}
else
{
result.Append(c);
}
}
return result;
}
示例8: FormatObjectRecursive
private Builder FormatObjectRecursive(Builder result, object obj, bool isRoot, out string debuggerDisplayName)
{
// TODO (https://github.com/dotnet/roslyn/issues/6689): remove this
if (!isRoot && _memberDisplayFormat == MemberDisplayFormat.SeparateLines)
{
_memberDisplayFormat = MemberDisplayFormat.SingleLine;
}
debuggerDisplayName = null;
string primitive = _formatter.PrimitiveFormatter.FormatPrimitive(obj, _primitiveOptions);
if (primitive != null)
{
result.Append(primitive);
return result;
}
Type type = obj.GetType();
TypeInfo typeInfo = type.GetTypeInfo();
//
// Override KeyValuePair<,>.ToString() to get better dictionary elements formatting:
//
// { { format(key), format(value) }, ... }
// instead of
// { [key.ToString(), value.ToString()], ... }
//
// This is more general than overriding Dictionary<,> debugger proxy attribute since it applies on all
// types that return an array of KeyValuePair in their DebuggerDisplay to display items.
//
if (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
{
if (isRoot)
{
result.Append(_formatter.TypeNameFormatter.FormatTypeName(type, _typeNameOptions));
result.Append(' ');
}
FormatKeyValuePair(result, obj);
return result;
}
if (typeInfo.IsArray)
{
if (VisitedObjects.Add(obj))
{
FormatArray(result, (Array)obj);
VisitedObjects.Remove(obj);
}
else
{
result.AppendInfiniteRecursionMarker();
}
return result;
}
DebuggerDisplayAttribute debuggerDisplay = GetApplicableDebuggerDisplayAttribute(typeInfo);
if (debuggerDisplay != null)
{
debuggerDisplayName = debuggerDisplay.Name;
}
// Suppresses members if inlineMembers is true,
// does nothing otherwise.
bool suppressInlineMembers = false;
//
// TypeName(count) for ICollection implementers
// or
// TypeName([[DebuggerDisplay.Value]]) // Inline
// [[DebuggerDisplay.Value]] // Inline && !isRoot
// or
// [[ToString()]] if ToString overridden
// or
// TypeName
//
ICollection collection;
if ((collection = obj as ICollection) != null)
{
FormatCollectionHeader(result, collection);
}
else if (debuggerDisplay != null && !string.IsNullOrEmpty(debuggerDisplay.Value))
{
if (isRoot)
{
result.Append(_formatter.TypeNameFormatter.FormatTypeName(type, _typeNameOptions));
result.Append('(');
}
FormatWithEmbeddedExpressions(result, debuggerDisplay.Value, obj);
if (isRoot)
{
result.Append(')');
}
suppressInlineMembers = true;
}
else if (HasOverriddenToString(typeInfo))
//.........这里部分代码省略.........
示例9: FormatSequenceMembers
private void FormatSequenceMembers(Builder result, IEnumerable sequence, bool inline)
{
result.AppendGroupOpening();
int i = 0;
try
{
foreach (var item in sequence)
{
string _;
result.AppendCollectionItemSeparator(isFirst: i == 0, inline: inline);
FormatObjectRecursive(result, item, isRoot: false, debuggerDisplayName: out _);
i++;
}
}
catch (Exception e)
{
result.AppendCollectionItemSeparator(isFirst: i == 0, inline: inline);
FormatException(result, e);
result.Append(" ...");
}
result.AppendGroupClosing(inline);
}
示例10: CheckCompletePacket
private Pair<int, object[]> CheckCompletePacket()
{
Pair<int, object[]> nPair = new Pair<int, object[]>(0, null);
PacketType type = (PacketType) _Buffer[0];
if (_Buffer[0] >= PacketStructure.Data.Length && _Buffer[0] != 0xFF) {
Spacecraft.Log("Got invalid packet: " + _Buffer[0]);
return nPair;
}
string structure = (type == PacketType.Disconnect ? "bt" : PacketStructure.Data[_Buffer[0]]);
int bufPos = 0;
Builder<object> data = new Builder<object>();
byte[] bytes = new byte[8];
for (int i = 0; i < structure.Length; ++i) {
switch (structure[i]) {
case 'b': // sbyte(1)
if ((bufPos + 1) > _Buffer.Length) return nPair;
if (i == 0)
data.Append((byte) _Buffer[bufPos]);
else
data.Append((sbyte) _Buffer[bufPos]);
bufPos += 1;
break;
case 's': // short(2)
if ((bufPos + 2) > _Buffer.Length) return nPair;
data.Append((short) IPAddress.NetworkToHostOrder(BitConverter.ToInt16(_Buffer, bufPos)));
bufPos += 2;
break;
case 'f': // float(4)
if ((bufPos + 4) > _Buffer.Length) return nPair;
for (int j = 0; j < 4; ++j) {
bytes[j] = _Buffer[bufPos + 3 - j];
}
data.Append((float) BitConverter.ToSingle(bytes, 0));
bufPos += 4;
break;
case 'i': // int(4)
if ((bufPos + 4) > _Buffer.Length) return nPair;
data.Append((int) IPAddress.NetworkToHostOrder(BitConverter.ToInt32(_Buffer, bufPos)));
bufPos += 4;
break;
case 'd': // double(8)
if ((bufPos + 8) > _Buffer.Length) return nPair;
for (int j = 0; j < 8; ++j) {
bytes[j] = _Buffer[bufPos + 7 - j];
}
data.Append((double) BitConverter.ToDouble(bytes, 0));
bufPos += 8;
break;
case 'l': // long(8)
if ((bufPos + 8) > _Buffer.Length) return nPair;
data.Append((long) IPAddress.NetworkToHostOrder(BitConverter.ToInt64(_Buffer, bufPos)));
bufPos += 8;
break;
case 't': // string
if ((bufPos + 2) > _Buffer.Length) return nPair;
short len = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(_Buffer, bufPos));
if ((bufPos + 2 + len) > _Buffer.Length) return nPair;
data.Append((string) Encoding.UTF8.GetString(_Buffer, bufPos + 2, len));
bufPos += (2 + len);
break;
case 'I': // inventory entity
// short; if nonnegative, byte then short.
InventoryItem item;
if ((bufPos + 2) > _Buffer.Length) return nPair;
item.Type = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(_Buffer, bufPos));
if (item.Type >= 0) {
if ((bufPos + 3) > _Buffer.Length) return nPair;
item.Count = _Buffer[bufPos + 2];
item.Damage = (short) IPAddress.NetworkToHostOrder(BitConverter.ToInt16(_Buffer, bufPos + 3));
bufPos += 5;
} else {
item.Count = 0;
item.Damage = 0;
bufPos += 2;
}
data.Append(item);
break;
default:
throw new NotImplementedException("Unimplemented data type (recieve)");
}
}
return new Pair<int, object[]>(bufPos, data.ToArray());
}
示例11: FormatObjectRecursive
private Builder FormatObjectRecursive(Builder result, object obj, bool quoteStrings, MemberDisplayFormat memberFormat, out string name)
{
name = null;
string primitive = _language.FormatPrimitive(obj, quoteStrings, _options.IncludeCodePoints, _options.UseHexadecimalNumbers);
if (primitive != null)
{
result.Append(primitive);
return result;
}
object originalObj = obj;
Type originalType = originalObj.GetType();
//
// Override KeyValuePair<,>.ToString() to get better dictionary elements formatting:
//
// { { format(key), format(value) }, ... }
// instead of
// { [key.ToString(), value.ToString()], ... }
//
// This is more general than overriding Dictionary<,> debugger proxy attribute since it applies on all
// types that return an array of KeyValuePair in their DebuggerDisplay to display items.
//
if (originalType.IsGenericType && originalType.GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
{
if (memberFormat != MemberDisplayFormat.InlineValue)
{
result.Append(_language.FormatTypeName(originalType, _options));
result.Append(' ');
}
FormatKeyValuePair(result, originalObj);
return result;
}
if (originalType.IsArray)
{
if (!VisitedObjects.Add(originalObj))
{
result.AppendInfiniteRecursionMarker();
return result;
}
FormatArray(result, (Array)originalObj, inline: memberFormat != MemberDisplayFormat.List);
VisitedObjects.Remove(originalObj);
return result;
}
DebuggerDisplayAttribute debuggerDisplay = GetApplicableDebuggerDisplayAttribute(originalType);
if (debuggerDisplay != null)
{
name = debuggerDisplay.Name;
}
bool suppressMembers = false;
//
// TypeName(count) for ICollection implementers
// or
// TypeName([[DebuggerDisplay.Value]]) // Inline
// [[DebuggerDisplay.Value]] // InlineValue
// or
// [[ToString()]] if ToString overridden
// or
// TypeName
//
ICollection collection;
if ((collection = originalObj as ICollection) != null)
{
FormatCollectionHeader(result, collection);
}
else if (debuggerDisplay != null && !String.IsNullOrEmpty(debuggerDisplay.Value))
{
if (memberFormat != MemberDisplayFormat.InlineValue)
{
result.Append(_language.FormatTypeName(originalType, _options));
result.Append('(');
}
FormatWithEmbeddedExpressions(result, debuggerDisplay.Value, originalObj);
if (memberFormat != MemberDisplayFormat.InlineValue)
{
result.Append(')');
}
suppressMembers = true;
}
else if (HasOverriddenToString(originalType))
{
ObjectToString(result, originalObj);
suppressMembers = true;
}
else
{
result.Append(_language.FormatTypeName(originalType, _options));
}
if (memberFormat == MemberDisplayFormat.NoMembers)
//.........这里部分代码省略.........
示例12: FormatArray
private void FormatArray(Builder result, Array array, bool inline)
{
FormatCollectionHeader(result, array);
if (array.Rank > 1)
{
FormatMultidimensionalArray(result, array, inline);
}
else
{
result.Append(' ');
FormatSequence(result, (IEnumerable)array, inline);
}
}
示例13: ObjectToString
private void ObjectToString(Builder result, object obj)
{
try
{
string str = obj.ToString();
result.Append('[');
result.Append(str);
result.Append(']');
}
catch (Exception e)
{
FormatException(result, e);
}
}
示例14: Transmit
public void Transmit(PacketType type, params object[] args)
{
// Spacecraft.Log("Transmitting: " + type + "(" + (byte)type + ")");
string structure = (type == PacketType.Disconnect ? "bt" : PacketStructure.Data[(byte) type]);
Builder<Byte> packet = new Builder<Byte>();
packet.Append((byte) type);
byte[] bytes;
int current = 1;
try {
for (int i = 1; i < structure.Length; ++i) {
current = i;
switch (structure[i]) {
case 'b': // sbyte(1)
packet.Append((byte) (sbyte) args[i-1]);
break;
case 's': // short(2)
packet.Append(BitConverter.GetBytes(IPAddress.HostToNetworkOrder((short) args[i-1])));
break;
case 'f': // float(4)
bytes = BitConverter.GetBytes((float) args[i-1]);
for (int j = 3; j >= 0; --j) {
packet.Append(bytes[j]);
}
//packet.Append(bytes);
break;
case 'i': // int(4)
packet.Append(BitConverter.GetBytes(IPAddress.HostToNetworkOrder((int) args[i-1])));
break;
case 'd': // double(8)
bytes = BitConverter.GetBytes((double) args[i-1]);
for (int j = 7; j >= 0; --j) {
packet.Append(bytes[j]);
}
//packet.Append(bytes);
break;
case 'l': // long(8)
packet.Append(BitConverter.GetBytes(IPAddress.HostToNetworkOrder((long) args[i-1])));
break;
case 't': // string
bytes = Encoding.UTF8.GetBytes((string) args[i-1]);
packet.Append(BitConverter.GetBytes(IPAddress.HostToNetworkOrder((short) bytes.Length)));
packet.Append(bytes);
break;
case 'x': // byte array
packet.Append((byte[]) args[i-1]);
break;
case 'I': // inventory entity
// short; if nonnegative, byte then short.
InventoryItem item = (InventoryItem) args[i - 1];
packet.Append(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(item.Type)));
if (item.Type >= 0) {
packet.Append(item.Count);
packet.Append(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(item.Damage)));
}
break;
default:
throw new NotImplementedException("Unimplemented data type (transmit)");
}
}
}
catch (InvalidCastException) {
Spacecraft.Log("[Error] Transmitting " + type + ": expected '" + structure[current] +
"', got " + args[current - 1].GetType().ToString() + " for argument " + current + " (format: " + structure + ")");
throw;
}
lock (_TransmitQueue) {
_TransmitQueue.Enqueue(packet.ToArray());
}
}
示例15: IncomingData
private void IncomingData()
{
NetworkStream stream = _Client.GetStream();
Builder<byte> buffer = new Builder<byte>();
buffer.Append(_Buffer);
while (stream.DataAvailable) {
buffer.Append((byte) stream.ReadByte());
}
_Buffer = buffer.ToArray();
buffer = null;
while (_Buffer.Length > 0) {
Pair<int, object[]> pair = CheckCompletePacket();
int length = pair.First;
if (length > 0) {
//byte[] packet = new byte[length];
//Array.Copy(_Buffer, packet, length);
byte[] newBuffer = new byte[_Buffer.Length - length];
Array.Copy(_Buffer, length, newBuffer, 0, _Buffer.Length - length);
_Buffer = newBuffer;
ProcessPacket(pair.Second);
} else {
break;
}
}
}