本文整理汇总了C#中IFileInfo.GetExtendedAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# IFileInfo.GetExtendedAttribute方法的具体用法?C# IFileInfo.GetExtendedAttribute怎么用?C# IFileInfo.GetExtendedAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileInfo
的用法示例。
在下文中一共展示了IFileInfo.GetExtendedAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Replace
/// <summary>
/// Replaces the contents of a specified destinationFile with the file described by the current IFileInfo
/// object, deleting the original file, and creating a backup of the replaced file.
/// Also specifies whether to ignore merge errors.
/// </summary>
/// <param name="destinationFile">Destination file.</param>
/// <param name="destinationBackupFileName">Destination backup file name.</param>
/// <param name="ignoreMetadataErrors"><c>true</c> to ignore merge errors (such as attributes and ACLs) from the replaced file to the replacement file; otherwise <c>false</c>.</param>
/// <returns>A IFileInfo object that encapsulates information about the file described by the destFileName parameter.</returns>
public IFileInfo Replace(IFileInfo destinationFile, IFileInfo destinationBackupFileName, bool ignoreMetadataErrors) {
#if __MonoCS__
var reader = new ExtendedAttributeReaderUnix();
var oldSourceEAs = new Dictionary<string, string>();
var oldTargetEAs = new Dictionary<string, string>();
if (reader.IsFeatureAvailable(this.FullName)) {
foreach (var key in reader.ListAttributeKeys(this.FullName)) {
oldSourceEAs.Add(key, this.GetExtendedAttribute(key));
}
foreach (var key in reader.ListAttributeKeys(destinationFile.FullName)) {
oldTargetEAs.Add(key, destinationFile.GetExtendedAttribute(key));
}
}
#else
try {
#endif
var result = new FileInfoWrapper(this.original.Replace(destinationFile.FullName, destinationBackupFileName.FullName, ignoreMetadataErrors));
#if __MonoCS__
foreach (var entry in oldSourceEAs) {
result.SetExtendedAttribute(entry.Key, entry.Value, true);
}
foreach (var entry in oldTargetEAs) {
destinationBackupFileName.SetExtendedAttribute(entry.Key, entry.Value, true);
}
return result;
#else
return result;
} catch (IOException ex) {
int error = Marshal.GetHRForException(ex) & 0xffff;
if (error == 1176) {
string newName = destinationFile.FullName + Guid.NewGuid().ToString() + ".sync";
IFileInfo newResult = null;
try {
var copy = this.original.CopyTo(newName, true);
newResult = new FileInfoWrapper(copy.Replace(destinationFile.FullName, destinationBackupFileName.FullName, ignoreMetadataErrors));
this.Delete();
return newResult;
} catch (Exception) {
} finally {
if (File.Exists(newName)) {
File.Delete(newName);
}
}
throw;
} else {
throw;
}
}
#endif
}