Skip to content

Commit

Permalink
Merge branch 'main' into avoid-multi-enumeration-warnings-in-TryGetSt…
Browse files Browse the repository at this point in the history
…ringBeforeChars
  • Loading branch information
SimonCropp authored Nov 6, 2024
2 parents baa5a3d + 65f9bed commit 6e79b7c
Show file tree
Hide file tree
Showing 204 changed files with 4,574 additions and 4,646 deletions.
12 changes: 5 additions & 7 deletions src/Docfx.Build.ManagedReference/FillReferenceInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ public class FillReferenceInformation : BaseDocumentBuildStep

public override void Postbuild(ImmutableList<FileModel> models, IHostService host)
{
if (models.Count > 0)
foreach (var model in models)
{
foreach (var model in models)
if (model.Type != DocumentType.Article)
{
if (model.Type != DocumentType.Article)
{
continue;
}
FillCore((PageViewModel)model.Content, host, model.OriginalFileAndType.File);
continue;
}

FillCore((PageViewModel)model.Content, host, model.OriginalFileAndType.File);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,34 +205,25 @@ private static IEnumerable<XRefSpec> GetXRefInfo(ItemViewModel item, string key,
Href = ((RelativePath)key).UrlEncode().ToString(),
CommentId = item.CommentId,
};
if (item.Names.Count > 0)
foreach (var pair in item.Names)
{
foreach (var pair in item.Names)
{
result["name." + pair.Key] = pair.Value;
}
result["name." + pair.Key] = pair.Value;
}
if (!string.IsNullOrEmpty(item.FullName))
{
result["fullName"] = item.FullName;
}
if (item.FullNames.Count > 0)
foreach (var pair in item.FullNames)
{
foreach (var pair in item.FullNames)
{
result["fullName." + pair.Key] = pair.Value;
}
result["fullName." + pair.Key] = pair.Value;
}
if (!string.IsNullOrEmpty(item.NameWithType))
{
result["nameWithType"] = item.NameWithType;
}
if (item.NamesWithType.Count > 0)
foreach (var pair in item.NamesWithType)
{
foreach (var pair in item.NamesWithType)
{
result["nameWithType." + pair.Key] = pair.Value;
}
result["nameWithType." + pair.Key] = pair.Value;
}
yield return result;
// generate overload xref spec.
Expand Down Expand Up @@ -263,34 +254,25 @@ private static XRefSpec GetXRefSpecFromReference(ReferenceViewModel item)
CommentId = item.CommentId,
IsSpec = item.IsExternal != true,
};
if (item.NameInDevLangs.Count > 0)
foreach (var pair in item.NameInDevLangs)
{
foreach (var pair in item.NameInDevLangs)
{
result["name." + pair.Key] = pair.Value;
}
result["name." + pair.Key] = pair.Value;
}
if (!string.IsNullOrEmpty(item.FullName))
{
result["fullName"] = item.FullName;
}
if (item.FullNameInDevLangs.Count > 0)
foreach (var pair in item.FullNameInDevLangs)
{
foreach (var pair in item.FullNameInDevLangs)
{
result["fullName." + pair.Key] = pair.Value;
}
result["fullName." + pair.Key] = pair.Value;
}
if (!string.IsNullOrEmpty(item.NameWithType))
{
result["nameWithType"] = item.NameWithType;
}
if (item.NameWithTypeInDevLangs.Count > 0)
foreach (var pair in item.NameWithTypeInDevLangs)
{
foreach (var pair in item.NameWithTypeInDevLangs)
{
result["nameWithType." + pair.Key] = pair.Value;
}
result["nameWithType." + pair.Key] = pair.Value;
}
if (item.Additional != null)
{
Expand Down
42 changes: 12 additions & 30 deletions src/Docfx.Build.ManagedReference/SplitClassPageToMemberLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,26 +343,17 @@ private ReferenceViewModel ConvertToReference(ItemViewModel item)
FullName = item.FullName,
};

if (item.Names.Count > 0)
foreach (var pair in item.Names)
{
foreach (var pair in item.Names)
{
reference.NameInDevLangs[pair.Key] = pair.Value;
}
reference.NameInDevLangs[pair.Key] = pair.Value;
}
if (item.FullNames.Count > 0)
foreach (var pair in item.FullNames)
{
foreach (var pair in item.FullNames)
{
reference.FullNameInDevLangs[pair.Key] = pair.Value;
}
reference.FullNameInDevLangs[pair.Key] = pair.Value;
}
if (item.NamesWithType.Count > 0)
foreach (var pair in item.NamesWithType)
{
foreach (var pair in item.NamesWithType)
{
reference.NameWithTypeInDevLangs[pair.Key] = pair.Value;
}
reference.NameWithTypeInDevLangs[pair.Key] = pair.Value;
}

return reference;
Expand All @@ -375,26 +366,17 @@ private static void MergeWithReference(ItemViewModel item, ReferenceViewModel re
item.FullName = reference.FullName;
item.CommentId = reference.CommentId;

if (reference.NameInDevLangs.Count > 0)
foreach (var pair in reference.NameInDevLangs)
{
foreach (var pair in reference.NameInDevLangs)
{
item.Names[pair.Key] = pair.Value;
}
item.Names[pair.Key] = pair.Value;
}
if (reference.FullNameInDevLangs.Count > 0)
foreach (var pair in reference.FullNameInDevLangs)
{
foreach (var pair in reference.FullNameInDevLangs)
{
item.FullNames[pair.Key] = pair.Value;
}
item.FullNames[pair.Key] = pair.Value;
}
if (reference.NameWithTypeInDevLangs.Count > 0)
foreach (var pair in reference.NameWithTypeInDevLangs)
{
foreach (var pair in reference.NameWithTypeInDevLangs)
{
item.NamesWithType[pair.Key] = pair.Value;
}
item.NamesWithType[pair.Key] = pair.Value;
}

// SHOULD sync with ItemViewModel & ReferenceViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public object Interpret(BaseSchema schema, object value, IProcessContext context
$"Markdown property `{path.Trim('/')}` is not allowed inside a YAML code block",
code: WarningCodes.Overwrite.InvalidMarkdownFragments);
return value;
};
}

