/// <summary> /// Returns the shared <see cref="Metadata"/> object for the specified /// class. /// </summary> /// <param name="type">The class corresponding to the element.</param> /// <returns> /// The <see cref="Metadata"/> object for the specified class. /// </returns> private Metadata GetSharedMetadata(Type type) { return(metadataCache.Intern(type, () => { validationTraversal.Visit(type); try { dagChecker.Check(type); } catch (CircularDependencyException e) { throw new BindException( $"{type.Name} has circular dependency.", e); } var fields = Classes.GetInstanceFields <ForTextAttribute>(type); var methods = Classes.GetInstanceMethods <FromTextAttribute>(type); if (fields.Any() && methods.Any()) { Debug.Fail(fields.First() + " and " + methods.First()); } return fields.Any() ? new TextMetadata(type, fields) : methods.Any() ? new TextMetadata(type, methods) : new SchemaMetadata(type) as Metadata; })); }