本文整理汇总了C#中ImmutableDictionary.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableDictionary.ToDictionary方法的具体用法?C# ImmutableDictionary.ToDictionary怎么用?C# ImmutableDictionary.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImmutableDictionary
的用法示例。
在下文中一共展示了ImmutableDictionary.ToDictionary方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public FileModel Load(FileAndType file, ImmutableDictionary<string, object> metadata)
{
switch (file.Type)
{
case DocumentType.Article:
var page = YamlUtility.Deserialize<PageViewModel>(Path.Combine(file.BaseDir, file.File));
if (page.Metadata == null)
{
page.Metadata = metadata.ToDictionary(p => p.Key, p => p.Value);
}
else
{
foreach (var item in metadata)
{
if (!page.Metadata.ContainsKey(item.Key))
{
page.Metadata[item.Key] = item.Value;
}
}
}
var result = new FileModel(file, page, serializer: new BinaryFormatter())
{
Uids = (from item in page.Items select item.Uid).ToImmutableArray(),
};
result.Properties.LinkToFiles = new HashSet<string>();
result.Properties.LinkToUids = new HashSet<string>();
return result;
case DocumentType.Override:
var overrides = MarkdownReader.ReadMarkdownAsOverride(file.BaseDir, file.File);
return new FileModel(file, overrides, serializer: new BinaryFormatter())
{
Uids = (from item in overrides
select item.Uid).ToImmutableArray(),
Properties =
{
LinkToFiles = new HashSet<string>(),
LinkToUids = new HashSet<string>(),
}
};
default:
throw new NotSupportedException();
}
}
示例2: Load
public FileModel Load(FileAndType file, ImmutableDictionary<string, object> metadata)
{
string uid = null;
Dictionary<string, object> content = null;
var metafile = Path.Combine(file.BaseDir, file.File.TrimEnd('.') + ".meta");
if (File.Exists(metafile))
{
content = YamlUtility.Deserialize<Dictionary<string, object>>(metafile);
if (content != null)
{
foreach (var item in metadata)
{
if (!content.ContainsKey(item.Key))
{
content[item.Key] = item.Value;
}
if (item.Key == "uid")
{
uid = item.Value as string;
}
}
}
}
if (content == null)
{
content = metadata.ToDictionary(p => p.Key, p => p.Value);
}
var filePath = Path.Combine(file.BaseDir, file.File);
var repoDetail = GitUtility.GetGitDetail(filePath);
return new FileModel(file, content)
{
Uids = string.IsNullOrEmpty(uid) ? ImmutableArray<string>.Empty : ImmutableArray<string>.Empty.Add(uid),
LocalPathFromRepoRoot = repoDetail?.RelativePath
};
}
示例3: Load
public override FileModel Load(FileAndType file, ImmutableDictionary<string, object> metadata)
{
string uid = null;
Dictionary<string, object> content = null;
var metafile = Path.Combine(file.BaseDir, file.File.TrimEnd('.') + ".meta");
if (File.Exists(metafile))
{
content = YamlUtility.Deserialize<Dictionary<string, object>>(metafile);
if (content != null)
{
foreach (var item in metadata)
{
if (!content.ContainsKey(item.Key))
{
content[item.Key] = item.Value;
}
if (item.Key == Constants.PropertyName.Uid)
{
uid = item.Value as string;
}
}
}
}
if (content == null)
{
content = metadata.ToDictionary(p => p.Key, p => p.Value);
}
var displayLocalPath = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath);
return new FileModel(file, content)
{
Uids = string.IsNullOrEmpty(uid) ? ImmutableArray<UidDefinition>.Empty : ImmutableArray<UidDefinition>.Empty.Add(new UidDefinition(uid, displayLocalPath)),
LocalPathFromRoot = displayLocalPath
};
}
示例4: Load
public override FileModel Load(FileAndType file, ImmutableDictionary<string, object> metadata)
{
switch (file.Type)
{
case DocumentType.Article:
var page = YamlUtility.Deserialize<PageViewModel>(Path.Combine(file.BaseDir, file.File));
if (page.Items == null || page.Items.Count == 0)
{
return null;
}
if (page.Metadata == null)
{
page.Metadata = metadata.ToDictionary(p => p.Key, p => p.Value);
}
else
{
foreach (var item in metadata)
{
if (!page.Metadata.ContainsKey(item.Key))
{
page.Metadata[item.Key] = item.Value;
}
}
}
var displayLocalPath = TypeForwardedToPathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, file.FullPath);
return new FileModel(file, page, serializer: Environment.Is64BitProcess ? null : new BinaryFormatter())
{
Uids = (from item in page.Items select new UidDefinition(item.Uid, displayLocalPath)).ToImmutableArray(),
LocalPathFromRepoRoot = displayLocalPath,
LocalPathFromRoot = displayLocalPath
};
case DocumentType.Overwrite:
// TODO: Refactor current behavior that overwrite file is read multiple times by multiple processors
return OverwriteDocumentReader.Read(file);
default:
throw new NotSupportedException();
}
}
示例5: Transform
private IReadOnlyDictionary<string, IEnumerable<DiagnosticDescriptor>> Transform(
ImmutableDictionary<string, ImmutableArray<DiagnosticDescriptor>> map)
{
// unfortunately, we had to do this since ruleset editor and us are set to use this signature
return map.ToDictionary(kv => kv.Key, kv => (IEnumerable<DiagnosticDescriptor>)kv.Value);
}