Example #1
0
        /// <summary>
        /// Gets either cached value or gets value and caches for future.
        /// </summary>
        /// <param name="objType">use object.GetType()</param>
        /// <returns>version number</returns>
        /// <exception cref="ArgumentException">if object does not have version attribute</exception>
        public static VersionNumbers GetVersion(Type objType)
        {
            VersionNumbers versionNo;

            if (TypeVersionCache.TryGetValue(objType, out versionNo))
            {
                return(versionNo);
            }

            versionNo = BuildVersionCache(objType);

            return(versionNo);
        }
Example #2
0
        /// <summary>
        /// Builds type wise version number cache.
        /// </summary>
        /// <param name="objType"></param>
        /// <returns></returns>
        private static VersionNumbers BuildVersionCache(Type objType)
        {
            var versionTypeAttribute = Attribute.GetCustomAttribute(objType, typeof(VersionTypeAttribute))
                                       as VersionTypeAttribute;

            if (versionTypeAttribute == null)
            {
                throw new ArgumentException("No version type attribute specified for the type");
            }

            var versionNo = versionTypeAttribute.Version;

            TypeVersionCache.TryAdd(objType, versionNo);
            return(versionNo);
        }