Esempio n. 1
0
 private void MapServiceDefinedAtAttributeLevel(ServiceMapTable services, Type serviceType, ServiceAttribute serviceAttribute)
 {
     if (serviceAttribute.Contracts != null)
     {
         foreach (var contract in serviceAttribute.Contracts)
         {
             if (contract != null)
             {
                 //First we need to check whether service class is inherited from this contract
                 if (contract.GetTypeInfo().IsAssignableFrom(serviceType))
                 {
                     MapService(services, contract, serviceType);
                 }
             }
         }
     }
 }
Esempio n. 2
0
        private void MapSelectiveBaseAndInterfaceTypes(Type serviceType, ServiceMapTable services, ServiceAttribute serviceAttribute)
        {
#if NET46
            /*Fetch implemented interfaces of service whose interface is decorated with  ContractAttribute.*/
            IEnumerable <Type> interfaces = serviceType.GetInterfaces()
                                            .Where(@interface => @interface.GetCustomAttribute <ContractAttribute>() != null);
#else
            /*Fetch implemented interfaces of service whose interface is decorated with  ContractAttribute.*/
            IEnumerable <Type> interfaces = serviceType.GetInterfaces()
                                            .Where(@interface => @interface.GetTypeInfo().GetCustomAttribute <ContractAttribute>() != null);
#endif
            /*Maps the base class (which is decorated with contract attribute) of the service*/
            if (serviceType.GetTypeInfo().BaseType != typeof(object))
            {
                //if base type is decorated with contract attribute then add that to service.
                var baseTypeInfo = serviceType.GetTypeInfo().BaseType.GetTypeInfo();
                if (baseTypeInfo.GetCustomAttribute <ContractAttribute>() != null)
                {
                    MapService(services, interfaceType: serviceType.GetTypeInfo().BaseType, serviceType: serviceType);
                }
            }

            /*Maps the interfaces (which are decorated with contract attribute) of the service */
            /*Map service type with the contract interfaces*/
            foreach (var interfaceType in interfaces)
            {
                MapService(services, interfaceType, serviceType);
            }

            /*Maps inherit type (base class/interface) if the type is set to the property contract of ServiceAttribute  */
            MapServiceDefinedAtAttributeLevel(services, serviceType, serviceAttribute);
        }