コード例 #1
0
 public ITypeData GetTypeData(string identifier, TypeDataProviderStack stack)
 {
     if (identifier.StartsWith(exp))
     {
         var tp = TypeData.GetTypeData(identifier.Substring(exp.Length));
         if (tp != null)
         {
             return(FromTypeData(tp));
         }
     }
     return(null);
 }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
        /// <summary> Gets the type data from an identifier. </summary>
        /// <param name="identifier">The identifier to get type information for.</param>
        /// <returns>A representation of the type specified by identifier or null if no providers can handle the specified identifier.</returns>
        public ITypeData GetTypeData(string identifier)
        {
            if (identifier == null)
            {
                return(null);
            }
            while (offset < providers.Count)
            {
                var provider = providers[offset];
                offset++;
                try
                {
                    if (provider is IStackedTypeDataProvider sp)
                    {
                        var newStack = new TypeDataProviderStack(providers, offset);
                        if (sp.GetTypeData(identifier, newStack) is ITypeData found)
                        {
                            return(found);
                        }
                    }
                    else if (provider is ITypeDataProvider p)
                    {
                        if (p.GetTypeData(identifier) is ITypeData found)
                        {
                            return(found);
                        }
                    }
                }
                catch (Exception error)
                {
                    logProviderError(provider, error);
                }
            }

            return(null);
        }