Skip to content

Commit bbc8c17

Browse files
fix(mapping): remove dead AddIncludedResourcesRecursive method (#55)
- Remove unused AddIncludedResourcesRecursive method (146 lines of dead code) - Eliminates silent exception swallowing via Console.WriteLine - Active code path (AddIncludedResources) already uses proper ILogger
1 parent 90fe52e commit bbc8c17

1 file changed

Lines changed: 0 additions & 147 deletions

File tree

JsonApiToolkit/Mapping/InclusionMapper.cs

Lines changed: 0 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -149,151 +149,4 @@ private static void AddSingleIncluded(
149149
AddIncludedResources(relEntity, nestedPaths, included, logger, processedEntities);
150150
}
151151
}
152-
153-
/// <summary>
154-
/// Recursively processes include path to extract related resources.
155-
/// Handles to-one/to-many relationships and nested paths with duplicate prevention.
156-
/// </summary>
157-
public static void AddIncludedResourcesRecursive<T>(
158-
T entity,
159-
string[] pathParts,
160-
int depth,
161-
List<ResourceObject> included,
162-
HashSet<string> processedEntities
163-
)
164-
where T : class
165-
{
166-
if (entity == null || depth >= pathParts.Length)
167-
return;
168-
169-
string propertyName = pathParts[depth];
170-
PropertyInfo? property = typeof(T)
171-
.GetProperties()
172-
.FirstOrDefault(p =>
173-
string.Equals(p.Name, propertyName, StringComparison.OrdinalIgnoreCase)
174-
);
175-
176-
if (property == null)
177-
return;
178-
179-
object? value = property.GetValue(entity);
180-
if (value == null)
181-
return;
182-
183-
if (
184-
typeof(IEnumerable).IsAssignableFrom(property.PropertyType)
185-
&& property.PropertyType != typeof(string)
186-
)
187-
{
188-
foreach (object? item in (IEnumerable)value)
189-
{
190-
if (item == null)
191-
continue;
192-
193-
Type itemType = item.GetType();
194-
PropertyInfo? idProperty = EntityMapper.GetIdProperty(itemType);
195-
if (idProperty == null)
196-
continue;
197-
198-
string? itemId = idProperty.GetValue(item)?.ToString();
199-
if (itemId == null)
200-
continue;
201-
202-
string entityKey = $"{itemType.Name}:{itemId}";
203-
204-
if (processedEntities.Contains(entityKey))
205-
continue;
206-
207-
processedEntities.Add(entityKey);
208-
209-
try
210-
{
211-
var resourceObject = new ResourceObject
212-
{
213-
Id = itemId,
214-
Type = EntityMapper.GetResourceType(itemType),
215-
Attributes = [],
216-
};
217-
218-
foreach (PropertyInfo prop in EntityMapper.GetAttributeProperties(itemType))
219-
{
220-
object? propValue = prop.GetValue(item);
221-
if (propValue != null)
222-
resourceObject.Attributes[prop.Name.ToCamelCase()] = propValue;
223-
}
224-
225-
included.Add(resourceObject);
226-
227-
if (depth + 1 < pathParts.Length)
228-
{
229-
AddIncludedResourcesRecursive(
230-
item,
231-
pathParts,
232-
depth + 1,
233-
included,
234-
processedEntities
235-
);
236-
}
237-
}
238-
catch (Exception)
239-
{
240-
Console.WriteLine("Failed to process included resource");
241-
}
242-
}
243-
}
244-
else
245-
{
246-
Type relType = value.GetType();
247-
PropertyInfo? idProperty = EntityMapper.GetIdProperty(relType);
248-
if (idProperty == null)
249-
return;
250-
251-
string? relId = idProperty.GetValue(value)?.ToString();
252-
if (relId == null)
253-
return;
254-
255-
string entityKey = $"{relType.Name}:{relId}";
256-
257-
if (processedEntities.Contains(entityKey))
258-
return;
259-
260-
processedEntities.Add(entityKey);
261-
262-
try
263-
{
264-
var resourceObject = new ResourceObject
265-
{
266-
Id = relId,
267-
Type = EntityMapper.GetResourceType(relType),
268-
Attributes = [],
269-
};
270-
271-
foreach (PropertyInfo prop in EntityMapper.GetAttributeProperties(relType))
272-
{
273-
object? propValue = prop.GetValue(value);
274-
if (propValue != null)
275-
{
276-
resourceObject.Attributes[prop.Name.ToCamelCase()] = propValue;
277-
}
278-
}
279-
280-
included.Add(resourceObject);
281-
282-
if (depth + 1 < pathParts.Length)
283-
{
284-
AddIncludedResourcesRecursive(
285-
value,
286-
pathParts,
287-
depth + 1,
288-
included,
289-
processedEntities
290-
);
291-
}
292-
}
293-
catch (Exception)
294-
{
295-
Console.WriteLine("Failed to process included resource");
296-
}
297-
}
298-
}
299152
}

0 commit comments

Comments
 (0)