Opening objects with a renamed namespace/assembly in db4o

*爱你&永不变心* 提交于 2019-12-24 00:15:36

问题


I have a set of objects in db4o format in a .dat file. The objects in that file are OldNamespace.MyObject, OldAssemblyName.

The problem is I've since renamed the namespace and assembly to something more permanent. Short of renaming the assembly and namespace (which is what I'm doing), is there a way of opening the objects into the new assembly/namespace names?

Or am I stuck forever with "MyTest3" for the assembly name and namespace?!


回答1:


I found the answer faster than I thought I would, in the wiki documentation.

This is the temporary way of doing it:

TypeAlias alias = new TypeAlias("OldNameSpace.OldTypeName, OldAssembly", "NewNameSpace.NewTypeName, NewAssembly");
Db4oFactory.Configure().AddAlias(alias);
IObjectContainer db = Db4oFactory.OpenFile(dbfilename);

The more permanent way (it's messy code but it's for a temp fix):

using (IObjectContainer db = Db4oFactory.OpenFile(dbfilename))
{
    var n = db.Ext().StoredClasses();
    foreach (var x in n)
    {
        System.Diagnostics.Debug.WriteLine(x.GetName());
    }
    var c1 = db.Ext().StoredClass("OldNameSpace.OldType, OldAssembly");//
    if (c1 != null)
        c1.Rename("NewNameSpace.OldType, NewAssembly");

    var c2 = db.Ext().StoredClass("System.Collections.Generic.List`1[[OldNameSpace.OldType, OldAssembly]], mscorlib");
    if (c2 != null)
        c2.Rename("System.Collections.Generic.List`1[[NewNameSpace.OldType, NewAssembly]], mscorlib");
}

As you can see 'ILists' need updating. Make sure when you save you do it to a new file, otherwise you will get both types in the output file.



来源:https://stackoverflow.com/questions/1137955/opening-objects-with-a-renamed-namespace-assembly-in-db4o

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!