using System.Collections.Generic;
using Newtonsoft.Json.Serialization;
public static void Main()
""AttachedTaskLocations"": [
var settings = new JsonSerializerSettings();
settings.ObjectCreationHandling = ObjectCreationHandling.Replace;
Console.WriteLine("Deserializing AnchorMetaData from JSON");
var metaData = JsonConvert.DeserializeObject<AnchorMetaData>(json, settings);
Console.WriteLine("Dumping attachedTaskLocations list");
if (metaData.attachedTaskLocations.Any())
foreach (Vector3 vector in metaData.attachedTaskLocations)
Console.WriteLine(vector);
Console.WriteLine("attachedTaskLocations list is empty!");
public class AnchorMetaData
public List<Vector3> attachedTaskLocations = new List<Vector3>();
[JsonProperty("AttachedTaskLocations")]
public List<SerializableVector3> AttachedTaskLocations
Console.WriteLine("AttachedTaskLocations getter was called");
return attachedTaskLocations
.Select(vector3 => new SerializableVector3(vector3))
Console.WriteLine("AttachedTaskLocations setter was called");
attachedTaskLocations = value
.Select(sVector3 => new Vector3(sVector3.x, sVector3.y, sVector3.z))
public class SerializableVector3
public Vector3 vector = Vector3.negativeInfinity;
public SerializableVector3() { }
public SerializableVector3(float x, float y, float z)
public SerializableVector3(Vector3 vector3)
public override string ToString() => $"SerializableVector3 [{x}, {y}, {z}]";
public static implicit operator Vector3(SerializableVector3 rhs) => new Vector3(rhs.x, rhs.y, rhs.z);
public static implicit operator SerializableVector3(Vector3 rhs) => new SerializableVector3(rhs);
public partial struct Vector3 : IEquatable<Vector3>
public const float kEpsilon = 0.00001F;
public Vector3(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
public Vector3(float x, float y) { this.x = x; this.y = y; z = 0F; }
public void Set(float newX, float newY, float newZ) { x = newX; y = newY; z = newZ; }
public override int GetHashCode()
return x.GetHashCode() ^ (y.GetHashCode() << 2) ^ (z.GetHashCode() >> 2);
public override bool Equals(object other)
if (!(other is Vector3)) return false;
return Equals((Vector3)other);
public bool Equals(Vector3 other)
return x == other.x && y == other.y && z == other.z;
public Vector3 normalized
public float magnitude { get { return (float)Math.Sqrt(x * x + y * y + z * z); } }
public float sqrMagnitude { get { return x * x + y * y + z * z; } }
static readonly Vector3 zeroVector = new Vector3(0F, 0F, 0F);
static readonly Vector3 oneVector = new Vector3(1F, 1F, 1F);
static readonly Vector3 positiveInfinityVector = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
static readonly Vector3 negativeInfinityVector = new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity);
public static Vector3 zero { get { return zeroVector; } }
public static Vector3 one { get { return oneVector; } }
public static Vector3 positiveInfinity { get { return positiveInfinityVector; } }
public static Vector3 negativeInfinity { get { return negativeInfinityVector; } }
public static Vector3 operator +(Vector3 a, Vector3 b) { return new Vector3(a.x + b.x, a.y + b.y, a.z + b.z); }
public static Vector3 operator -(Vector3 a, Vector3 b) { return new Vector3(a.x - b.x, a.y - b.y, a.z - b.z); }
public static Vector3 operator -(Vector3 a) { return new Vector3(-a.x, -a.y, -a.z); }
public static Vector3 operator *(Vector3 a, float d) { return new Vector3(a.x * d, a.y * d, a.z * d); }
public static Vector3 operator *(float d, Vector3 a) { return new Vector3(a.x * d, a.y * d, a.z * d); }
public static Vector3 operator /(Vector3 a, float d) { return new Vector3(a.x / d, a.y / d, a.z / d); }
public static bool operator ==(Vector3 lhs, Vector3 rhs)
float diff_x = lhs.x - rhs.x;
float diff_y = lhs.y - rhs.y;
float diff_z = lhs.z - rhs.z;
float sqrmag = diff_x * diff_x + diff_y * diff_y + diff_z * diff_z;
return sqrmag < kEpsilon * kEpsilon;
public static bool operator !=(Vector3 lhs, Vector3 rhs)
public override string ToString()
return $"Vector3 ({x}, {y}, {z})";