Skip to content

Commit

Permalink
chore: Remove obsolete warning suppression. and fix deprecated APIs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
filzrev authored Jul 5, 2023
1 parent a0832df commit ed96e8d
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 35 deletions.
10 changes: 0 additions & 10 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@
</PropertyGroup>

<PropertyGroup>
<!--
Suppress warnings similar to the following:
warning CS0612: 'StringHelper.LegacyEscapeMarkdown(string)' is obsolete
-->
<NoWarn>$(NoWarn);CS0612</NoWarn>
<!--
Suppress warnings similar to the following:
warning CS0618: 'MarkdownLHeadingBlockRule.LHeading' is obsolete: 'Please use LHeadingMatcher.'
-->
<NoWarn>$(NoWarn);CS0618</NoWarn>
<!--
Suppress warnings similar to the following:
warning NU1507: There are 2 package sources defined in your configuration.
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.DocAsCode.Build.Engine/ManifestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

namespace Microsoft.DocAsCode.Common;

#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete

public static class ManifestUtility
{
public static void RemoveDuplicateOutputFiles(ManifestItemCollection manifestItems)
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.DocAsCode.Build.Engine/SingleDocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace Microsoft.DocAsCode.Build.Engine;

#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete

public class SingleDocumentBuilder : IDisposable
{
private const string PhaseName = "Build Document";
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.DocAsCode.Common/JsonUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.DocAsCode.Plugins;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;

namespace Microsoft.DocAsCode.Common;

Expand All @@ -16,7 +17,7 @@ public static class JsonUtility
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
Converters =
{
new StringEnumConverter { CamelCaseText = true },
new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy() },
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public static void DeserializeHelper<TItem>(IParser reader, Type expectedType, F
{
var list = result as IList<TItem>;

reader.Expect<SequenceStart>();
while (!reader.Accept<SequenceEnd>())
reader.Consume<SequenceStart>();
while (!reader.Accept<SequenceEnd>(out _))
{
var current = reader.Current;

Expand All @@ -103,6 +103,6 @@ public static void DeserializeHelper<TItem>(IParser reader, Type expectedType, F
);
}
}
reader.Expect<SequenceEnd>();
reader.Consume<SequenceEnd>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func<IPars
return false;
}

reader.Expect<MappingStart>();
reader.Consume<MappingStart>();

value = _objectFactory.Create(expectedType);
var cacheKey = Tuple.Create(gp[0], gp[1]);
Expand All @@ -72,15 +72,15 @@ bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func<IPars
}
action(reader, expectedType, nestedObjectDeserializer, value);

reader.Expect<MappingEnd>();
reader.Consume<MappingEnd>();

return true;
}

