public static IAttribute FindAttribute(this IG3D g3D, AttributeType attributeType, bool throwIfMissing = true) { var candidates = g3D.FindAttributes(attributeType).ToList(); if (candidates.Count > 1) { throw new Exception($"Multiple matching attributes of type {attributeType.AttributeTypeString()}"); } if (candidates.Count == 0) { if (throwIfMissing) { throw new Exception($"No matching attributes of type {attributeType.AttributeTypeString()}"); } return(null); } return(candidates[0]); }