示例#1
0
        public void CreateIndex(string name, IIndex index)
        {
            CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(name), name);
            CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(index), index);

            ThreadSafety.DoLocked(() =>
            {
                CheckOpen();
                var concreteIndex = Misc.TryCast <IIndex, QueryIndex>(index);
                var jsonObj       = concreteIndex.ToJSON();
                var json          = JsonConvert.SerializeObject(jsonObj);
                LiteCoreBridge.Check(err =>
                {
                    var internalOpts = concreteIndex.Options;

                    // For some reason a "using" statement here causes a compiler error
                    try {
                        return(Native.c4db_createIndex(c4db, name, json, concreteIndex.IndexType, &internalOpts, err));
                    } finally {
                        internalOpts.Dispose();
                    }
                });
            });
        }