public object PreSerialize(TagElementAttribute info, object obj) { if (obj == null) return null; // When serializing a resource address, just add a fixup for it and serialize a null pointer if (obj is ResourceAddress) { _fixups.Add(MakeDefinitionFixup((ResourceAddress)obj)); return 0U; } var type = obj.GetType(); if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(D3DPointer<>)) { // Add a D3D fixup for D3DPointers based on the type of object being pointed to var d3dType = GetD3DObjectType(type.GenericTypeArguments[0]); _d3dFixups.Add(MakeD3DFixup((uint)Stream.Position, d3dType)); } return obj; }
public object PreSerialize(TagElementAttribute info, object obj) { if (obj == null) return null; // Get the object type and make sure it's supported var type = obj.GetType(); if (type == typeof(ResourceDataReference) || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(D3DPointer<>))) throw new InvalidOperationException(type + " cannot be serialized as tag data"); if (type == typeof(HaloTag)) { // Object is a tag reference - add it as a dependency var referencedTag = obj as HaloTag; if (referencedTag != null) _context._dependencies.Add(referencedTag.Index); } return obj; }