Alexandria.Engines.GoldBox.Resources.ScriptOperand.ToRichText C# (CSharp) Method

ToRichText() public method

public ToRichText ( RichTextBuilder builder ) : void
builder RichTextBuilder
return void
        public void ToRichText(RichTextBuilder builder)
        {
            Color foregroundColor = builder.ForegroundColor;

            try {
                if (!IsValid)
                    builder.ForegroundColor = Color.Red;

                switch (Type) {
                    default:
                        builder.Append(this);
                        break;
                }
            } finally {
                builder.ForegroundColor = foregroundColor;
            }
        }

Usage Example

Example #1
0
        public virtual void ToRichText(RichTextBuilder builder)
        {
            string format;

            if (OpcodeFormats.TryGetValue(Opcode, out format))
            {
                for (int index = 0; index < format.Length; index++)
                {
                    if (format[index] == '{')
                    {
                        if (format[index + 1] == '{')
                        {
                            index++;
                            builder.Append('{');
                        }
                        else
                        {
                            int end;

                            for (end = ++index; format[end] != '}'; end++)
                            {
                                ;
                            }
                            int           operandIndex = int.Parse(format.Substring(index, end - index));
                            ScriptOperand operand      = GetOperand(operandIndex);
                            operand.ToRichText(builder);
                            index = end;
                        }
                    }
                    else
                    {
                        builder.Append(format[index]);
                    }
                }
            }
            else
            {
                if (IsOpcodeDefined)
                {
                    builder.Append(Opcode.ToString());
                }
                else
                {
                    builder.ForegroundColor = Color.Red;
                    builder.AppendFormat("{0:X2}", (int)Opcode);
                    builder.ForegroundColor = Color.Black;
                }

                foreach (ScriptOperand operand in Operands)
                {
                    builder.Append(" ");
                    operand.ToRichText(builder);
                }
            }
        }