Skip to content

Commit

Permalink
Add back in the Units support
Browse files Browse the repository at this point in the history
  • Loading branch information
saintentropy committed Oct 13, 2023
1 parent 8e0ef8c commit 1f43200
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
5 changes: 5 additions & 0 deletions src/Libraries/CoreNodes/CoreNodes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<Project>{c0d6dee5-5532-4345-9c66-4c00d7fdb8be}</Project>
<Name>DesignScriptBuiltin</Name>
</ProjectReference>
<ProjectReference Include="..\DynamoUnits\UnitsCore.csproj">
<Project>{6e0a079e-85f1-45a1-ad5b-9855e4344809}</Project>
<Name>Units</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="DSCoreNodes.Migrations.xml">
Expand Down
60 changes: 30 additions & 30 deletions src/Libraries/CoreNodes/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ private static object DynamoJObjectToNative(JObject jObject)

return null;

//case "dynamo.data:location-1.0.0":
// return DynamoUnits.Location.ByLatitudeAndLongitude(
// (double)jObject["Latitude"],
// (double)jObject["Longitude"],
// (string)jObject["Name"]);
case "dynamo.data:location-1.0.0":
return DynamoUnits.Location.ByLatitudeAndLongitude(
(double)jObject["Latitude"],
(double)jObject["Longitude"],
(string)jObject["Name"]);

default:
return null;
Expand Down Expand Up @@ -290,31 +290,31 @@ public override bool CanConvert(Type objectType)
}
}

//private class LocationConverter : JsonConverter
//{
// public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
// {
// var jobject = JObject.FromObject(value);
// jobject.Add("$typeid", "dynamo.data:location-1.0.0");

// jobject.WriteTo(writer);
// }

// public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
// {
// throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter.");
// }

// public override bool CanRead
// {
// get { return false; }
// }

// public override bool CanConvert(Type objectType)
// {
// return typeof(DynamoUnits.Location) == objectType;
// }
//}
private class LocationConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var jobject = JObject.FromObject(value);
jobject.Add("$typeid", "dynamo.data:location-1.0.0");

jobject.WriteTo(writer);
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter.");
}

public override bool CanRead
{
get { return false; }
}

public override bool CanConvert(Type objectType)
{
return typeof(DynamoUnits.Location) == objectType;
}
}

private class ImageConverter : JsonConverter
{
Expand Down

0 comments on commit 1f43200

Please sign in to comment.