public void UnicodePropTest() { // Set class first, or it will throw an exception. const int hvo = 1; var clidAnal = SilDataAccess.MetaDataCache.GetClassId("ClassE"); SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, clidAnal); // Set its 'UnicodeProp4' property, using the 'BSTR' method. var tag = SilDataAccess.MetaDataCache.GetFieldId("ClassE", "UnicodeProp4", false); const string ec = "ZPI"; SilDataAccess.set_UnicodeProp(hvo, tag, ec); var ec2 = SilDataAccess.get_UnicodeProp(hvo, tag); Assert.AreEqual(ec, ec2, "Wrong Unicode string in cache."); // Set its 'UnicodeProp4' property, using non-bstr method. const string ecNew = "ZPR"; SilDataAccess.SetUnicode(hvo, tag, ecNew, ecNew.Length); int len; SilDataAccess.UnicodePropRgch(hvo, tag, null, 0, out len); Assert.AreEqual(ecNew.Length, len); using (var arrayPtr = MarshalEx.StringToNative(len + 1, true)) { int cch; SilDataAccess.UnicodePropRgch(hvo, tag, arrayPtr, len + 1, out cch); var ecNew2 = MarshalEx.NativeToString(arrayPtr, cch, true); Assert.AreEqual(ecNew, ecNew2); Assert.AreEqual(ecNew2.Length, cch); Assert.IsTrue(SilDataAccess.IsDirty()); } }