internal static ResourceInfoAttribute GetMostInheritedResourceInterfaceInfo(
            this IClientTypeResolver client,
            Type sourceType)
        {
            ResourceInfoAttribute sourceTypeResourceInfo;

            if (client.TryGetResourceInfoForType(sourceType, out sourceTypeResourceInfo))
            {
                return(sourceTypeResourceInfo);
            }

            var allResourceInfos = sourceType.GetInterfaces().Select(
                x =>
            {
                ResourceInfoAttribute resourceInfo;
                if (!client.TryGetResourceInfoForType(x, out resourceInfo))
                {
                    resourceInfo = null;
                }
                return(resourceInfo);
            }).Where(x => x != null).ToList();

            var mostSubtyped = allResourceInfos
                               .FirstOrDefault(
                x =>
                !allResourceInfos.Any(
                    y => x.InterfaceType != y.InterfaceType && x.InterfaceType.IsAssignableFrom(y.InterfaceType)));

            return(mostSubtyped);
        }
Пример #2
0
 public ExtendedResourceMapper(IClientTypeResolver clientTypeResolver)
 {
     if (clientTypeResolver == null)
     {
         throw new ArgumentNullException(nameof(clientTypeResolver));
     }
     this.clientTypeResolver = clientTypeResolver;
 }
Пример #3
0
 internal ExtendedQueryableRoot(IClientTypeResolver client,
                                IQueryable wrappedSource,
                                ExtendedResourceInfo extendedResourceInfo,
                                ExtendedResourceMapper extendedResourceMapper)
     : base(new ExtendedQueryProvider(extendedResourceMapper), null)
 {
     WrappedSource        = wrappedSource;
     ExtendedResourceInfo = extendedResourceInfo;
 }
        public static ResourceInfoAttribute GetResourceInfoForType(this IClientTypeResolver client, Type type)
        {
            ResourceInfoAttribute resourceInfoAttribute;

            if (!client.TryGetResourceInfoForType(type, out resourceInfoAttribute))
            {
                throw new InvalidOperationException(
                          "Unable to find ResourceInfoAttribute for type " + type.FullName);
            }
            return(resourceInfoAttribute);
        }
        /// <summary>
        /// This function gets the most subtyped server-known interface implemented by given type.
        ///
        /// For example lets take a type hierarchy where we got entities IBase and IEntity, where IEntity
        /// inherits from IBase.
        ///
        /// Then we got some other type like ICustomCrazyType that inherits from IEntity. When given
        /// this type this function will return IEntity type.
        /// </summary>
        /// <param name="client">Client responsible for resolving type. TODO: Might put this in its own interface.</param>
        /// <param name="sourceType">Type to find resource interface on.</param>
        /// <returns>Most subtyped server-known interface implemented by sourceType.</returns>
        public static Type GetMostInheritedResourceInterface(this IClientTypeResolver client, Type sourceType)
        {
            var mostSubtyped = client.GetMostInheritedResourceInterfaceInfo(sourceType);

            if (mostSubtyped == null)
            {
                throw new ArgumentException(
                          "sourceType does not implement any resource-type known to client.",
                          nameof(sourceType));
            }
            return(mostSubtyped.InterfaceType);
        }
Пример #6
0
        internal static bool TryGetExtendedResourceInfo(Type clientType, IClientTypeResolver client, out ExtendedResourceInfo info)
        {
            info = null;
            var serverTypeInfo = client.GetMostInheritedResourceInterfaceInfo(clientType);
            if (!clientType.IsInterface || serverTypeInfo == null)
                return false;

            var serverType = serverTypeInfo.InterfaceType;

            if (serverType == clientType)
                return false;

            var dictProperty = GetAttributesDictionaryPropertyFromResource(serverType);
            info = new ExtendedResourceInfo(clientType, serverType, dictProperty);
            return true;
        }