if (schema.MergeType == MergeType.Key)
{
Expand Down
21 changes: 16 additions & 5 deletions src/Docfx.Build.SchemaDriven/Processors/Merger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,22 @@ private static bool TestKey(object source, object overrides, BaseSchema schema)
{
return false;
}
return schema?.Properties != null && schema.Properties.Any(p => p.Value.MergeType == MergeType.Key) && schema.Properties.Where(p => p.Value.MergeType == MergeType.Key).All(p =>

var properties = schema?.Properties;
if (properties == null)
{
(source as IDictionary<string, object>).TryGetValue(p.Key, out var s);
(overrides as IDictionary<string, object>).TryGetValue(p.Key, out var o);
return object.Equals(s, o);
});
return false;
}

var sourceDictionary = (IDictionary<string, object>)source;
var overridesDictionary = (IDictionary<string, object>)overrides;
return properties.Any(p => p.Value.MergeType == MergeType.Key) &&
properties.Where(p => p.Value.MergeType == MergeType.Key)
.All(p =>
{
sourceDictionary.TryGetValue(p.Key, out var s);
overridesDictionary.TryGetValue(p.Key, out var o);
return object.Equals(s, o);
});
}
}
12 changes: 5 additions & 7 deletions src/Docfx.Build.UniversalReference/FillReferenceInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ public class FillReferenceInformation : BaseDocumentBuildStep

