Tpm2Lib.TpmStructPrinter.Print C# (CSharp) Method

Print() private method

private Print ( string name, string type, Object o ) : void
name string
type string
o Object
return void
        internal void Print(string name, string type, Object o)
        {
            if (o == null)
            {
                // E.g. inPrivate null SomeStruct
                AddLine(B, "{0}@{1}#{2}", name, "null", type);
                return;
            }

            // ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
            if (o is TpmStructureBase)
            {
                string ss = type;
                if (ss.StartsWith("I"))
                {
                    // If the member is an interface, also print the type of entity that is being dumped
                    string intType = o.GetType().ToString();
                    intType = intType.Substring(intType.LastIndexOf('.') + 1);

                    type = intType;
                }
                // Print the name and type but not the contents (that is printed recursibley below)
                AddLine(B, "{0}@-#{1}", name, type);
                // Recurse
                Indent++;
                ((TpmStructureBase)o).ToStringInternal(this);
                Indent--;
                return;
            }

            // ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
            if (o is Enum)
            {
                var en = (Enum)o;
                string s = Enum.Format(en.GetType(), en, "g");
                s = s.Replace(',', '|');
                // name   Elem1|Elem2
                AddLine(B, "{0}@{1}#{2}", name, s, type);
                return;
            }

            if (o is ValueType)
            {
                //checked that this actually works with Int64, etc.
                UInt64 valIs = Convert.ToUInt64(o);
                var signedVal = (Int64)valIs;

                string hexString = Convert.ToString(signedVal, 16);

                // ReSharper disable once SpecifyACultureInStringConversionExplicitly
                AddLine(B, "{0}@{1} (0x{2})#{3}", name, valIs.ToString(), hexString, type);
                return;
            }

            // ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
            if (o is Array)
            {
                var a = (Array)o;
                Type elementType = o.GetType().GetElementType();
                if (elementType == typeof (byte))
                {
                    // Byte arrays as special - 
                    string hexString = "0x" + Globs.HexFromByteArrayCompactNoSpaces((byte[])a);
                    string typeString = String.Format("byte[{0}]", a.Length);
                    AddLine(B, "{0}@{1}#{2}", name, hexString, typeString);
                    return;
                }
                // ReSharper disable once RedundantIfElseBlock
                else
                {
                    B.AppendFormat("{0}Array - {1}[{2}]\n", Spaces(), type, a.Length);
                    Indent++;
                    for (int j = 0; j < a.Length; j++)
                    {
                        Object elem = a.GetValue(j);
                        // ReSharper disable once SpecifyACultureInStringConversionExplicitly
                        Print(elem.GetType().ToString(), j.ToString(), elem);
                    }
                    Indent--;
                    return;
                }
            }
            Globs.Throw<NotImplementedException>("Print: Unknown type " + o.GetType());
        }

Usage Example

コード例 #1
0
ファイル: TpmBaseClasses.cs プロジェクト: siyingpoof/TSS.MSR
        virtual internal void ToStringInternal(TpmStructPrinter p)
        {
            bool enabled = dbg.Enabled;

            dbg.Enabled = false;
            var members = GetFieldsToMarshal();

            dbg.Enabled = enabled;
            foreach (var mem in members)
            {
                MemberInfo memInfo = mem;
                object     memVal  = Globs.GetMember(memInfo, this);
                Type       memType = Globs.GetMemberType(memInfo);
                p.Print(memInfo.Name, Globs.ToCSharpStyle(memType.Name), memVal);
            }
        }
All Usage Examples Of Tpm2Lib.TpmStructPrinter::Print