Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,14 @@
<NoWarn>$(NoWarn);CA1830</NoWarn> <!-- Remove the ToString call in order to use a strongly-typed StringBuilder overload -->
<NoWarn>$(NoWarn);CA1846</NoWarn> <!-- Prefer 'AsSpan' over 'Substring' when span-based overloads are available -->
<NoWarn>$(NoWarn);CA1834</NoWarn> <!-- Member XXX is explicitly initialized to its default value -->
<NoWarn>$(NoWarn);CA1841</NoWarn> <!-- Prefer 'ContainsValue' over 'Values.Contains' for dictionary type 'SortedList' -->
<NoWarn>$(NoWarn);CA1845</NoWarn> <!-- Use span-based 'string.Concat' and 'AsSpan' instead of 'Substring' -->
<NoWarn>$(NoWarn);CA1847</NoWarn> <!-- Use 'string.Contains(char)' instead of 'string.Contains(string)' when searching for a single character -->
<NoWarn>$(NoWarn);CA1850</NoWarn> <!-- Prefer static 'System.Security.Cryptography.MD5.HashData' method over 'ComputeHash' -->
<NoWarn>$(NoWarn);CA1852</NoWarn> <!-- Type 'XXX' can be sealed because it has no subtypes in its containing assembly and is not externally visible -->
<NoWarn>$(NoWarn);CA1854</NoWarn> <!-- Prefer a 'TryGetValue' call over a Dictionary indexer access guarded by a 'ContainsKey' check -->
<NoWarn>$(NoWarn);CA1859</NoWarn> <!-- Change return type of method -->
<NoWarn>$(NoWarn);CA1861</NoWarn> <!-- Prefer 'static readonly' fields over constant array arguments -->
<NoWarn>$(NoWarn);CA1862</NoWarn> <!-- Prefer the string comparison method overload -->
<NoWarn>$(NoWarn);CA1864</NoWarn> <!-- To avoid double lookup, call 'TryAdd' instead of calling 'Add' with a 'ContainsKey' -->
<NoWarn>$(NoWarn);CA1853</NoWarn> <!-- Do not guard 'Dictionary.Remove(key)' with 'Dictionary.ContainsKey(key)' -->
<NoWarn>$(NoWarn);CA1872</NoWarn> <!-- Prefer 'System.Convert.ToHexString(byte[])' over call chains based on 'System.BitConverter.ToString(byte[])' -->
<NoWarn>$(NoWarn);CA2019</NoWarn> <!-- 'ThreadStatic' fields should not use inline initialization -->
<NoWarn>$(NoWarn);CA2022</NoWarn> <!-- Avoid inexact read -->
Expand Down
2 changes: 1 addition & 1 deletion main/HPSF/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public void SetProperty(int id, long variantType, Object value)
/// @see Variant
public void SetProperty(Property p)
{
Property old = properties.ContainsKey(p.ID)? properties[p.ID] : null;
Property old = properties.TryGetValue(p.ID, out Property value) ? value : null;
if(old == null || !old.Equals(p))
{
properties[p.ID] = p;
Expand Down
4 changes: 2 additions & 2 deletions main/HSSF/Record/RecordFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,9 @@ private static Dictionary<short, I_RecordCreator> RecordsToMap(Type[] records)
throw new RecordFormatException(
"Unable to determine record types", ArgumentException);
}
if (result.ContainsKey(sid))
if (result.TryGetValue(sid, out I_RecordCreator value))
{
Type prevClass = result[sid].GetRecordClass();
Type prevClass = value.GetRecordClass();
throw new RuntimeException("duplicate record sid 0x" + sid.ToString("X", CultureInfo.CurrentCulture)
+ " for classes (" + recClass.Name + ") and (" + prevClass.Name + ")");
}
Expand Down
4 changes: 2 additions & 2 deletions main/POIFS/FileSystem/EntryUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public static bool AreDirectoriesIdentical(DirectoryEntry dirA, DirectoryEntry d
foreach (Entry b in dirB)
{
String bName = b.Name;
if (!aSizes.ContainsKey(bName))
if (!aSizes.TryGetValue(bName, out int value))
{
// In B but not A
return false;
Expand All @@ -228,7 +228,7 @@ public static bool AreDirectoriesIdentical(DirectoryEntry dirA, DirectoryEntry d
{
size = ((DocumentNode)b).Size;
}
if (size != aSizes[(bName)])
if (size != value)
{
// Either the wrong type, or they're different sizes
return false;
Expand Down
13 changes: 7 additions & 6 deletions main/POIFS/FileSystem/FilteringDirectoryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ public FilteringDirectoryNode(DirectoryEntry directory, ICollection<String> excl
// Applies to a child
String child = excl.Substring(0, splitAt);
String childExcl = excl.Substring(splitAt + 1);
if (!this.childExcludes.ContainsKey(child))
if (!this.childExcludes.TryGetValue(child, out List<String> value))
{
this.childExcludes.Add(child, new List<String>());
value = new List<String>();
this.childExcludes.Add(child, value);
}
this.childExcludes[child].Add(childExcl);

value.Add(childExcl);
}
}
}
Expand Down Expand Up @@ -134,10 +136,9 @@ public Entry GetEntry(String name)
private Entry WrapEntry(Entry entry)
{
String name = entry.Name;
if (childExcludes.ContainsKey(name) && entry is DirectoryEntry directoryEntry)
if (childExcludes.TryGetValue(name, out List<string> value) && entry is DirectoryEntry directoryEntry)
{
return new FilteringDirectoryNode(
directoryEntry, childExcludes[name]);
return new FilteringDirectoryNode(directoryEntry, value);
}
return entry;
}
Expand Down
6 changes: 3 additions & 3 deletions ooxml/POIXMLDocumentPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -716,14 +716,14 @@ protected RelationPart CreateRelationship(POIXMLRelation descriptor, POIXMLFacto

public TValue PutDictionary<TKey, TValue>(Dictionary<TKey, TValue> dict, TKey key, TValue value)
{
TValue oldValue = default(TValue);
if (dict.ContainsKey(key))
if (dict.TryGetValue(key, out TValue oldValue))
{
oldValue = dict[key];
dict[key] = value;
}
else
{
dict.Add(key, value);
}
return oldValue;
}

Expand Down
12 changes: 6 additions & 6 deletions ooxml/XSSF/UserModel/XSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4438,22 +4438,22 @@ public void AddIgnoredErrors(CellRangeAddress region, params IgnoredErrorType[]
/// <returns>Map of error type to the range(s) where they are ignored.</returns>
public Dictionary<IgnoredErrorType, ISet<CellRangeAddress>> GetIgnoredErrors()
{
Dictionary<IgnoredErrorType, ISet<CellRangeAddress>> result =
new Dictionary<IgnoredErrorType, ISet<CellRangeAddress>>();
Dictionary<IgnoredErrorType, ISet<CellRangeAddress>> result = new();
if(worksheet.IsSetIgnoredErrors())
{
foreach(CT_IgnoredError err in worksheet.ignoredErrors.ignoredError)
{
foreach(IgnoredErrorType errType in GetErrorTypes(err))
{
if(!result.ContainsKey(errType))
if(!result.TryGetValue(errType, out ISet<CellRangeAddress> value))
{
result.Add(errType, new HashSet<CellRangeAddress>());
value = new HashSet<CellRangeAddress>();
result.Add(errType, value);
}

foreach(object ref1 in err.sqref)
foreach(string ref1 in err.sqref)
{
result[errType].Add(CellRangeAddress.ValueOf(ref1.ToString()));
value.Add(CellRangeAddress.ValueOf(ref1));
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions ooxml/XSSF/UserModel/XSSFWorkbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,14 @@ public IName CreateName()

private void PutValuesMapping(string key, XSSFName name)
{
if (namedRangesByName.ContainsKey(key))
namedRangesByName[key].Add(name);
if(namedRangesByName.TryGetValue(key, out List<XSSFName> value))
{
value.Add(name);
}
else
namedRangesByName.Add(key, new List<XSSFName>() { name });
{
namedRangesByName.Add(key, [name]);
}
}

private XSSFName CreateAndStoreName(CT_DefinedName ctName)
Expand Down
3 changes: 1 addition & 2 deletions openxml4Net/OPC/Internal/ContentTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ public bool IsContentTypeRegister(String contentType)
if (contentType == null)
throw new ArgumentException("contentType");

return (this.defaultContentType.Values.Contains(contentType) || (this.overrideContentType != null && this.overrideContentType
.Values.Contains(contentType)));
return defaultContentType.ContainsValue(contentType) || (overrideContentType != null && overrideContentType.ContainsValue(contentType));
}

/**
Expand Down