public override void Postbuild(ImmutableList<FileModel> models, IHostService host)
{
if (models.Count > 0)
foreach (var model in models)
{
foreach (var model in models)
if (model.Type != DocumentType.Article)
{
if (model.Type != DocumentType.Article)
{
continue;
}
FillCore((PageViewModel)model.Content, host);
continue;
}

FillCore((PageViewModel)model.Content, host);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,34 +159,25 @@ private static IEnumerable<XRefSpec> GetXRefInfo(
Href = ((RelativePath)key).UrlEncode().ToString(),
CommentId = item.CommentId,
};
if (item.Names.Count > 0)
foreach (var pair in item.Names)
{
foreach (var pair in item.Names)
{
result["name." + pair.Key] = pair.Value;
}
result["name." + pair.Key] = pair.Value;
}
if (!string.IsNullOrEmpty(item.FullName))
{
result["fullName"] = item.FullName;
}
if (item.FullNames.Count > 0)
foreach (var pair in item.FullNames)
{
foreach (var pair in item.FullNames)
{
result["fullName." + pair.Key] = pair.Value;
}
result["fullName." + pair.Key] = pair.Value;
}
if (!string.IsNullOrEmpty(item.NameWithType))
{
result["nameWithType"] = item.NameWithType;
}
if (item.NamesWithType.Count > 0)
foreach (var pair in item.NamesWithType)
{
foreach (var pair in item.NamesWithType)
{
result["nameWithType." + pair.Key] = pair.Value;
}
result["nameWithType." + pair.Key] = pair.Value;
}
yield return result;

Expand Down Expand Up @@ -217,34 +208,25 @@ private static XRefSpec GetXRefSpecFromReference(ReferenceViewModel item)
Href = item.Href,
CommentId = item.CommentId,
};
if (item.NameInDevLangs.Count > 0)
foreach (var pair in item.NameInDevLangs)
{
foreach (var pair in item.NameInDevLangs)
{
result["name." + pair.Key] = pair.Value;
}
result["name." + pair.Key] = pair.Value;
}
if (!string.IsNullOrEmpty(item.FullName))
{
result["fullName"] = item.FullName;
}
if (item.FullNameInDevLangs.Count > 0)
foreach (var pair in item.FullNameInDevLangs)
{
foreach (var pair in item.FullNameInDevLangs)
{
result["fullName." + pair.Key] = pair.Value;
}
result["fullName." + pair.Key] = pair.Value;
}
if (!string.IsNullOrEmpty(item.NameWithType))
{
result["nameWithType"] = item.NameWithType;
}
if (item.NameWithTypeInDevLangs.Count > 0)
foreach (var pair in item.NameWithTypeInDevLangs)
{
foreach (var pair in item.NameWithTypeInDevLangs)
{
result["nameWithType." + pair.Key] = pair.Value;
}
result["nameWithType." + pair.Key] = pair.Value;
}
if (item.Additional != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build/TemplateProcessors/TemplateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static void Copy(Action<Stream> streamHandler, string filePath, bool ove
try
{
var subfolder = Path.GetDirectoryName(filePath);
if (!string.IsNullOrEmpty(subfolder) && !Directory.Exists(subfolder))
if (!string.IsNullOrEmpty(subfolder))
{
Directory.CreateDirectory(subfolder);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Docfx.Build/XRefMaps/XRefMapDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static async ValueTask<IXRefContainer> ReadLocalFileAsync(string filePat
{
using var reader = new StreamReader(stream);
return YamlUtility.Deserialize<XRefMap>(reader);
};
}
}
}

Expand All @@ -147,8 +147,7 @@ private static async ValueTask<IXRefContainer> ReadLocalFileAsync(string filePat
case ".yml":
default:
{
using var sr = File.OpenText(filePath);
return YamlUtility.Deserialize<XRefMap>(sr);
return YamlUtility.Deserialize<XRefMap>(filePath);
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/Docfx.Common/FileAbstractLayer/FileWriterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ protected internal static void EnsureFolder(string folder)
{
return;
}
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}

Directory.CreateDirectory(folder);
}
}
2 changes: 1 addition & 1 deletion src/Docfx.Dotnet/DotnetApiCatalog.ApiPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ _ when SymbolHelper.IsConstructor(method) => "Constructor",
_ when SymbolHelper.IsOperator(method) => "Operator",
_ when SymbolHelper.IsMember(method) => "Method",
_ => throw new NotSupportedException($"Unknown method type {method.MethodKind}"),
}); ;
});
foreach (var (s, c) in symbols)
Method((IMethodSymbol)s, c, 2);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.MarkdigEngine.Extensions/ExtensionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private static bool MatchPath(ref StringSlice slice, ref string path)
else
{
includedFilePath = TryGetStringBeforeChars([')'], ref slice, breakOnWhitespace: true);
};
}

if (includedFilePath == null)
{
Expand Down
Loading

0 comments on commit 6e79b7c

Please sign in to comment.