public void ReadOnly() { TextInfo enus = new CultureInfo("en-US").TextInfo; Assert.IsFalse(enus.IsReadOnly, "IsReadOnly-1"); TextInfo ro = TextInfo.ReadOnly(enus); Assert.IsTrue(ro.IsReadOnly, "IsReadOnly-2"); CompareProperties(enus, ro, false); }
public void Clone_ReadOnly() { TextInfo enus = TextInfo.ReadOnly(new CultureInfo("en-US").TextInfo); Assert.IsTrue(enus.IsReadOnly, "IsReadOnly-1"); TextInfo clone = (TextInfo)enus.Clone(); Assert.IsFalse(clone.IsReadOnly, "IsReadOnly-2"); CompareProperties(enus, clone, false); // cloned item is *NOT* read-only }
public void ReadOnlyTest() { TextInfo ti = CultureInfo.GetCultureInfo("en-US").TextInfo; Assert.True(ti.IsReadOnly, "IsReadOnly should be true with cached TextInfo object"); ti = (TextInfo)ti.Clone(); Assert.False(ti.IsReadOnly, "IsReadOnly should be false with cloned TextInfo object"); ti = TextInfo.ReadOnly(ti); Assert.True(ti.IsReadOnly, "IsReadOnly should be true with created read-nly TextInfo object"); }
public static void Main() { // Get the TextInfo of a predefined culture that ships with // the .NET Framework. CultureInfo ci = new CultureInfo("en-US"); TextInfo ti1 = ci.TextInfo; // Display whether the TextInfo is read-only or not. DisplayReadOnly("1) The original TextInfo object", ti1); Console.WriteLine(); // Create a clone of the original TextInfo and cast the clone to a TextInfo type. Console.WriteLine("2a) Create a clone of the original TextInfo object..."); TextInfo ti2 = (TextInfo)ti1.Clone(); // Display whether the clone is read-only. DisplayReadOnly("2b) The TextInfo clone", ti2); // Set the ListSeparator property on the TextInfo clone. Console.WriteLine("2c) The original value of the clone's ListSeparator " + "property is \"{0}\".", ti2.ListSeparator); ti2.ListSeparator = "/"; Console.WriteLine("2d) The new value of the clone's ListSeparator " + "property is \"{0}\".\n", ti2.ListSeparator); // Create a read-only clone of the original TextInfo. Console.WriteLine("3a) Create a read-only clone of the original TextInfo object..."); TextInfo ti3 = TextInfo.ReadOnly(ti1); // Display whether the read-only clone is actually read-only. DisplayReadOnly("3b) The TextInfo clone", ti3); // Try to set the ListSeparator property of a read-only TextInfo object. Use the // IsReadOnly property again to determine whether to attempt the set operation. You // could use a try-catch block instead and catch an InvalidOperationException when // the set operation fails, but that programming technique is inefficient. Console.WriteLine("3c) Try to set the read-only clone's LineSeparator " + "property."); if (ti3.IsReadOnly == true) { Console.WriteLine("3d) The set operation is invalid."); } else { // This clause is not executed. ti3.ListSeparator = "/"; Console.WriteLine("3d) The new value of the clone's ListSeparator " + "property is \"{0}\".\n", ti2.ListSeparator); } }