/// <summary>
        ///   Searches for all string resources inside the <see cref="System.Resources.ResourceManager"/> whose name is prefixed with a matching tag.
        /// </summary>
        /// <remarks>
        /// <para>
        ///   If a duplicate ID is found, the ID from the last ResourceManager wins.
        /// </para><para>
        ///   Fallback:
        ///     <list type="number">
        ///       <item>
        ///         Resource hierarchy for current culture.
        ///       </item>
        ///       <item>
        ///         Resource hierarchies for less specific cultures
        ///       </item>
        ///     </list>
        ///   </para>
        /// </remarks>
        public NameValueCollection GetAllStrings(string prefix)
        {
            return(_cachedResourceSet.GetOrCreateValue(
                       Tuple.Create(CultureInfo.CurrentUICulture, prefix ?? string.Empty),
                       key =>
            {
                //  Loop through all entries in the resource managers
                CultureInfo[] cultureHierarchy = GetCultureHierarchy(key.Item1);

                // Loop from most neutral to current UICulture
                // Copy the resources into a collection
                NameValueCollection result = new NameValueCollection();
                for (int i = 0; i < cultureHierarchy.Length; i++)
                {
                    CultureInfo culture = cultureHierarchy[i];
                    ResourceSet resourceSet = _resourceManager.GetResourceSet(culture, true, false);
                    if (resourceSet != null)
                    {
                        foreach (DictionaryEntry entry in resourceSet)
                        {
                            string entryKey = (string)entry.Key;
                            if (entryKey.StartsWith(key.Item2))
                            {
                                result[entryKey] = (string)entry.Value;
                            }
                        }
                    }
                }

                return result;
            }));
        }
Пример #2
0
        /// <summary>
        /// Returns the type arguments for the ascribed <paramref name="ascribeeType"/> as inherited or implemented by a given <paramref name="type"/>.
        /// </summary>
        /// <param name="type">The <see cref="Type"/> for which to return the type parameter. Must not be <see langword="null" />.</param>
        /// <param name="ascribeeType">The <see cref="Type"/> to check the <paramref name="type"/> against. Must not be <see langword="null" />.</param>
        /// <returns>A <see cref="Type"/> array containing the generic arguments of the <paramref name="ascribeeType"/> as it is inherited or implemented
        /// by <paramref name="type"/>.</returns>
        /// <exception cref="ArgumentException">
        /// Thrown if the <paramref name="type"/> is not the <paramref name="ascribeeType"/> or its instantiation, its subclass or the implementation
        /// of an interface in case the <paramref name="ascribeeType"/> is an interface.
        /// </exception>
        /// <exception cref="AmbiguousMatchException">
        /// Thrown if the <paramref name="type"/> is an interface and implements the interface <paramref name="ascribeeType"/> or its instantiations
        /// more than once.
        /// </exception>
        public static Type[] GetAscribedGenericArguments(this Type type, Type ascribeeType)
        {
            ArgumentUtility.CheckNotNull("type", type);
            ArgumentUtility.CheckNotNull("ascribeeType", ascribeeType);

            return(s_ascribedGenericArgumentsCache.GetOrCreateValue(
                       Tuple.Create(type, ascribeeType), key => GetAscribedGenericArgumentsWithoutCache(key.Item1, key.Item2)));
        }
Пример #3
0
        /// <summary>
        /// Returns the mapping name for the given <paramref name="propertyInformation"/>.
        /// </summary>
        /// <param name="propertyInformation">The property whose mapping name should be retrieved.</param>
        /// <returns>The name of the given <paramref name="propertyInformation"/> as used internally by the mapping.</returns>
        public string GetPropertyName(IPropertyInformation propertyInformation)
        {
            ArgumentUtility.CheckNotNull("propertyInformation", propertyInformation);

            return(s_propertyNameCache.GetOrCreateValue(
                       propertyInformation,
                       pi => GetPropertyName(pi.GetOriginalDeclaringType(), pi.Name)));
        }
        private ResolvedResourceManagerResult GetResolvedResourceManagerFromCache(Type type)
        {
            if (type == null)
            {
                return(ResolvedResourceManagerResult.Null);
            }

            return(_resourceManagerWrappersCache.GetOrCreateValue(type, CreateResolvedResourceManagerResult));
        }
        public static WxeParameterDeclaration[] GetParameterDeclarations(Type type)
        {
            ArgumentUtility.CheckNotNull("type", type);
            if (!typeof(WxeFunction).IsAssignableFrom(type))
            {
                throw new ArgumentException("Type " + type.FullName + " is not derived from WxeFunction.", "type");
            }

            return(s_parameterDeclarations.GetOrCreateValue(type, GetParameterDeclarationsUnchecked));
        }
