Skip to content

Commit

Permalink
refactor: reformat and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rikarin committed Mar 31, 2024
1 parent 495257b commit a19a04b
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Rin.Core.Reflection.Yaml/Rin.Core.Reflection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Rin.Core\Rin.Core.csproj" />
<ProjectReference Include="..\Rin.Core\Rin.Core.csproj"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ public void SetValue(object dictionary, object key, object value) {
} else {
// Only throw an exception if the addMethod is not accessible when adding to a dictionary
if (indexerSetter == null) {
throw new InvalidOperationException(
$"No indexer this[key] method found on dictionary [{Type}]"
);
throw new InvalidOperationException($"No indexer this[key] method found on dictionary [{Type}]");
}

indexerSetter.Invoke(dictionary, [key, value]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ protected virtual List<IMemberDescriptor> PrepareMembers() {

var bindingFlags = BindingFlags.Instance | BindingFlags.Public;

var metadataTypeAttributes = Type.GetCustomAttributes<DataContractMetadataTypeAttribute>(inherit: true);
var metadataTypeAttributes = Type.GetCustomAttributes<DataContractMetadataTypeAttribute>(true);
var metadataClassMemberInfos =
metadataTypeAttributes.Any() ? new List<(MemberInfo MemberInfo, Type MemberType)>() : null;
foreach (var metadataTypeAttr in metadataTypeAttributes) {
Expand Down
2 changes: 1 addition & 1 deletion Rin.Core.Yaml/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Event ParseDocumentStart(bool isImplicit) {

states.Push(ParserState.YamlParseDocumentEndState);
state = ParserState.YamlParseBlockNodeState;

return new Events.DocumentStart(null, directives, true, GetCurrentToken().Start, GetCurrentToken().End);
}

Expand Down
49 changes: 0 additions & 49 deletions Rin.Core.Yaml/Properties/AssemblyInfo.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Rin.Core.Yaml/Rin.Core.Yaml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Rin.Core.Reflection.Yaml\Rin.Core.Reflection.csproj" />
<ProjectReference Include="..\Rin.Core\Rin.Core.csproj" />
<ProjectReference Include="..\Rin.Core.Reflection.Yaml\Rin.Core.Reflection.csproj"/>
<ProjectReference Include="..\Rin.Core\Rin.Core.csproj"/>
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions Rin.Core.Yaml/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ Token ScanBlockScalar(bool isLiteral) {
}

var end = mark;

// Set the indentation level if it was specified.
if (increment != 0) {
currentIndent = indent >= 0 ? indent + increment : increment;
Expand Down Expand Up @@ -1219,6 +1219,7 @@ Token ScanFlowScalar(bool isSingleQuoted) {
"While parsing a quoted scalar, find unknown escape character."
);
}

break;
}

Expand Down Expand Up @@ -1463,7 +1464,7 @@ Token ScanPlainScalar() {
/// </summary>
void RemoveSimpleKey() {
var key = simpleKeys.Peek();

if (key is { IsPossible: true, IsRequired: true }) {
// If the key is required, it is an error.
throw new SyntaxErrorException(
Expand Down
7 changes: 6 additions & 1 deletion Rin.Core.Yaml/Serialization/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ public void Serialize(IEmitter emitter, object graph) {
/// <param name="graph">The object to serialize.</param>
/// <param name="type">The static type of the object to serialize.</param>
/// <param name="contextSettings">The context settings.</param>
public void Serialize(IEmitter emitter, object graph, Type type, SerializerContextSettings? contextSettings = null) {
public void Serialize(
IEmitter emitter,
object graph,
Type type,
SerializerContextSettings? contextSettings = null
) {
if (emitter == null) {
throw new ArgumentNullException(nameof(emitter));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override object ConvertFrom(ref ObjectContext context, Scalar scalar) {

// If type is an enum, try to parse it
if (type.IsEnum) {
var result = primitiveType.ParseEnum(text, out bool enumRemapped);
var result = primitiveType.ParseEnum(text, out var enumRemapped);
if (enumRemapped) {
context.SerializerContext.HasRemapOccurred = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Rin.Core.Yaml/Serialization/YamlAssemblyRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void RegisterAssembly(Assembly assembly, IAttributeRegistry attributeRegi
var assemblyScanTypes = AssemblyRegistry.GetScanTypes(assembly);
if (assemblyScanTypes != null) {
// Register serializer factories
if (assemblyScanTypes.Types.TryGetValue(typeof(IYamlSerializableFactory), out List<Type> types)) {
if (assemblyScanTypes.Types.TryGetValue(typeof(IYamlSerializableFactory), out var types)) {
foreach (var type in types) {
if (typeof(IYamlSerializableFactory).IsAssignableFrom(type)
&& type.GetConstructor(Type.EmptyTypes) != null) {
Expand Down
4 changes: 2 additions & 2 deletions Rin.Core.Yaml/Serialization/YamlSequenceNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class YamlSequenceNode : YamlNode, IEnumerable<YamlNode> {
public override IEnumerable<YamlNode> AllNodes {
get {
yield return this;

foreach (var child in Children) {
foreach (var node in child.AllNodes) {
yield return node;
Expand Down Expand Up @@ -87,7 +87,7 @@ public YamlSequenceNode(params YamlNode[] children)
/// </summary>
public YamlSequenceNode(IEnumerable<YamlNode> children) {
foreach (var child in children) {
this.Children.Add(child);
Children.Add(child);
}
}

Expand Down
1 change: 0 additions & 1 deletion Rin.Core.Yaml/TagDirectiveCollection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Rin.Core.Yaml.Tokens;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Rin.Core.Yaml;
Expand Down

0 comments on commit a19a04b

Please sign in to comment.