[EditorBrowsable(EditorBrowsableState.Never)]
public static void DeserializeHelper<TKey, TValue>(IParser reader, Type expectedType, Func<IParser, Type, object> nestedObjectDeserializer, IDictionary<TKey, TValue> result)
{
while (!reader.Accept<MappingEnd>())
while (!reader.Accept<MappingEnd>(out _))
{
var key = nestedObjectDeserializer(reader, typeof(TKey));
var keyPromise = key as IValuePromise;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ public ExtensibleObjectNodeDeserializer(IObjectFactory objectFactory, ITypeInspe

bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func<IParser, Type, object> nestedObjectDeserializer, out object value)
{
var mapping = reader.Allow<MappingStart>();
if (mapping == null)
if (!reader.TryConsume<MappingStart>(out _))
{
value = null;
return false;
}

value = _objectFactory.Create(expectedType);
while (!reader.Accept<MappingEnd>())
while (!reader.Accept<MappingEnd>(out _))
{
var propertyName = reader.Expect<Scalar>();
var propertyName = reader.Consume<Scalar>();
var property = _typeDescriptor.GetProperty(expectedType, value, propertyName.Value, _ignoreUnmatched);
if (property == null)
{
Expand All @@ -58,7 +57,7 @@ bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func<IPars
}
}

reader.Expect<MappingEnd>();
reader.Consume<MappingEnd>();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private void TraverseGenericDictionary<TContext>(IObjectDescriptor dictionary, T
action = GetTraverseGenericDictionaryHelper(entryTypes[0], entryTypes[1], typeof(TContext));
_traverseGenericDictionaryCache[key] = action;
}
action(this, dictionary.Value, v, currentDepth, _namingConvention ?? new NullNamingConvention(), c);
action(this, dictionary.Value, v, currentDepth, _namingConvention ?? NullNamingConvention.Instance, c);

v.VisitMappingEnd(dictionary, c);
}
Expand Down
18 changes: 8 additions & 10 deletions src/Microsoft.DocAsCode.YamlSerialization/YamlDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public YamlDeserializer(
bool ignoreNotFoundAnchor = true)
{
objectFactory = objectFactory ?? new DefaultEmitObjectFactory();
namingConvention = namingConvention ?? new NullNamingConvention();
namingConvention = namingConvention ?? NullNamingConvention.Instance;

_typeDescriptor.TypeDescriptor =
new ExtensibleYamlAttributesTypeInspector(
Expand Down Expand Up @@ -170,12 +170,12 @@ public object Deserialize(IParser parser, Type type, IValueDeserializer deserial
throw new ArgumentNullException("type");
}

var hasStreamStart = parser.Allow<StreamStart>() != null;
var hasStreamStart = parser.TryConsume<StreamStart>(out _);

var hasDocumentStart = parser.Allow<DocumentStart>() != null;
var hasDocumentStart = parser.TryConsume<DocumentStart>(out _);
deserializer = deserializer ?? _valueDeserializer;
object result = null;
if (!parser.Accept<DocumentEnd>() && !parser.Accept<StreamEnd>())
if (!parser.Accept<DocumentEnd>(out _) && !parser.Accept<StreamEnd>(out _))
{
using var state = new SerializerState();
result = deserializer.DeserializeValue(parser, type, state, deserializer);
Expand All @@ -184,12 +184,12 @@ public object Deserialize(IParser parser, Type type, IValueDeserializer deserial

if (hasDocumentStart)
{
parser.Expect<DocumentEnd>();
parser.Consume<DocumentEnd>();
}

if (hasStreamStart)
{
parser.Expect<StreamEnd>();
parser.Consume<StreamEnd>();
}

return result;
Expand Down Expand Up @@ -267,8 +267,7 @@ public object Value
public object DeserializeValue(IParser reader, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
{
object value;
var alias = reader.Allow<AnchorAlias>();
if (alias != null)
if (reader.TryConsume<AnchorAlias>(out var alias))
{
var aliasState = state.Get<AliasState>();
if (!aliasState.TryGetValue(alias.Value, out ValuePromise valuePromise))
Expand All @@ -282,8 +281,7 @@ public object DeserializeValue(IParser reader, Type expectedType, SerializerStat

AnchorName? anchor = null;

var nodeEvent = reader.Peek<NodeEvent>();
if (nodeEvent != null && !nodeEvent.Anchor.IsEmpty)
if (reader.Accept<NodeEvent>(out var nodeEvent) && !nodeEvent.Anchor.IsEmpty)
{
anchor = nodeEvent.Anchor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class YamlSerializer
public YamlSerializer(SerializationOptions options = SerializationOptions.None, INamingConvention namingConvention = null)
{
_options = options;
_namingConvention = namingConvention ?? new NullNamingConvention();
_namingConvention = namingConvention ?? NullNamingConvention.Instance;

Converters = new List<IYamlTypeConverter>();
foreach (IYamlTypeConverter yamlTypeConverter in YamlTypeConverters.BuiltInConverters)
Expand Down
2 changes: 2 additions & 0 deletions test/Microsoft.DocAsCode.Common.Tests/GitUtilityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void Environment_ForGitTimeout()
Assert.Equal(10_000, GitUtility.GetGitTimeout());
}

[Obsolete]
[Fact]
public void TestParseGitRepoInfo()
{
Expand All @@ -68,6 +69,7 @@ public void TestParseGitRepoInfo()
Assert.Equal(RepoType.Vso, repoInfo.RepoType);
}

[Obsolete]
[Fact]
public void TestCombineGitUrl()
{
Expand Down
3 changes: 2 additions & 1 deletion test/Microsoft.DocAsCode.Plugins.Tests/JsonConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Xunit;

namespace Microsoft.DocAsCode.Plugins.Tests;
Expand Down Expand Up @@ -33,7 +34,7 @@ public void TestJObjectDictionaryToObjectDictionaryConverterSerializeAndDeserial
{
Converters =
{
new StringEnumConverter { CamelCaseText = true },
new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy() },
}
};

Expand Down

0 comments on commit ed96e8d

Please sign in to comment.