Skip to content

Commit

Permalink
putting root back
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Jun 14, 2024
1 parent f510d49 commit 808232c
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions DUI3-DX/Sdk/Speckle.Converters.Common/IRootToSpeckleConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
using Speckle.Autofac.DependencyInjection;
using Speckle.Converters.Common.Objects;
using Speckle.Core.Models;
using Speckle.InterfaceGenerator;

namespace Speckle.Converters.Common;

public interface IRootToSpeckleConverter
[GenerateAutoInterface]
public class RootToSpeckleConverter : IRootToSpeckleConverter
{
Speckle.Core.Models.Base Convert(object target);
private readonly IFactory<IToSpeckleTopLevelConverter> _toSpeckle;

public RootToSpeckleConverter(IFactory<IToSpeckleTopLevelConverter> toSpeckle)
{
_toSpeckle = toSpeckle;
}

public Base Convert(Type type, object target)
{
try
{
var objectConverter = _toSpeckle.ResolveInstance(type.Name); //poc: would be nice to have supertypes resolve

if (objectConverter == null)
{
throw new NotSupportedException($"No conversion found for {type.Name}");
}
var convertedObject = objectConverter.Convert(target);

return convertedObject;
}
catch (SpeckleConversionException e)
{
Console.WriteLine(e);
throw; // Just rethrowing for now, Logs may be needed here.
}
}
}

0 comments on commit 808232c

Please sign in to comment.