Exemplo n.º 1
0
        public IMemberAccessor GetAccessor(Type type, string name)
        {
            IMemberAccessor accessor = null;

            while (type != typeof(object))
            {
                // Look for specific property map
                if (_map.TryGetValue(type, out var typeMap))
                {
                    if (typeMap.TryGetValue(name, out accessor) || typeMap.TryGetValue("*", out accessor))
                    {
                        return(accessor);
                    }
                }

                accessor = accessor ?? _parent?.GetAccessor(type, name);

                if (accessor != null)
                {
                    return(accessor);
                }

                type = type.GetTypeInfo().BaseType;
            }

            return(null);
        }
Exemplo n.º 2
0
        public IMemberAccessor GetAccessor(Type type, string name)
        {
            IMemberAccessor accessor = null;

            if (!_initialized)
            {
                _initialized = true;
            }

            // Get a reference on the map as it can be changed by a call to Register
            var locaMap = _map;

            while (type != typeof(object))
            {
                // Look for specific property map
                if (locaMap.TryGetValue(type, out var typeMap))
                {
                    if (typeMap.TryGetValue(name, out accessor) || typeMap.TryGetValue("*", out accessor))
                    {
                        return(accessor);
                    }
                }

                accessor = accessor ?? _parent?.GetAccessor(type, name);

                if (accessor != null)
                {
                    return(accessor);
                }

                type = type.GetTypeInfo().BaseType;
            }

            return(null);
        }
Exemplo n.º 3
0
        public IMemberAccessor GetAccessor(object obj, string name)
        {
            var type = obj.GetType();

            if (_map.Count > 0)
            {
                while (type != null)
                {
                    // Look for specific property map
                    if (_map.TryGetValue(Key(type, name), out var accessor))
                    {
                        return(accessor);
                    }

                    // Look for a catch-all getter
                    if (_map.TryGetValue(Key(type, "*"), out accessor))
                    {
                        return(accessor);
                    }

                    type = type.GetTypeInfo().BaseType;
                }
            }

            return(_parent?.GetAccessor(obj, name));
        }
Exemplo n.º 4
0
        public IMemberAccessor GetAccessor(Type type, string name)
        {
            IMemberAccessor accessor = null;

            var currentType = type;

            while (currentType != typeof(object) && currentType != null)
            {
                // Look for specific property map
                if (_map.TryGetValue(currentType, out var typeMap))
                {
                    if (typeMap.TryGetValue(name, out accessor) || typeMap.TryGetValue("*", out accessor))
                    {
                        return(accessor);
                    }
                }

                accessor = accessor ?? _parent?.GetAccessor(currentType, name);

                if (accessor != null)
                {
                    return(accessor);
                }

                currentType = currentType.GetTypeInfo().BaseType;
            }

            // Search for accessors defined on interfaces
            foreach (var interfaceType in type.GetTypeInfo().GetInterfaces())
            {
                if (_map.TryGetValue(interfaceType, out var typeMap))
                {
                    if (typeMap.TryGetValue(name, out accessor) || typeMap.TryGetValue("*", out accessor))
                    {
                        if (accessor != null)
                        {
                            return(accessor);
                        }
                    }
                }
            }

            return(null);
        }