You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ReflectorNet/src/Convertor/Reflection/ArrayReflectionConvertor.cs
+39-15Lines changed: 39 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -169,20 +169,29 @@ public override bool SetField(
169
169
ILogger?logger=null)
170
170
{
171
171
varpadding=StringUtils.GetPadding(depth);
172
-
if(logger?.IsEnabled(LogLevel.Trace)==true)
173
-
logger.LogTrace($"{padding}Set field type='{fieldInfo.FieldType.GetTypeShortName()}', name='{fieldInfo.Name}'. Convertor='{GetType().GetTypeShortName()}'.");
172
+
// if (logger?.IsEnabled(LogLevel.Trace) == true)
173
+
// logger.LogTrace($"{padding}Set field type='{fieldInfo.FieldType.GetTypeShortName()}', name='{fieldInfo.Name}'. Convertor='{GetType().GetTypeShortName()}'.");
stringBuilder?.AppendLine($"{padding}[Error] Parsed value type '{type.GetTypeName(pretty:false)}' is not assignable to field type '{fieldInfo.FieldType.GetTypeName(pretty:false)}' for field '{fieldInfo.Name}'.");
184
192
returnfalse;
185
193
}
194
+
186
195
// TODO: Print previous and new value in stringBuilder
187
196
fieldInfo.SetValue(obj,parsedValue);
188
197
returntrue;
@@ -200,20 +209,35 @@ public override bool SetProperty(
stringBuilder?.AppendLine($"{padding}[Error] Parsed value type '{type.GetTypeName(pretty:false)}' is not assignable to property type '{propertyInfo.PropertyType.GetTypeName(pretty:false)}' for property '{propertyInfo.Name}'.");
238
+
returnfalse;
239
+
}
240
+
217
241
// TODO: Print previous and new value in stringBuilder
stringBuilder?.AppendLine($"{padding}[Error] Parsed value type '{type.GetTypeName(pretty:false)}' is not assignable to field type '{fieldInfo.FieldType.GetTypeName(pretty:false)}' for field '{fieldInfo.Name}'.");
113
+
returnfalse;
114
+
}
115
+
108
116
// TODO: Print previous and new value in stringBuilder
109
117
fieldInfo.SetValue(obj,parsedValue);
110
118
if(stringBuilder!=null)
@@ -125,9 +133,16 @@ public override bool SetProperty(
125
133
{
126
134
varpadding=StringUtils.GetPadding(depth);
127
135
136
+
// Check if property is writable
137
+
if(!propertyInfo.CanWrite)
138
+
{
139
+
stringBuilder?.AppendLine($"{padding}[Error] Property '{propertyInfo.Name}' is read-only.");
140
+
returnfalse;
141
+
}
142
+
128
143
if(!TryDeserializeValue(
129
144
reflector,
130
-
serializedMember:value,
145
+
data:value,
131
146
result:outvarparsedValue,
132
147
type:outvartype,
133
148
fallbackType:fallbackType,
@@ -138,6 +153,14 @@ public override bool SetProperty(
138
153
stringBuilder?.AppendLine($"{padding}[Error] Failed to deserialize value for property '{propertyInfo.Name}'.");
139
154
returnfalse;
140
155
}
156
+
157
+
// Check if property type matches parsed value type
stringBuilder?.AppendLine($"{padding}[Error] Parsed value type '{type.GetTypeName(pretty:false)}' is not assignable to property type '{propertyInfo.PropertyType.GetTypeName(pretty:false)}' for property '{propertyInfo.Name}'.");
161
+
returnfalse;
162
+
}
163
+
141
164
// TODO: Print previous and new value in stringBuilder
0 commit comments