public static void ReadWriteAccess() { Point3d newPoint = new Point3d(-19.121m, 0.2m, 199.96m); using Rwlkres lck = TheRwVault.Lock(); Console.WriteLine("The value is: [" + lck.Value + "]."); lck.Value.UpdatePoint(in newPoint); Console.WriteLine("The value is: [" + lck.Value + "]."); }
public static void ReadWriteAccess() { Point3d newPoint = new Point3d(-19.121m, 0.2m, 199.96m); Rwlkres gonnaCopyMe; //FLAW: SHOULD NOT BE ABLE TO DO THIS .. .actually may not be a problem //can't call dispose on copy and it has scope lesser in extent to the scope of lck. { using Rwlkres lck = TheRwVault.Lock(); gonnaCopyMe = SneakyCopy(in lck); }
public static void ReadOnlyAccess() { using var lck = TheRwVault.RoLock(); Console.WriteLine("Here is the value: [" + lck.Value + "]."); Console.WriteLine("The value's name is: [" + lck.Value.Name + "]."); //Note that if you attempt to mutate value returned by readonly reference, it will have no effect //and might trigger a defensive copy! //FLAW# shouldnt be able to do this! lck.Value.UpdatePoint(new Point3d(1, 2, 3)); Console.WriteLine("X: [" + lck.Value.X + "], Y: [" + lck.Value.Y + "], Z: [" + lck.Value.Z + "]."); Console.WriteLine("Value: [" + lck.Value + "]."); }
public static void UpgradableTest() { string final; { using var upgrRoLock = TheRwVault.UpgradableRoLock(); Console.WriteLine("Upgradable demo ... Current value: [" + (upgrRoLock.Value.ToString() ?? string.Empty) + "]."); if (upgrRoLock.Value.Id != default) { using var rwLck = upgrRoLock.Lock(); rwLck.Value.X = 15.111m; } final = upgrRoLock.Value.ToString(); } Console.WriteLine("Final result of upgradable demo: [" + final + "]."); }
public static void ReadWriteAccess() { Point3d newPoint = new Point3d(-19.121m, 0.2m, 199.96m); //FLAW: SHOULD NOT BE ABLE TO DO THIS .. .actually may not be a problem //can't call dispose on copy and it has scope lesser in extent to the scope of lck. { using Rwlkres lck = TheRwVault.Lock(); var copy = lck; //Figure out why this isn't being flagged as an error using Rwlkres copy2 = copy; using (var cop3 = copy2) { Console.WriteLine(cop3.Value.ToString()); Console.WriteLine(@"The value is: [" + lck.Value + @"]."); lck.Value.UpdatePoint(in newPoint); Console.WriteLine(@"The value is: [" + lck.Value + @"]."); } } //static void DoStuff(Rwlkres foo) //{ // Console.WriteLine(foo.Value.ToString()); //} }