protected virtual TokenObjectCategory BackLogSerialization(object obj)
        {
            var objType = obj.GetType();

            if (TryContractSaving(objType, obj))
            {
                return(TokenObjectCategory.Contract);
            }

            switch (obj)
            {
            case ISerializable serializable:
                var context = new StreamingContext(StreamingContextStates.Other);
                var info    = new SerializationInfo(objType, new FormatterConverter());
                serializable.GetObjectData(info, context);
                RegisterSerialization(obj, _typeMap.GetId(objType), info);

                return(TokenObjectCategory.Serializable);

            // cannot use blitting on enumerables as there may be clobbering
            // developer will just need to implement iserializable for any special cases
            case IEnumerable enumerable:
                RegisterEnumeratableInitialization(enumerable);
                return(TokenObjectCategory.Enumerable);

            default:
                if (objType.GetCustomAttributes <SerializableAttribute>() == null)
                {
                    throw new InvalidOperationException();
                }

                if (!_blitMap.TryGetId(objType, out var fieldMap))
                {
                    var fieldData = new List <FieldInfo>();
                    foreach (var field in objType.GetFields(
                                 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                    {
                        if (field.GetCustomAttribute <NonSerializedAttribute>() != null)
                        {
                            continue;
                        }

                        fieldData.Add(field);
                    }

                    _blitMap.Map(fieldMap = fieldData.ToArray(), objType);
                }

                RegisterBlit(obj, fieldMap);

                return(TokenObjectCategory.FieldSettable);
            }
        }
        /// <summary>
        ///     Register the data, and related types associated with the
        ///     objType passed into this function
        /// </summary>
        /// <param name="objType"></param>
        public void RegisterType(Type objType)
        {
            if (_typeMap.TryGetId(objType, out var igl))
            {
                return;
            }

            var name = objType.AssemblyQualifiedName;

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            igl = new IglRegisterType(_idCounter++, objType.AssemblyQualifiedName);
            _typeMap.Map(igl, objType);

            _script.TypeDef.AddLast(igl);
            objType.ResolveRelatedTypes(_knownTypes);
            foreach (var type in _knownTypes)
            {
                RegisterType(type);
            }
        }