Пример #6
0
        /// <summary>
        /// Use this method as a shortcut to retrieve the <see cref="BindableObjectProvider"/> for a <see cref="Type"/>
        /// that has the <see cref="BindableObjectMixinBase{T}"/> applied or is derived from a bindable object base class without first retrieving the
        /// matching provider.
        /// </summary>
        /// <param name="type">The <see cref="Type"/> to retrieve the <see cref="BindableObjectProvider"/> for.</param>
        /// <returns>Returns the <see cref="BindableObjectProvider"/> for the <paramref name="type"/>.</returns>
        public static BindableObjectProvider GetProviderForBindableObjectType(Type type)
        {
            ArgumentUtility.CheckNotNull("type", type);

            var providerAttributeType = s_providerAttributeTypeCache.GetOrCreateValue(type, FindProviderAttributeType);

            var provider = (BindableObjectProvider)GetProvider(providerAttributeType);

            Assertion.IsNotNull(provider, "GetProvider cannot return null (type '{0}').", type.FullName);
            return(provider);
        }
Пример #7
0
        private static MethodInfo GetParseMethod(Type type, bool throwIfNotFound)
        {
            var parseMethod =
                s_parseMethods.GetOrCreateValue(type, key => GetParseMethodWithFormatProviderFromType(type) ?? GetParseMethodFromType(type));

            if (throwIfNotFound && parseMethod == null)
            {
                throw new ParseException(string.Format("Type does not have method 'public static {0} Parse (string s)'.", type.Name));
            }

            return(parseMethod);
        }
Пример #8
0
        /// <summary>
        /// Gets a query for the given LINQ query, returning it from the cache if possible.
        /// </summary>
        /// <typeparam name="T">The <see cref="DomainObject"/> type to start the query with.</typeparam>
        /// <param name="id">The ID to associate with the LINQ queryable. This ID is used as the cache key of the parsed query.</param>
        /// <param name="queryGenerator">A delegate returning the LINQ queryable. The argument of this delegate is a <see cref="DomainObjectQueryable{T}"/>
        /// to start the LINQ query with.</param>
        /// <returns>An <see cref="IQuery"/> implementation corresponding to the LINQ query returned by <paramref name="queryGenerator"/>.</returns>
        /// <remarks>
        /// The <paramref name="queryGenerator"/> delegate is only evaluated if no query with the given <paramref name="id"/> is found in the cache.
        /// </remarks>
        public IQuery GetQuery <T> (string id, Func <IQueryable <T>, IQueryable> queryGenerator) where T : DomainObject
        {
            ArgumentUtility.CheckNotNullOrEmpty("id", id);
            ArgumentUtility.CheckNotNull("queryGenerator", queryGenerator);

            return(_cache.GetOrCreateValue(id, delegate
            {
                var querySource = QueryFactory.CreateLinqQuery <T> ();
                var query = queryGenerator(querySource);
                return QueryFactory.CreateQuery <T> (id, query);
            }));
        }
 private XmlSerializer GetXmlSerializer(Type concreteType)
 {
     return(_attributeOverridesCache.GetOrCreateValue(
                concreteType,
                delegate(Type type)
     {
         return new XmlSerializer(
             type,
             CreateAttributeOverrides(type),
             new Type[0],
             AttributeUtility.GetCustomAttribute <XmlRootAttribute> (type, true),
             null);
     }));
 }
Пример #10
0
        public ClassContext GetWithInheritance(Type type)
        {
            ArgumentUtility.CheckNotNull("type", type);

            var exactMatch = GetExact(type);

            if (exactMatch != null)
            {
                return(exactMatch);
            }
            else
            {
                return(_inheritedContextCache.GetOrCreateValue(type, DeriveInheritedContext));
            }
        }
