private static MValue Get([NotNull] MArray array, int index, IThreadSafety threadSafety = null) { return((threadSafety ?? NullThreadSafety.Instance).DoLocked(() => { var val = array.Get(index); if (val.IsEmpty) { throw new IndexOutOfRangeException(); } return val; })); }
public unsafe void TestReadOnlyArray() { var now = DateTimeOffset.UtcNow; var nestedArray = new[] { 1L, 2L, 3L }; var nestedDict = new Dictionary <string, object> { ["foo"] = "bar" }; var masterData = new object[] { 1, "str", nestedArray, now, nestedDict }; var flData = new FLSliceResult(); Db.InBatch(() => { flData = masterData.FLEncode(); }); try { var context = new DocContext(Db, null); using (var mRoot = new MRoot(context)) { mRoot.Context.Should().BeSameAs(context); var flValue = NativeRaw.FLValue_FromData((FLSlice)flData, FLTrust.Trusted); var mArr = new MArray(new MValue(flValue), mRoot); var deserializedArray = new ArrayObject(mArr, false); deserializedArray.GetArray(2).Should().Equal(1L, 2L, 3L); deserializedArray.GetArray(3).Should().BeNull(); deserializedArray.GetBlob(1).Should().BeNull(); deserializedArray.GetDate(3).Should().Be(now); deserializedArray.GetDate(4).Should().Be(DateTimeOffset.MinValue); deserializedArray[1].ToString().Should().Be("str"); deserializedArray.GetString(2).Should().BeNull(); deserializedArray.GetDictionary(4).Should().BeEquivalentTo(nestedDict); deserializedArray[0].Dictionary.Should().BeNull(); var list = deserializedArray.ToList(); list[2].Should().BeAssignableTo <IList <object> >(); list[4].Should().BeAssignableTo <IDictionary <string, object> >(); var mVal = new MValue(); mVal.Dispose(); } } finally { Native.FLSliceResult_Release(flData); } var mroot = new MRoot(); }
public unsafe void TestSharedstrings() { var now = DateTimeOffset.UtcNow; var nestedArray = new[] { 1L, 2L, 3L }; var nestedDict = new Dictionary <string, object> { ["foo"] = "bar" }; var masterData = new object[] { 1, "str", nestedArray, now, nestedDict }; var flData = new FLSliceResult(); Db.InBatch(() => { flData = masterData.FLEncode(); }); try { var context = new DocContext(Db, null); using (var mRoot = new MRoot(context)) { var flValue = NativeRaw.FLValue_FromTrustedData((FLSlice)flData); var mArr = new MArray(new MValue(flValue), mRoot); var sharedstrings = context.SharedStrings; FLEncoder *fLEncoder = Db.SharedEncoder; mRoot.FLEncode(fLEncoder); mRoot.Encode(); var isReadonly = mArr.IsReadOnly; isReadonly.Should().BeFalse(); #if !WINDOWS_UWP Assert.Throws <NotImplementedException>(() => mArr.IndexOf(now)); Assert.Throws <NotImplementedException>(() => mArr.Contains(now)); Assert.Throws <NotImplementedException>(() => mArr.Remove(now)); Assert.Throws <NotImplementedException>(() => mArr.CopyTo(new object[] { }, 12)); #endif var flDict = Native.FLValue_AsDict(flValue); var sharedStringCache = new SharedStringCache(); var sharedStringCache1 = new SharedStringCache(sharedStringCache); sharedStringCache1 = new SharedStringCache(sharedStringCache, flDict); var i = default(FLDictIterator); var iterKey = sharedStringCache1.GetDictIterKey(&i); sharedStringCache1.UseDocumentRoot(flDict); } } finally { Native.FLSliceResult_Free(flData); } }
static void Main(string[] args) { int size; int elements; int index; MArray mArray = new MArray(); Console.WriteLine("Введите кол-во элементов:"); int.TryParse(Console.ReadLine(), out size); mArray.Array = new int[size]; Console.WriteLine("Введите элементы массива"); for (int i = 0; i < size; i++) { int.TryParse(Console.ReadLine(), out elements); mArray[i] = elements; } Console.WriteLine("Элементы"); for (int i = 0; i < size; i++) { Console.Write(mArray[i] + " "); } Console.WriteLine("\nВведите индекс"); int.TryParse(Console.ReadLine(), out index); Console.WriteLine(mArray.ReturnToIndex(index)); Console.ReadLine(); }
public Enumerator(MArray parent) { _parent = parent; }
internal ArrayObject([NotNull] MArray array, bool isMutable) { _array.InitAsCopyOf(array, isMutable); _threadSafety = SetupThreadSafety(); }
private static T GetObject <T>([NotNull] MArray array, int index, IThreadSafety threadSafety = null) where T : class => GetObject(array, index, threadSafety) as T;
private static object GetObject([NotNull] MArray array, int index, IThreadSafety threadSafety = null) => Get(array, index, threadSafety).AsObject(array);
internal MutableArrayObject(MArray array, bool isMutable) { _array.InitAsCopyOf(array, isMutable); }