Castle.ActiveRecord.Framework.Internal.AssemblyXmlGenerator.CreateXmlConfigurations C# (CSharp) Méthode

CreateXmlConfigurations() public méthode

Generate XML from assembly attributes. If it can't find relevant attributes, returns null.
public CreateXmlConfigurations ( Assembly assembly ) : string[]
assembly System.Reflection.Assembly
Résultat string[]
		public string[] CreateXmlConfigurations(Assembly assembly)
		{
			object[] atts = assembly.GetCustomAttributes(true);
			ArrayList namedQueries = new ArrayList();
			ArrayList imports = new ArrayList();
			ArrayList rawXml = new ArrayList();
			foreach (object attribute in atts)
			{
				if (attribute is HqlNamedQueryAttribute)
				{
					namedQueries.Add(attribute);
				}
				else if (attribute is ImportAttribute)
				{
					imports.Add(attribute);
				}
				else if (attribute is RawXmlMappingAttribute)
				{
					string[] result = ((RawXmlMappingAttribute)attribute).GetMappings();
					rawXml.AddRange(result);
				}
			}
			xml.Append(Constants.XmlPI);
			xml.AppendFormat(Constants.XmlHeader, "", "");
			//note that there is a meaning to the order of import vs. named queries, imports must come first.
			foreach (ImportAttribute attribute in imports)
			{
				AppendImport(attribute);
			}
			foreach (HqlNamedQueryAttribute attribute in namedQueries)
			{
				AppendNamedQuery(attribute, assembly);
			}
			xml.AppendLine(Constants.XmlFooter);
			bool hasQueriesOrImportsToAdd = namedQueries.Count != 0 || imports.Count != 0;
			if (hasQueriesOrImportsToAdd)
			{
				rawXml.Insert(0,xml.ToString());
			}
			Reset();
			return (string[])rawXml.ToArray(typeof(string));
		}

Usage Example

		private static void AddXmlToNHibernateFromAssmebliesAttributes(ISessionFactoryHolder holder, ActiveRecordModelCollection models)
		{
			Iesi.Collections.Generic.ISet<Assembly> assembliesGeneratedXmlFor = new HashedSet<Assembly>();
			AssemblyXmlGenerator assemblyXmlGenerator = new AssemblyXmlGenerator();

			foreach (ActiveRecordModel model in models)
			{
				if (assembliesGeneratedXmlFor.Contains(model.Type.Assembly)) 
					continue;

				assembliesGeneratedXmlFor.Add(model.Type.Assembly);

				Configuration config = holder.GetConfiguration(holder.GetRootType(model.Type));
					
				string[] configurations = assemblyXmlGenerator.CreateXmlConfigurations(model.Type.Assembly);

				foreach (string xml in configurations)
				{
					if (xml != string.Empty)
					{
						config.AddXmlString(xml);
					}
				}
			}

			foreach (Assembly assembly in registeredAssemblies)
			{
				if (assembliesGeneratedXmlFor.Contains(assembly))
					continue;

				assembliesGeneratedXmlFor.Add(assembly);

				Configuration config = holder.GetConfiguration(holder.GetRootType(typeof(ActiveRecordBase)));

				string[] configurations = assemblyXmlGenerator.CreateXmlConfigurations(assembly);

				foreach (string xml in configurations)
				{
					if (xml != string.Empty)
					{
						config.AddXmlString(xml);
					}
				}
			}
		}