Exemple #1
0
        /// <summary>
        /// Get the service name for the class (either by convention or by attribute).
        /// </summary>
        /// <param name="type">A service to get the name for.</param>
        /// <returns>The canonical name of the service or the name provided in the corresponding name attribute, if supplied.</returns>
        public static string GetServiceName(Type type)
        {
            // Check for ServiceName attribute
            var nameAttributes = type.GetCustomAttributes(typeof(ServiceNameAttribute), inherit: true);

            if (nameAttributes.Length > 0)
            {
                ServiceNameAttribute nameAttribute = nameAttributes[0] as ServiceNameAttribute;
                if (nameAttribute != null)
                {
                    string name = nameAttribute.Name;
                    CheckServiceName(name);
                    return(name);
                }
            }

            return(GetCanonicalName(type));
        }
Exemple #2
0
        /// <summary>
        /// Get the service name for the class (either by convention or by attribute).
        /// </summary>
        /// <param name="type">A service to get the name for.</param>
        /// <returns>The canonical name of the service or the name provided in the corresponding name attribute, if supplied.</returns>
        public static string GetServiceName(Type type)
        {
            // Check for ServiceName attribute
            var nameAttributes = type.GetTypeInfo().GetCustomAttributes(typeof(ServiceNameAttribute), true);

            if (nameAttributes.Any())
            {
                ServiceNameAttribute nameAttribute = nameAttributes.FirstOrDefault() as ServiceNameAttribute;
                if (nameAttribute != null)
                {
                    string name = nameAttribute.Name;
                    CheckServiceName(name);
                    return(name);
                }
            }

            return(GetCanonicalName(type));
        }