Пример #11
0
        /// <summary>
        /// Evaluates whether the <paramref name="type"/> can be ascribed to the <paramref name="ascribeeType"/>.
        /// </summary>
        /// <param name="type">The <see cref="Type"/> to check. Must not be <see langword="null" />.</param>
        /// <param name="ascribeeType">The <see cref="Type"/> to check the <paramref name="type"/> against. Must not be <see langword="null" />.</param>
        /// <returns>
        /// <see langword="true"/> if the <paramref name="type"/> is the <paramref name="ascribeeType"/> or its instantiation,
        /// its subclass or the implementation of an interface in case the <paramref name="ascribeeType"/> is an interface.
        /// </returns>
        public static bool CanAscribeTo(this Type type, Type ascribeeType)
        {
            ArgumentUtility.CheckNotNull("type", type);
            ArgumentUtility.CheckNotNull("ascribeeType", ascribeeType);

            return(s_canAscribeCache.GetOrCreateValue(
                       Tuple.Create(type, ascribeeType),
                       key =>
            {
                if (key.Item2.IsInterface)
                {
                    if (key.Item1.IsInterface && CanAscribeInternalFromCache(key.Item1, key.Item2))
                    {
                        return true;
                    }

                    return Array.Exists(key.Item1.GetInterfaces(), current => CanAscribeInternalFromCache(current, key.Item2));
                }
                else
                {
                    return CanAscribeInternalFromCache(type, ascribeeType);
                }
            }));
        }
Пример #12
0
 public static EnumMetadata GetEnumMetadata(Type enumType)
 {
     return(s_cache.GetOrCreateValue(enumType, t => new EnumMetadata(t)));
 }
Пример #13
0
 private static bool CanAscribeInternalFromCache(Type type, Type ascribeeType)
 {
     return(s_canAscribeInternalCache.GetOrCreateValue(Tuple.Create(type, ascribeeType), key => CanAscribeInternal(key.Item1, key.Item2)));
 }
Пример #14
0
        public string GetEnumName(Enum enumValue)
        {
            ArgumentUtility.CheckNotNull("enumValue", enumValue);

            return(s_enumCache.GetOrCreateValue(enumValue, GetEnumNameInternal));
        }
Пример #15
0
 private static bool CanDirectlyAscribeToGenericTypeInternalFromCache(Type type, Type ascribeeType, Type ascribeeGenericTypeDefinition)
 {
     return(s_canDirectlyAscribeToGenericTypeInternalCache.GetOrCreateValue(
                Tuple.Create(type, ascribeeType, ascribeeGenericTypeDefinition),
                key => CanDirectlyAscribeToGenericTypeInternal(key.Item1, key.Item2, key.Item3)));
 }
 public static bool IsAssemblySigned(Assembly assembly)
 {
     ArgumentUtility.CheckNotNull("assembly", assembly);
     return(s_isAssemblySignedCache.GetOrCreateValue(assembly, asm => IsAssemblySigned(asm.GetName())));
 }
        /// <summary>
        /// Gets the <see cref="ExtensibleEnumDefinition{T}"/> for the given <paramref name="extensibleEnumType"/> from the cache creating a new
        /// one if necessary. If a new instance is created, the <see cref="ValueDiscoveryService"/> is used to discover the values of the enum type.
        /// </summary>
        /// <param name="extensibleEnumType">The type of the extensible enum for which to retrieve an <see cref="ExtensibleEnumDefinition{T}"/>.</param>
        /// <returns>The <see cref="ExtensibleEnumDefinition{T}"/> for the given type.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="extensibleEnumType"/> parameter is <see langword="null" />.</exception>
        /// <exception cref="ArgumentException">The <paramref name="extensibleEnumType"/> parameter is not derived from
        /// <see cref="ExtensibleEnumInfo{T}"/>.</exception>
        public IExtensibleEnumDefinition GetDefinition(Type extensibleEnumType)
        {
            ArgumentUtility.CheckNotNull("extensibleEnumType", extensibleEnumType);

            return(_cache.GetOrCreateValue(extensibleEnumType, CreateDefinition));
        }
Пример #18
0
        /// <summary>
        /// Returns the mapping name for the given <paramref name="typeInformation"/>.
        /// </summary>
        /// <param name="typeInformation">The type whose mapping name should be retrieved.</param>
        /// <returns>The name of the given <paramref name="typeInformation"/> as used internally by the mapping.</returns>
        public string GetTypeName(ITypeInformation typeInformation)
        {
            ArgumentUtility.CheckNotNull("typeInformation", typeInformation);

            return(s_typeNameCache.GetOrCreateValue(typeInformation, GetTypeNameInternal));
        }
 private ResourceManager GetResourceManagerFromCache(Assembly assembly, IResourcesAttribute resourcesAttribute)
 {
     return(_resourceManagersCache.GetOrCreateValue(
                Tuple.Create(resourcesAttribute.ResourceAssembly ?? assembly, resourcesAttribute.BaseName),
                GetResourceManager));
 }