in TPM Parser/Tpm2Lib/Marshaller.cs [171:260]
public void PutInternal(Object o, string name)
{
bool measuringElement = false;
if (QualifiedName != null)
{
// We are searching for the start and length of a fragment
if (name == QualifiedName[QualNamePos])
{
ElementStart = (int)GetPutPos();
measuringElement = true;
}
}
if (o == null)
{
}
// ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
else if (o is TpmStructureBase)
{
((TpmStructureBase)o).ToNet(this);
}
else if (o is Enum)
{
Type underlyingType = Enum.GetUnderlyingType(o.GetType());
if (underlyingType == typeof(byte))
{
// ReSharper disable once SuggestUseVarKeywordEvident
// ReSharper disable once PossibleInvalidCastException
var x = (byte)o;
ToNetValueType(x, name);
}
else if (underlyingType == typeof(ushort))
{
// ReSharper disable once SuggestUseVarKeywordEvident
// ReSharper disable once PossibleInvalidCastException
var x = (ushort)o;
ToNetValueType(x, name);
}
else if (underlyingType == typeof(uint))
{
// ReSharper disable once SuggestUseVarKeywordEvident
// ReSharper disable once PossibleInvalidCastException
var x = (uint)o;
ToNetValueType(x, name);
}
else if (underlyingType == typeof(sbyte))
{
// ReSharper disable once SuggestUseVarKeywordEvident
// ReSharper disable once PossibleInvalidCastException
var x = (byte)((sbyte)o);
ToNetValueType(x, name);
}
else if (underlyingType == typeof(ulong))
{
// ReSharper disable once SuggestUseVarKeywordEvident
// ReSharper disable once PossibleInvalidCastException
var x = (ulong)o;
ToNetValueType(x, name);
}
else
{
Globs.Throw<ArgumentException>("PutInternal: Unsupported enum type");
ToNetValueType(0, name);
}
}
else if (o is ValueType)
{
ToNetValueType(o, name);
}
// ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
else if (o is Array)
{
var a = (Array)o;
int count = 0;
foreach (Object elem in a)
{
Put(elem, name + count);
count++;
}
}
else
{
Globs.Throw<NotImplementedException>("PutInternal: Unsupported object type");
}
if (measuringElement)
{
ElementEnd = (int)GetPutPos();
}
}