Skip to content

Commit b9345ce

Browse files
authored
Merge pull request #44 from bacongobbler/ignore-missing-objects
fix: IgnoreMissingProperties should ignore objects
2 parents 5605d7c + cca52d5 commit b9345ce

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/Tomlyn.Tests/ModelTests/ReflectionModelTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,9 @@ public void TestModelWithFixedList()
428428
public void TestModelWithMissingProperties()
429429
{
430430
var input = @"values = ['1', '2', '3']
431-
some_thing_that_doesnt_exist = true";
431+
some_thing_that_doesnt_exist = true
432+
[object_that_doesnt_exist]
433+
required = true";
432434

433435
StandardTests.DisplayHeader("input");
434436
Console.WriteLine(input);

src/Tomlyn/Model/Accessors/DictionaryDynamicAccessor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ public override bool TryCreateAndSetDefaultPropertyValue(SourceSpan span, object
107107
errorMessage = $"Unexpected error when creating object for property {name} on object type {TargetType.FullName}. Reason: {ex.Message}";
108108
}
109109

110-
Context.Diagnostics.Error(span, errorMessage);
110+
// If configured to ignore missing properties on the target type,
111+
// return false to indicate it is missing but don't set an error
112+
if (!Context.IgnoreMissingProperties)
113+
{
114+
Context.Diagnostics.Error(span, errorMessage);
115+
}
111116
return false;
112117
}
113118

src/Tomlyn/Model/Accessors/StandardObjectDynamicAccessor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,12 @@ public override bool TryCreateAndSetDefaultPropertyValue(SourceSpan span, object
197197
errorMessage = $"Unexpected error when creating object for property {name} on object type {TargetType.FullName}. Reason: {ex.Message}";
198198
}
199199

200-
Context.Diagnostics.Error(span, errorMessage);
200+
// If configured to ignore missing properties on the target type,
201+
// return false to indicate it is missing but don't set an error
202+
if (!Context.IgnoreMissingProperties)
203+
{
204+
Context.Diagnostics.Error(span, errorMessage);
205+
}
201206
return false;
202207
}
203208
}

0 commit comments

Comments
 (0)