Beispiel #1
0
        public ITypeData GetTypeData(object obj, TypeDataProviderStack stack)
        {
            var typedata = stack.GetTypeData(obj);

            if (internedValues.TryGetValue(typedata, out EmbeddedTypeData val))
            {
                return(val ?? typedata);
            }
            if (typedata.GetMembers().Any(x => x.HasAttribute <EmbedPropertiesAttribute>()))
            {
                return(FromTypeData(typedata));
            }
            // assign null to the value.
            return(internedValues.GetValue(typedata, t => null) ?? typedata);
        }
Beispiel #2
0
        /// <summary> Get the type info of an object. </summary>
        static public ITypeData GetTypeData(object obj)
        {
            var cache = TypeDataCache.Current;

            if (cache != null && cache.TryGetValue(obj, out var cachedValue))
            {
                return(cachedValue);
            }
            checkCacheValidity();
            if (obj == null)
            {
                return(FromType(typeof(object)));
            }
            var resolver = new TypeDataProviderStack();
            var result   = resolver.GetTypeData(obj);

            if (cache == null)
            {
                return(result);
            }
            cache[obj] = result;
            return(result);
        }