UpdateProperties
Metadata.UpdateProperties method
更新满足指定谓词的已知元数据属性。 该操作是递归的,因此它也会影响所有嵌套包。
public int UpdateProperties(Func<MetadataProperty, bool> predicate, PropertyValue value)
范围 | 类型 | 描述 |
---|---|---|
predicate | Func`2 | 用于测试条件的每个元数据属性的函数。 |
value | PropertyValue | 筛选属性的新值。 |
返回值
受影响的属性的数量。
评论
请注意,GroupDocs.Metadata 隐式检查每个筛选属性的类型。 无法使用类型不当的值更新属性。
了解更多
- 更多示例演示此方法的用法: 更新元数据
例子
using (Metadata metadata = new Metadata(Constants.InputXlsx))
{
if (metadata.FileFormat != FileFormat.Unknown && !metadata.GetDocumentInfo().IsEncrypted)
{
// 如果现有值超过 3 天,则更新文件创建日期/时间
var affected = metadata.UpdateProperties(p => p.Tags.Contains(Tags.Time.Created) &&
p.Value.Type == MetadataPropertyType.DateTime &&
p.Value.ToStruct<DateTime>() < threeDaysAgo, new PropertyValue(today));
Console.WriteLine("Affected properties: {0}", affected);
metadata.Save(Constants.OutputXlsx);
}
}
也可以看看
- delegate Func<T,TResult>
- class MetadataProperty
- class PropertyValue
- class Metadata
- 命名空间 GroupDocs.Metadata
- 部件 GroupDocs.Metadata