public bool TryGetExtension <T>(string name, out T value) { if (Extensions == null) { value = default(T); return(false); } INode node; if (!Extensions.TryGetValue(name, out node)) { value = default(T); return(false); } var v = JsonSchemaAttribute.CreateFromClass <T>(); var ex = v.Validate(node); if (ex != null) { // TODO: throw ex; } var d = new JsonDeserializer(typeof(T)); var dv = d.DeserializeFromNode(node); value = (T)dv; return(true); }
public static Types.Gltf Read(Stream s, bool withRepairment = true, bool withValidation = true) { using (var r = new JsonReader(s)) { var node = r.Read(); if (withRepairment) { RepairKnownInvalidFormat(node); } var jd = new JsonDeserializer(typeof(Types.Gltf)); var gltf = (Types.Gltf)jd.DeserializeFromNode(node); if (withValidation) { var schema = JsonSchemaAttribute.CreateFromClass <Types.Gltf>(); var ex = schema.Validate(gltf); if (ex != null) { throw ex; } } return(gltf); } }