public static void SerializeDynamic(BitStream stream, Type baseType, ref Type obj)
 {
     if (stream.Reading)
     {
         var typeId = new MyRuntimeObjectBuilderId(stream.ReadUInt16());
         obj = (MyObjectBuilderType)typeId;
     }
     else
     {
         var typeId = (MyRuntimeObjectBuilderId)(MyObjectBuilderType)obj;
         stream.WriteUInt16(typeId.Value);
     }
 }
        internal static void RegisterFromAssembly(Assembly assembly, bool registerLegacyNames = false)
        {
            if (assembly == null)
            {
                return;
            }

            var baseType = typeof(MyObjectBuilder_Base);

#if XB1 // XB1_ALLINONEASSEMBLY
            System.Diagnostics.Debug.Assert(m_registered == false);
            if (m_registered == true)
            {
                return;
            }
            m_registered = true;
            var types = MyAssembly.GetTypes();
#else // !XB1
            var types = assembly.GetTypes();
#endif // !XB1
            Array.Sort(types, FullyQualifiedNameComparer.Default);
            foreach (var type in types)
            {
                if (baseType.IsAssignableFrom(type) && !m_typeByName.ContainsKey(type.Name))
                {
                    var myType = new MyObjectBuilderType(type);
                    var myId   = new MyRuntimeObjectBuilderId(++m_idCounter);

                    m_typeById.Add(myId, myType);
                    m_idByType.Add(myType, myId);
                    m_typeByName.Add(type.Name, myType);

                    const string PREFIX = "MyObjectBuilder_";
                    if (registerLegacyNames && type.Name.StartsWith(PREFIX))
                    {
                        RegisterLegacyName(myType, type.Name.Substring(PREFIX.Length));
                    }

                    var attrs = type.GetCustomAttributes(typeof(MyObjectBuilderDefinitionAttribute), true);
                    if (attrs.Length > 0)
                    {
                        MyObjectBuilderDefinitionAttribute att = (MyObjectBuilderDefinitionAttribute)attrs[0];
                        if (!string.IsNullOrEmpty(att.LegacyName))
                        {
                            RegisterLegacyName(myType, att.LegacyName);
                        }
                    }
                }
            }
        }