/// <summary>
        /// Creates an <see cref="XliffElement"/> that corresponds to the given Xml namespace and name.
        /// </summary>
        /// <param name="name">The Xml namespace and name that represents the element to create.</param>
        /// <returns>The corresponding <see cref="XliffElement"/> or null if one wasn't found.</returns>
        public XliffElement CreateElement(XmlNameInfo name)
        {
            Dictionary <string, Type> typeMap;
            XliffElement result;
            Type         elementType;
            string       key;

            typeMap = this.GetAllXliffElementTypes();
            key     = ReflectorCache.MakeAllXliffElementTypesKey(name);
            if (typeMap.TryGetValue(key, out elementType))
            {
                result = (XliffElement)Reflector.InvokeDefaultConstructor(elementType);
            }
            else
            {
                result = null;
            }

            return(result);
        }
        /// <summary>
        /// Gets all the registered <see cref="XliffElement"/>s using reflection on the types in this assembly.
        /// </summary>
        /// <returns>A dictionary whose key is a combination of the Xml namespace and name that the element is
        /// serialized under. The value is the type of the element.</returns>
        private Dictionary <string, Type> GetAllXliffElementTypes()
        {
            if (!this.allXliffElementTypes.IsValueCreated)
            {
                lock (this.allXliffElementTypes)
                {
                    if (!this.allXliffElementTypes.IsValueCreated)
                    {
                        foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
                        {
                            IDictionary <Type, XmlNameInfo> childrenTypes;

                            childrenTypes = Reflector.GetSchemaChildren(type);
                            foreach (KeyValuePair <Type, XmlNameInfo> pair in childrenTypes)
                            {
                                Type   existingType;
                                string key;

                                key = ReflectorCache.MakeAllXliffElementTypesKey(pair.Value);

                                // This assumes that the names of Xliff elements are the same for a given type. For
                                // instance a Foo element is called xyz in the Xliff and we don't have a Bar element
                                // also called xyz.
                                if (this.allXliffElementTypes.Value.TryGetValue(key, out existingType))
                                {
                                    Debug.Assert(pair.Key == existingType, "The type for an Xml name is inconsistent.");
                                }
                                else
                                {
                                    this.allXliffElementTypes.Value.Add(key, pair.Key);
                                }
                            }
                        }
                    }
                }
            }

            return(this.allXliffElementTypes.Value);
        }
 /// <summary>
 /// Initializes static members of the <see cref="ReflectorCache"/> class.
 /// </summary>
 static ReflectorCache()
 {
     ReflectorCache.ObjectInstance = new ReflectorCache();
 }
 /// <summary>
 /// Initializes static members of the <see cref="ReflectorCache"/> class.
 /// </summary>
 static ReflectorCache()
 {
     ReflectorCache.ObjectInstance = new ReflectorCache();
 }