构造 fieldbuilder 的代码行分配了一个可以存储为字符串、int、XYZ 等的类型。
开发人员文档不包括“BuiltInCategory”类型。我需要将其写入List<BuiltInCategory>
“projectinfo 对象”进行存储。我是否需要将其转换List<BuiltinCategory>
为字符串List<string>
进行存储,然后再转换回来进行检索?那会奏效吗?
public void StoreDataInProjectInfo(Document doc, Element projectInfoElement)
{
Schema schema = Schema.Lookup(SchemaGuid);
IList<BuiltInCategory> BuiltincatStringList = new List<BuiltInCategory>();
BuiltincatStringList.Add("1");
BuiltincatStringList.Add("2");
using (Transaction transEstorage = new Transaction(doc))
{
transEstorage.Start("add estorage list");
if (null == schema)
{
SchemaBuilder sb = new SchemaBuilder(new Guid("AF5E4C3E-C2E2-493B-8236-BA0F5E323887"));
//public accesibility
sb.SetReadAccessLevel(AccessLevel.Public);
sb.SetWriteAccessLevel(AccessLevel.Public);
这是需要类型的字段构建器列表,代码在执行时失败并报告不正确的“类型”。
//Storage Filled for Cat List
***FieldBuilder fb = sb.AddArrayField("UserCategoryList", typeof(BuiltInCategory))***;
fb.SetDocumentation("A Set Of Categories to be worksetted");
//set schema name and register
sb.SetSchemaName("UserCategoryList");
schema = sb.Finish();
}
// Create an entity (object) for this schema (class)
Entity entity = new Entity(schema);
// Get the field from the schema
Field userWSCategoryList = schema.GetField("UserCategoryList");
entity.Set<IList<BuiltInCategory>>(userWSCategoryList, BuiltincatStringList);
//Entity storage on Element
projectInfoElement.SetEntity(entity);
// Read back the data from the wall
Entity retrievedEntity = projectInfoElement.GetEntity(schema);
IList<BuiltInCategory> retrievedData = retrievedEntity.Get<List<BuiltInCategory>>(schema.GetField("UserCategoryList"));
transEstorage.Commit();
}
}