public Type GetActualType(MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType)
    {
        if (nominalType != typeof(MyAbstractClass))
        {
            throw new Exception("Cannot use FooDiscriminator for type " + nominalType);
        }
        var ret      = nominalType;
        var bookmark = bsonReader.GetBookmark();

        bsonReader.ReadStartDocument();
        if (bsonReader.FindElement(ElementName))
        {
            var value = bsonReader.ReadString();
            ret = Type.GetType(value);
            if (ret == null)
            {
                throw new Exception("Could not find type " + value);
            }
            if (!ret.IsSubclassOf(typeof(MyAbstractClass)))
            {
                throw new Exception("Database type does not inherit from MyAbstractClass.");
            }
        }
        bsonReader.ReturnToBookmark(bookmark);
        return(ret);
    }
Пример #2
0
        static int _m_GetBookmark(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                MongoDB.Bson.IO.BsonReader gen_to_be_invoked = (MongoDB.Bson.IO.BsonReader)translator.FastGetCSObj(L, 1);



                {
                    MongoDB.Bson.IO.BsonReaderBookmark gen_ret = gen_to_be_invoked.GetBookmark(  );
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }