示例#1
0
        internal string[] GetLanguageIdentifiers(Type type, bool extensionsOnly)
        {
            if (type != null && !type.IsSubclassOf(typeof(LanguageProvider)))
            {
                throw new ArgumentException("Invalid type - should be subclass of LanguageProvider"); // TODO
            }

            bool          get_all = type == null;
            List <string> result  = new List <string>();

            lock (_languageTypes) {
                LanguageProviderDesc singleton_desc = null;
                if (!get_all && !_languageTypes.TryGetValue(type.AssemblyQualifiedName, out singleton_desc))
                {
                    return(ArrayUtils.EmptyStrings);
                }

                foreach (KeyValuePair <string, LanguageProviderDesc> entry in _languageIds)
                {
                    if (get_all || ReferenceEquals(entry.Value, singleton_desc))
                    {
                        if (!extensionsOnly || IsExtensionId(entry.Key))
                        {
                            result.Add(entry.Key);
                        }
                    }
                }
            }

            return(result.ToArray());
        }
示例#2
0
        /// <summary>
        /// Throws an exception on failure.
        /// </summary>
        /// <exception cref="ArgumentNullException"><paramref name="type"/></exception>
        /// <exception cref="ArgumentException"><paramref name="type"/></exception>
        /// <exception cref="MissingTypeException"><paramref name="languageId"/></exception>
        /// <exception cref="InvalidImplementationException">The language provider's implementation failed to instantiate.</exception>
        public LanguageProvider GetLanguageProvider(Type type)
        {
            Contract.RequiresNotNull(type, "type");
            if (!type.IsSubclassOf(typeof(LanguageProvider)))
            {
                throw new ArgumentException("Invalid type - should be subclass of LanguageProvider");                                               // TODO
            }
            LanguageProviderDesc desc = null;

            lock (_languageProvidersLock) {
                if (!_languageTypes.TryGetValue(type.AssemblyQualifiedName, out desc))
                {
                    desc = new LanguageProviderDesc(type);
                    _languageTypes[type.AssemblyQualifiedName] = desc;
                }
            }

            if (desc != null)
            {
                return(desc.LoadProvider(this));
            }

            // not found, not registered:
            throw new ArgumentException(Resources.UnknownLanguageProviderType);
        }
示例#3
0
        public void RegisterLanguageProvider(string assemblyName, string typeName, bool overrideExistingIds, params string[] identifiers)
        {
            Contract.RequiresNotNull(identifiers, "identifiers");

            LanguageProviderDesc singleton_desc;
            bool   add_singleton_desc = false;
            string aq_name            = MakeAssemblyQualifiedName(typeName, assemblyName);

            lock (_languageProvidersLock) {
                if (!_languageTypes.TryGetValue(aq_name, out singleton_desc))
                {
                    add_singleton_desc = true;
                    singleton_desc     = new LanguageProviderDesc(typeName, assemblyName);
                }

                // check for conflicts:
                if (!overrideExistingIds)
                {
                    for (int i = 0; i < identifiers.Length; i++)
                    {
                        LanguageProviderDesc desc;
                        if (_languageIds.TryGetValue(identifiers[i], out desc) && !ReferenceEquals(desc, singleton_desc))
                        {
                            throw new InvalidOperationException("Conflicting Ids");
                        }
                    }
                }

                // add singleton LP-desc:
                if (add_singleton_desc)
                {
                    _languageTypes.Add(aq_name, singleton_desc);
                }

                // add id mapping to the singleton LP-desc:
                for (int i = 0; i < identifiers.Length; i++)
                {
                    _languageIds[identifiers[i]] = singleton_desc;
                }
            }
        }
        public void RegisterLanguageProvider(string assemblyName, string typeName, bool overrideExistingIds, params string[] identifiers)
        {
            Contract.RequiresNotNull(identifiers, "identifiers");

            LanguageProviderDesc singleton_desc;
            bool add_singleton_desc = false;
            string aq_name = MakeAssemblyQualifiedName(typeName, assemblyName);

            lock (_languageProvidersLock) {
                if (!_languageTypes.TryGetValue(aq_name, out singleton_desc)) {
                    add_singleton_desc = true;
                    singleton_desc = new LanguageProviderDesc(typeName, assemblyName);
                }

                // check for conflicts:
                if (!overrideExistingIds) {
                    for (int i = 0; i < identifiers.Length; i++) {
                        LanguageProviderDesc desc;
                        if (_languageIds.TryGetValue(identifiers[i], out desc) && !ReferenceEquals(desc, singleton_desc)) {
                            throw new InvalidOperationException("Conflicting Ids");
                        }
                    }
                }

                // add singleton LP-desc:
                if (add_singleton_desc)
                    _languageTypes.Add(aq_name, singleton_desc);

                // add id mapping to the singleton LP-desc:
                for (int i = 0; i < identifiers.Length; i++) {
                    _languageIds[identifiers[i]] = singleton_desc;
                }
            }
        }
        /// <summary>
        /// Throws an exception on failure.
        /// </summary>
        /// <exception cref="ArgumentNullException"><paramref name="type"/></exception>
        /// <exception cref="ArgumentException"><paramref name="type"/></exception>
        /// <exception cref="MissingTypeException"><paramref name="languageId"/></exception>
        /// <exception cref="InvalidImplementationException">The language provider's implementation failed to instantiate.</exception>
        public LanguageProvider GetLanguageProvider(Type type)
        {
            Contract.RequiresNotNull(type, "type");
            if (!type.IsSubclassOf(typeof(LanguageProvider))) throw new ArgumentException("Invalid type - should be subclass of LanguageProvider"); // TODO

            LanguageProviderDesc desc = null;

            lock (_languageProvidersLock) {
                if (!_languageTypes.TryGetValue(type.AssemblyQualifiedName, out desc)) {
                    desc = new LanguageProviderDesc(type);
                    _languageTypes[type.AssemblyQualifiedName] = desc;
                }
            }

            if (desc != null) {
                return desc.LoadProvider(this);
            }

            // not found, not registered:
            throw new ArgumentException(Resources.UnknownLanguageProviderType);
        }