private XmlDocument LoadAndValidate( string xml )
		{
			using( StringReader stringReader = new StringReader( xml ) )
			{
				XmlTextReader xmlReader = new XmlTextReader( stringReader );
				Configuration cfg = new Configuration();
				return cfg.LoadMappingDocument( xmlReader );
			}
		}
Exemplo n.º 2
0
        /// <summary>Adds mappings to the configuration.</summary>
        /// <param name="cfg">The configuration to add the mappings to.</param>
        /// <param name="name">The resource name of the embedded resource.</param>
        protected virtual void AddMapping(NHibernate.Cfg.Configuration cfg, string name)
        {
            if (!string.IsNullOrEmpty(name))
            {
                using (Stream stream = GetStreamFromName(name))
                {
                    if (stream == null)
                    {
                        throw new ArgumentException("Could not read stream from embedded resource '" + name + "'", "name");
                    }

                    using (StreamReader reader = new StreamReader(stream))
                    {
                        var mappingXml = reader.ReadToEnd();
                        mappingXml = FormatMapping(mappingXml);

                        var xmlReader       = new XmlTextReader(mappingXml, XmlNodeType.Document, null);
                        var mappingDocument = cfg.LoadMappingDocument(xmlReader, "N2");
                        cfg.AddDeserializedMapping(mappingDocument.Document, mappingDocument.Name);
                    }
                }
            }
        }