TryLoad
Loads all the properties of a document, already deseriazed into objects.
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEditor.Search
- Assembly: UnityEditor
TryLoad(ulong, IEnumerable<Object>)
Loads all the properties of a document, already deseriazed into objects.
bool TryLoad(ulong documentKey, out IEnumerable<object> data)
Parameters
Returns
Type | Description |
|---|---|
| bool | True if the record is found and is valid, false otherwise. |
Remarks
// Load all values not associated with a document, already deserialized.using (var view = propertyDatabase.GetView()){ var nullDocumentKey = view.CreateDocumentKey(null); if (!view.TryLoad(nullDocumentKey, out IEnumerable<object> noDocumentProperties)) Assert.Fail("Failed to load properties with no documents."); Assert.IsNotEmpty(noDocumentProperties); Assert.AreEqual("myDocs_", noDocumentProperties.First());}
Additional Resources: IPropertyDatabaseView.CreateDocumentKey.
TryLoad(ulong, IEnumerable<IPropertyDatabaseRecord>)
Loads all the properties of a document, still contained within records.
bool TryLoad(ulong documentKey, out IEnumerable<IPropertyDatabaseRecord> records)
Parameters
A document key.
The document property records.
Returns
Type | Description |
|---|---|
| bool | True if the record is found and is valid, false otherwise. |
Remarks
This method doesn't deserialize the values. You have to deserialize them yourself by calling IPropertyDatabaseView.GetObjectFromRecordValue.
// Load all values associated with a document, not deserialized.using (var view = propertyDatabase.GetView()){ var myAssetDocumentKey = view.CreateDocumentKey("path/to/my/asset"); if (!view.TryLoad(myAssetDocumentKey, out IEnumerable<IPropertyDatabaseRecord> myDocumentRecords)) Assert.Fail("Failed to load records for my asset document."); var deserializedValues = new Dictionary<PropertyDatabaseRecordKey, object>(); foreach (var myDocumentRecord in myDocumentRecords) { var value = view.GetValueFromRecord<object>(myDocumentRecord.value); deserializedValues.Add(myDocumentRecord.key, value); } Assert.AreEqual(5, deserializedValues.Count);}
Additional Resources: IPropertyDatabaseView.CreateDocumentKey.