Cached Metadata about the indicated type.
예제 #1
0
 static internal IEnumerable <string> GetColumnsFor(ClassMetadata metadata, string decompositionPrefix)
 {
     foreach (var property in metadata.Properties)
     {
         if (property.Decompose)
         {
             foreach (var item in GetColumnsFor(property.PropertyType, decompositionPrefix + property.DecompositionPrefix))
             {
                 yield return(item);
             }
         }
         else if (property.CanWrite && property.MappedColumnName != null)
         {
             yield return(decompositionPrefix + property.MappedColumnName);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Gets the metadata for the indicated type.
        /// </summary>
        /// <param name="typeInfo">The type of interest</param>
        /// <returns>A thread-safe copy of the class's metadata</returns>
        /// <remarks>Actually fetching the metadata requires taking a lock. Therefore it is advisable to locally cache the metadata as well.</remarks>
        public static ClassMetadata GetMetadata(TypeInfo typeInfo)
        {
            if (typeInfo == null)
            {
                throw new ArgumentNullException(nameof(typeInfo), $"{nameof(typeInfo)} is null.");
            }

            lock (s_SyncRoot)
            {
                ClassMetadata result;
                if (s_ModelInfo.TryGetValue(typeInfo, out result))
                {
                    return(result);
                }

                result = new ClassMetadata(typeInfo);

                //Cache the TypeInfo object
                s_ModelInfo.Add(typeInfo, result);
                return(result);
            }
        }