Update of /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Tool.Net2Hbm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25861/NHibernate.Tool.Net2Hbm Added Files: .cvsignore AssemblyInfo.cs CascadeType.cs ClassAttribute.cs ClassPolymorphismType.cs CollectionCompositeElementAttribute.cs CollectionIndexAttribute.cs CollectionKeyAttribute.cs CollectionManyToManyAttribute.cs DiscriminatorAttribute.cs IdAttribute.cs JoinedSubclassAttribute.cs JoinedSubclassKeyAttribute.cs ListAttribute.cs ManyToOneAttribute.cs MapGenerator.cs NHibernate.Tool.Net2Hbm-1.1.csproj NHibernate.Tool.Net2Hbm.build OuterJoinType.cs PropertyAttribute.cs SetAttribute.cs Size.cs SubclassAttribute.cs TypeKey.cs TypeNode.cs TypeNodeCollection.cs UnsavedValueType.cs VersionAttribute.cs Log Message: Added code from John Morris to enable mapping through attributes instead of xml files. --- NEW FILE: ListAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for ListAttribute. /// </summary> [AttributeUsage(AttributeTargets.Property)] public class ListAttribute : Attribute { #region Member Variables private string m_Table; private string m_Schema; private bool m_IsLazy; private bool m_IsInverse; private CascadeType m_Cascade = CascadeType.None; private string m_SqlWhere; #endregion /// <summary> /// Class constructor. /// </summary> public ListAttribute( string table ) { this.Table = table; } /// <summary> /// Gets and sets the Table. /// </summary> public string Table { get { return m_Table; } set { m_Table = value; } } /// <summary> /// Gets and sets the IsInverse. /// </summary> public bool IsInverse { get { return m_IsInverse; } set { m_IsInverse = value; } } /// <summary> /// Gets and sets the Schema. /// </summary> public string Schema { get { return m_Schema; } set { m_Schema = value; } } /// <summary> /// Gets and sets the IsLazy. /// </summary> public bool IsLazy { get { return m_IsLazy; } set { m_IsLazy = value; } } /// <summary> /// Gets and sets the Cascade. /// </summary> public CascadeType Cascade { get { return m_Cascade; } set { m_Cascade = value; } } /// <summary> /// Gets and sets the SqlWhere. /// </summary> public string SqlWhere { get { return m_SqlWhere; } set { m_SqlWhere = value; } } } } --- NEW FILE: TypeKey.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for TypeKey. /// </summary> internal class TypeKey : IComparable { #region Member Variables private System.Type m_Type; private System.Type m_ExtendsType; #endregion /// <summary> /// Class constructor. /// </summary> public TypeKey( System.Type type ) { m_Type = type; m_ExtendsType = FindExtendsType( type ); } /// <summary> /// Searchs the class hieracrhy for the first class with an attribute that we are looking for. /// </summary> /// <param name="type"></param> /// <returns></returns> private System.Type FindExtendsType( System.Type type ) { //check for joined subclass JoinedSubclassAttribute joinedSubclassAttr = (JoinedSubclassAttribute)Attribute.GetCustomAttribute( type, typeof(JoinedSubclassAttribute), false ); if( joinedSubclassAttr != null ) { if( joinedSubclassAttr.Extends != null ) { return joinedSubclassAttr.Extends; } else { return type.BaseType; } } else //check for subclass { SubclassAttribute subclassAttr = (SubclassAttribute)Attribute.GetCustomAttribute( type, typeof(SubclassAttribute), false ); if( subclassAttr != null ) { if( subclassAttr.Extends != null ) { return subclassAttr.Extends; } else { return type.BaseType; } } else //look to the base class { if( type.BaseType != null ) return FindExtendsType( type.BaseType ); else return null; } } } /// <summary> /// Gets and sets the Type. /// </summary> public System.Type Type { get { return m_Type; } } /// <summary> /// Gets and sets the ExtendsType. /// </summary> public System.Type ExtendsType { get { return m_ExtendsType; } } #region IComparable Members /// <summary> /// Compares the two objects. /// </summary> /// <param name="obj"></param> /// <returns></returns> public int CompareTo( object obj ) { if( obj is TypeKey ) { TypeKey other = (TypeKey)obj; if( this.Type == other.Type ) { return 0; } else if( this.ExtendsType == other.Type ) { return 1; } else if( other.ExtendsType == this.Type ) { return -1; } else { return -1; } } else { throw new ArgumentException(); } } #endregion } } --- NEW FILE: PropertyAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for PropertyAttribute. /// </summary> [AttributeUsage(AttributeTargets.Property)] public class PropertyAttribute : Attribute { #region Member Variables private string m_Column; private System.Type m_Type; private bool m_Update = true; private bool m_Insert = true; private string m_Formula; private int m_Size; #endregion /// <summary> /// Class constructor. /// </summary> public PropertyAttribute() { } /// <summary> /// Class constructor. /// </summary> /// <param name="type"></param> public PropertyAttribute( System.Type type ) { this.Type = type; } /// <summary> /// Class constructor. /// </summary> /// <param name="column"></param> /// <param name="type"></param> public PropertyAttribute( string column, System.Type type ) : this( column ) { this.Type = type; } /// <summary> /// Class constructor. /// </summary> /// <param name="column"></param> /// <param name="type"></param> /// <param name="size"></param> public PropertyAttribute( string column, System.Type type, int size ) : this( column, size ) { this.Type = type; } /// <summary> /// Class constructor. /// </summary> /// <param name="size"></param> public PropertyAttribute( int size ) { this.Size = size; } /// <summary> /// Class constructor. /// </summary> public PropertyAttribute( string column ) { this.Column = column; } /// <summary> /// Class constructor. /// </summary> /// <param name="column"></param> /// <param name="size"></param> public PropertyAttribute( string column, int size ) : this( column ) { this.Size = size; } /// <summary> /// Gets and sets the Size. /// </summary> public int Size { get { return m_Size; } set { m_Size = value; } } /// <summary> /// Gets and sets the Column. /// </summary> public string Column { get { return m_Column; } set { m_Column = value; } } /// <summary> /// Gets and sets the Type. /// </summary> public System.Type Type { get { return m_Type; } set { m_Type = value; } } /// <summary> /// Gets and sets the Update. /// </summary> public bool Update { get { return m_Update; } set { m_Update = value; } } /// <summary> /// Gets and sets the Insert. /// </summary> public bool Insert { get { return m_Insert; } set { m_Insert = value; } } /// <summary> /// Gets and sets the Formula. /// </summary> public string Formula { get { return m_Formula; } set { m_Formula = value; } } } } --- NEW FILE: IdAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for IdAttribute. /// </summary> [AttributeUsage(AttributeTargets.Property)] public class IdAttribute : Attribute { #region Member Variables private string m_Column; private UnsavedValueType m_UnsavedValueType = UnsavedValueType.Null; private string m_UnsavedValue; private System.Type m_Generator; #endregion /// <summary> /// Class constructor. /// </summary> public IdAttribute( string column, System.Type generator ) { this.Column = column; this.Generator = generator; } /// <summary> /// Gets and sets the Column. /// </summary> public string Column { get { return m_Column; } set { m_Column = value; } } /// <summary> /// Gets and sets the UnsavedValueType. /// </summary> public UnsavedValueType UnsavedValueType { get { return m_UnsavedValueType; } set { m_UnsavedValueType = value; } } /// <summary> /// Gets and sets the UnsavedValue. /// </summary> public string UnsavedValue { get { return m_UnsavedValue; } set { m_UnsavedValue = value; } } /// <summary> /// Gets and sets the Generator. /// </summary> public System.Type Generator { get { return m_Generator; } set { m_Generator = value; } } } } --- NEW FILE: SetAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for SetAttribute. /// </summary> [AttributeUsage(AttributeTargets.Property)] public class SetAttribute : Attribute { #region Member Variables private string m_Table; private string m_Schema; private bool m_IsLazy; private CascadeType m_Cascade = CascadeType.None; private string m_SqlWhere; #endregion /// <summary> /// Class constructor. /// </summary> public SetAttribute( string table ) { this.Table = table; } /// <summary> /// Gets and sets the Table. /// </summary> public string Table { get { return m_Table; } set { m_Table = value; } } /// <summary> /// Gets and sets the Schema. /// </summary> public string Schema { get { return m_Schema; } set { m_Schema = value; } } /// <summary> /// Gets and sets the IsLazy. /// </summary> public bool IsLazy { get { return m_IsLazy; } set { m_IsLazy = value; } } /// <summary> /// Gets and sets the Cascade. /// </summary> public CascadeType Cascade { get { return m_Cascade; } set { m_Cascade = value; } } /// <summary> /// Gets and sets the SqlWhere. /// </summary> public string SqlWhere { get { return m_SqlWhere; } set { m_SqlWhere = value; } } } } --- NEW FILE: ManyToOneAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for ManyToOneAttribute. /// </summary> [AttributeUsage(AttributeTargets.Property)] public class ManyToOneAttribute : Attribute { #region Member Variables private string m_Column; private System.Type m_Type; private bool m_Update = true; private bool m_Insert = true; private OuterJoinType m_OuterJoin; private CascadeType m_Cascade; private bool m_Inheritable = true; #endregion /// <summary> /// Class constructor. /// </summary> /// <param name="type"></param> public ManyToOneAttribute( System.Type type ) { this.Type = type; } /// <summary> /// Class constructor. /// </summary> public ManyToOneAttribute( string column ) { this.Column = column; } /// <summary> /// Class constructor. /// </summary> public ManyToOneAttribute( string column, System.Type type ) : this( column ) { this.Type = type; } /// <summary> /// Gets and sets the Column. /// </summary> public string Column { get { return m_Column; } set { m_Column = value; } } /// <summary> /// Gets and sets the Update. /// </summary> public bool Update { get { return m_Update; } set { m_Update = value; } } /// <summary> /// Gets and sets the Insert. /// </summary> public bool Insert { get { return m_Insert; } set { m_Insert = value; } } /// <summary> /// Gets and sets the OuterJoin. /// </summary> public OuterJoinType OuterJoin { get { return m_OuterJoin; } set { m_OuterJoin = value; } } /// <summary> /// Gets and sets the Cascade. /// </summary> public CascadeType Cascade { get { return m_Cascade; } set { m_Cascade = value; } } /// <summary> /// Gets and sets the Inheritable. /// </summary> public bool Inheritable { get { return m_Inheritable; } set { m_Inheritable = value; } } /// <summary> /// Gets and sets the Type. /// </summary> public System.Type Type { get { return m_Type; } set { m_Type = value; } } } } --- NEW FILE: Size.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for Size. /// </summary> public class Size { #region Member Variables public const int Max = 2147483647; #endregion /// <summary> /// Class constructor. /// </summary> private Size() { } } } --- NEW FILE: AssemblyInfo.cs --- using System.Reflection; using System.Runtime.CompilerServices; //------------------------------------------------------------------------------ // <autogenerated> // This code was generated by a tool. // Runtime Version: 1.1.4322.573 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </autogenerated> //------------------------------------------------------------------------------ [assembly: AssemblyTitleAttribute("NHibernate.Tool.Net2Hbm for Microsoft .NET Framework 1.1")] [assembly: AssemblyDescriptionAttribute("An attribute library which provides support for custom attributes that can be use" + "d in the generation of NHibernate mapping files.")] [assembly: AssemblyCompanyAttribute("nhibernate.sourceforge.net")] [assembly: AssemblyProductAttribute("NHibernate.Tool.Net2Hbm")] [assembly: AssemblyCopyrightAttribute("Licensed under LGPL.")] [assembly: AssemblyVersionAttribute("0.5.0.0")] [assembly: AssemblyInformationalVersionAttribute("0.5")] [assembly: AssemblyFileVersionAttribute("0.5.0.0")] //[assembly: AssemblyKeyFileAttribute("..\\NHibernate.snk")] --- NEW FILE: CollectionKeyAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for CollectionKeyAttribute. /// </summary> [AttributeUsage(AttributeTargets.Property)] public class CollectionKeyAttribute : Attribute { #region Member Variables private string m_Column; #endregion /// <summary> /// Class constructor. /// </summary> public CollectionKeyAttribute( string column ) { this.Column = column; } /// <summary> /// Gets and sets the Column. /// </summary> public string Column { get { return m_Column; } set { m_Column = value; } } } } --- NEW FILE: UnsavedValueType.cs --- using System; using System.Xml.Serialization; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for UnsavedValueType. /// </summary> public enum UnsavedValueType { [XmlEnum("null")] Null, [XmlEnum("any")] Any, [XmlEnum("none")] None, Specified } } --- NEW FILE: ClassPolymorphismType.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for ClassPolymorphismType. /// </summary> public enum ClassPolymorphismType { Implicit = 0, Explicit = 1 } } --- NEW FILE: NHibernate.Tool.Net2Hbm-1.1.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{FD72BBE4-AA77-459A-9F1D-6B7C7143CF2A}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "NHibernate.Tool.Net2Hbm" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "NHibernate.Tool.Net2Hbm" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> </References> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CascadeType.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ClassAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ClassPolymorphismType.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CollectionCompositeElementAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CollectionIndexAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CollectionKeyAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CollectionManyToManyAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "DiscriminatorAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "IdAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "JoinedSubclassAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "JoinedSubclassKeyAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ListAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ManyToOneAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MapGenerator.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "NHibernate.Tool.Net2Hbm.build" BuildAction = "None" /> <File RelPath = "OuterJoinType.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "PropertyAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "SetAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Size.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "SubclassAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TypeKey.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TypeNode.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TypeNodeCollection.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "UnsavedValueType.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "VersionAttribute.cs" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </CSHARP> </VisualStudioProject> --- NEW FILE: CascadeType.cs --- using System; using System.Xml.Serialization; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for Cascade. /// </summary> public enum CascadeType { [XmlEnum("none")] None, [XmlEnum("all")] All, [XmlEnum("save-update")] SaveUpdate, [XmlEnum("delete")] Delete } } --- NEW FILE: NHibernate.Tool.Net2Hbm.build --- <?xml version="1.0" ?> <project name="NHibernate.Tool.Net2Hbm" default="build" xmlns="http://nant.sf.net/schemas/nant-0.84.win32.net-1.0.xsd" > <!-- Required properties: * build.dir - (path) root level to build to, assemblies will go in ${build.dir}/bin * build.debug - (true|false) debug build? * current.build.defines - framework-specific build defines * project.version - full project version * project.version.major - the major number of the build * project.version.minor - the minor number of the build * project.version.build - the build number * sign - (true|false)indicates if the Assembly should be signed. * clover.enabled - (true|false) indicates if Clover.NET should handle the build * clover.src - location of the clovered source to be stored at from the root of NHibernateContrib * clover.db - location of the coverage db from the root of NHibernateContrib --> <if propertytrue="clover.enabled"> <loadtasks assembly="${clover.home}/CloverNAnt-0.84.dll" /> </if> <property name="keyFile" value="..\NHibernate.snk" /> <target name="build" description="Build NHibernate.Tool.Net2Hbm"> <if propertytrue="clover.enabled"> <clover-setup initstring="..\..\${clover.db}" builddir="..\..\${clover.src}\${nant.project.name}" enabled="${clover.enabled}" flushinterval="1000" /> </if> <!-- ensure the AssemblyInfo is writable --> <attrib file="AssemblyInfo.cs" readonly="false" /> <asminfo output="AssemblyInfo.cs" language="CSharp"> <imports> <import name="System.Reflection" /> <import name="System.Runtime.CompilerServices" /> </imports> <attributes> <attribute type="AssemblyTitleAttribute" value="${nant.project.name} for ${current.runtime.description}" /> <attribute type="AssemblyDescriptionAttribute" value="An attribute library which provides support for custom attributes that can be used in the generation of NHibernate mapping files." /> <attribute type="AssemblyCompanyAttribute" value="nhibernate.sourceforge.net" /> <attribute type="AssemblyProductAttribute" value="${nant.project.name}" /> <attribute type="AssemblyCopyrightAttribute" value="Licensed under LGPL." /> <attribute type="AssemblyVersionAttribute" value="${project.version}" /> <attribute type="AssemblyInformationalVersionAttribute" value="${project.version.major}.${project.version.minor}" /> <attribute type="AssemblyFileVersionAttribute" value="${project.version}" /> <attribute type="AssemblyKeyFileAttribute" value="${keyFile}" if="${sign}"/> </attributes> </asminfo> <csc target="library" define="${current.build.defines}" debug="${build.debug}" output="${build.dir}/bin/${nant.project.name}.dll" doc="${build.dir}/bin/${nant.project.name}.xml" > <sources failonempty="true"> <includes name="**/*.cs" /> </sources> <references basedir="${build.dir}/bin"> <includes name="${nant.settings.currentframework.frameworkassemblydirectory}/System.dll" /> <includes name="${nant.settings.currentframework.frameworkassemblydirectory}/System.Data.dll" /> <includes name="${nant.settings.currentframework.frameworkassemblydirectory}/System.XML.dll" /> </references> </csc> </target> </project> --- NEW FILE: CollectionIndexAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for CollectionIndexAttribute. /// </summary> [AttributeUsage(AttributeTargets.Property)] public class CollectionIndexAttribute : Attribute { #region Member Variables private string m_Column; #endregion /// <summary> /// Class constructor. /// </summary> public CollectionIndexAttribute( string column ) { this.Column = column; } /// <summary> /// Gets and sets the Column. /// </summary> public string Column { get { return m_Column; } set { m_Column = value; } } } } --- NEW FILE: TypeNode.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for TypeNode. /// </summary> internal class TypeNode { #region Member Variables private System.Type m_Type; private TypeNodeCollection m_Nodes; #endregion /// <summary> /// Class constructor. /// </summary> public TypeNode( System.Type type ) { m_Type = type; m_Nodes = new TypeNodeCollection(); } /// <summary> /// Gets and sets the Nodes. /// </summary> public TypeNodeCollection Nodes { get { return m_Nodes; } } /// <summary> /// Gets and sets the Type. /// </summary> public System.Type Type { get { return m_Type; } set { m_Type = value; } } } } --- NEW FILE: .cvsignore --- bin obj .#* *.user *.xsx --- NEW FILE: JoinedSubclassAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for JoinedSubclassAttribute. /// </summary> [AttributeUsage(AttributeTargets.Class)] public class JoinedSubclassAttribute : Attribute { #region Member Variables private System.Type m_Extends; // private System.Type m_Proxy; private bool m_DynamicUpdate; private bool m_DynamicInsert; private string m_Table; #endregion /// <summary> /// Class constructor. /// </summary> public JoinedSubclassAttribute( string table ) { this.Table = table; } /// <summary> /// Class constructor. /// </summary> /// <param name="table"></param> /// <param name="extends"></param> public JoinedSubclassAttribute( string table, System.Type extends ) : this( table ) { this.Extends = extends; } /// <summary> /// Gets and sets the Table. /// </summary> public string Table { get { return m_Table; } set { m_Table = value; } } /// <summary> /// Gets and sets the Extends. /// </summary> public System.Type Extends { get { return m_Extends; } set { m_Extends = value; } } /// <summary> /// Gets and sets the DynamicUpdate. /// </summary> public bool DynamicUpdate { get { return m_DynamicUpdate; } set { m_DynamicUpdate = value; } } /// <summary> /// Gets and sets the DynamicInsert. /// </summary> public bool DynamicInsert { get { return m_DynamicInsert; } set { m_DynamicInsert = value; } } // /// <summary> // /// Gets and sets the Proxy. // /// </summary> // public System.Type Proxy // { // get { return m_Proxy; } // set { m_Proxy = value; } // } } } --- NEW FILE: OuterJoinType.cs --- using System; using System.Xml.Serialization; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for OuterJoinType. /// </summary> public enum OuterJoinType { [XmlEnum("auto")] Auto, [XmlEnum("true")] True, [XmlEnum("false")] False } } --- NEW FILE: ClassAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for ClassAttribute. /// </summary> [AttributeUsage(AttributeTargets.Class)] public class ClassAttribute : Attribute { #region Member Variables private string m_Table; private bool m_Mutable; private string m_Schema; private string m_DiscriminatorValue; // private System.Type m_Proxy; private bool m_DynamicUpdate; private bool m_DynamicInsert; private ClassPolymorphismType m_Polymorphism = ClassPolymorphismType.Implicit; private string m_SqlWhere; private System.Type m_Persister; #endregion /// <summary> /// Class constructor. /// </summary> public ClassAttribute( string table ) { this.Table = table; } /// <summary> /// Gets and sets the Table. /// </summary> public string Table { get { return m_Table; } set { m_Table = value; } } /// <summary> /// Gets and sets the DiscriminatorValue. /// </summary> public string DiscriminatorValue { get { return m_DiscriminatorValue; } set { m_DiscriminatorValue = value; } } /// <summary> /// Gets and sets the Mutable. /// </summary> public bool Mutable { get { return m_Mutable; } set { m_Mutable = value; } } /// <summary> /// Gets and sets the DynamicUpdate. /// </summary> public bool DynamicUpdate { get { return m_DynamicUpdate; } set { m_DynamicUpdate = value; } } /// <summary> /// Gets and sets the DynamicInsert. /// </summary> public bool DynamicInsert { get { return m_DynamicInsert; } set { m_DynamicInsert = value; } } /// <summary> /// Gets and sets the Polymorphism. /// </summary> public ClassPolymorphismType Polymorphism { get { return m_Polymorphism; } set { m_Polymorphism = value; } } /// <summary> /// Gets and sets the SqlWhere. /// </summary> public string SqlWhere { get { return m_SqlWhere; } set { m_SqlWhere = value; } } /// <summary> /// Gets and sets the Persister. /// </summary> public System.Type Persister { get { return m_Persister; } set { m_Persister = value; } } /// <summary> /// Gets and sets the Schema. /// </summary> public string Schema { get { return m_Schema; } set { m_Schema = value; } } // /// <summary> // /// Gets and sets the Proxy. // /// </summary> // public System.Type Proxy // { // get { return m_Proxy; } // set { m_Proxy = value; } // } } } --- NEW FILE: JoinedSubclassKeyAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for JoinedSubclassKeyAttribute. /// </summary> [AttributeUsage(AttributeTargets.Class)] public class JoinedSubclassKeyAttribute : Attribute { #region Member Variables private string m_Column; #endregion /// <summary> /// Class constructor. /// </summary> public JoinedSubclassKeyAttribute( string column ) { this.Column = column; } /// <summary> /// Gets and sets the Column. /// </summary> public string Column { get { return m_Column; } set { m_Column = value; } } } } --- NEW FILE: CollectionCompositeElementAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for CollectionCompositeElementAttribute. /// </summary> [AttributeUsage(AttributeTargets.Property)] public class CollectionCompositeElementAttribute : Attribute { #region Member Variables private System.Type m_Type; #endregion /// <summary> /// Class constructor. /// </summary> public CollectionCompositeElementAttribute( System.Type type ) { this.Type = type; } /// <summary> /// Gets and sets the Type. /// </summary> public System.Type Type { get { return m_Type; } set { m_Type = value; } } } } --- NEW FILE: DiscriminatorAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for DiscriminatorAttribute. /// </summary> [AttributeUsage(AttributeTargets.Class)] public class DiscriminatorAttribute : Attribute { #region Member Variables private string m_Column; private System.Type m_Type; private bool m_Force; #endregion /// <summary> /// Class constructor. /// </summary> public DiscriminatorAttribute( string column, System.Type type ) { m_Column = column; m_Type = type; } /// <summary> /// Class constructor. /// </summary> /// <param name="column"></param> /// <param name="force"></param> public DiscriminatorAttribute( string column, System.Type type, bool force ) : this( column, type ) { m_Force = force; } /// <summary> /// Gets and sets the Column. /// </summary> public string Column { get { return m_Column; } set { m_Column = value; } } /// <summary> /// Gets and sets the Force. /// </summary> public bool Force { get { return m_Force; } set { m_Force = value; } } /// <summary> /// Gets and sets the Type. /// </summary> public System.Type Type { get { return m_Type; } set { m_Type = value; } } } } --- NEW FILE: CollectionManyToManyAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for CollectionManyToManyAttribute. /// </summary> [AttributeUsage(AttributeTargets.Property)] public class CollectionManyToManyAttribute : Attribute { #region Member Variables private string m_Column; private OuterJoinType m_OuterJoin; private System.Type m_Type; #endregion /// <summary> /// Class constructor. /// </summary> public CollectionManyToManyAttribute( string column, System.Type type ) { this.Column = column; this.Type = type; } /// <summary> /// Gets and sets the Column. /// </summary> public string Column { get { return m_Column; } set { m_Column = value; } } /// <summary> /// Gets and sets the OuterJoin. /// </summary> public OuterJoinType OuterJoin { get { return m_OuterJoin; } set { m_OuterJoin = value; } } /// <summary> /// Gets and sets the Type. /// </summary> public System.Type Type { get { return m_Type; } set { m_Type = value; } } } } --- NEW FILE: MapGenerator.cs --- using System; using System.Collections; using System.Reflection; using System.IO; using System.Xml; using System.Xml.Serialization; using System.Text.RegularExpressions; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for MapGenerator. /// </summary> public sealed class MapGenerator { #region Member Variables private SortedList m_Types; private Regex m_AssemblyQualifiedNameRegex; private const string AssemblyQualifiedPattern = @"^(?<type>[\w\.\[\]]+),\s(?<assembly>[\w\.]+),\sVersion=(?<version>[\d\.]+),\sCulture=(?<culture>[\w\.]+),\sPublicKeyToken=(?<key>[\w]+)$"; #endregion /// <summary> /// Class constructor. /// </summary> public MapGenerator() { m_Types = new SortedList(); m_AssemblyQualifiedNameRegex = new Regex( MapGenerator.AssemblyQualifiedPattern, RegexOptions.None ); } /// <summary> /// Adds the assembly's types to the generator. /// </summary> /// <param name="assembly"></param> public void AddAssembly( string assembly ) { this.AddAssembly( Assembly.Load( assembly ) ); } /// <summary> /// Adds the assembly's types to the generator. /// </summary> /// <param name="assembly"></param> public void AddAssembly( Assembly assembly ) { System.Type[] types = assembly.GetTypes(); foreach( System.Type type in types ) { if( type.IsClass ) { AddClass( type ); } } } /// <summary> /// Adds the class type to the generator. /// </summary> /// <param name="type"></param> public void AddClass( System.Type type ) { if( type.IsClass ) { if( type.IsDefined( typeof(ClassAttribute), true ) || type.IsDefined( typeof(JoinedSubclassAttribute), true ) || type.IsDefined( typeof(SubclassAttribute), true ) ) { m_Types.Add( new TypeKey( type ), type ); } } else { throw new ArgumentException( "Invalid type. Only class types can be added to the generator.", "type" ); } } /// <summary> /// Generates the mapping. /// </summary> /// <param name="map"></param> public void Generate( Stream map ) { // //create the stream we will use to write the xml into // XmlWriter writer = new XmlTextWriter( map, System.Text.Encoding.UTF8 ); writer.WriteComment( String.Format( "Generated by Net2Hbm on {0}.", DateTime.Now ) ); writer.WriteStartElement("hibernate-mapping", "urn:nhibernate-mapping-2.0" ); // //write each type into the stream // TypeNodeCollection nodes = BuildTypeDependencyTree( m_Types ); foreach( TypeNode node in nodes ) { WriteTypeNode( writer, node ); } writer.WriteEndElement(); //</hibernate-mapping> writer.Flush(); } /// <summary> /// Writes the type's map information into the xml writer. /// </summary> /// <param name="writer"></param> /// <param name="node"></param> private void WriteTypeNode( XmlWriter writer, TypeNode node ) { bool looking = true; System.Type type = node.Type; while( looking ) { if( Attribute.IsDefined( type, typeof(ClassAttribute), false ) ) { writer.WriteComment( GetShortTypeName( node.Type ) ); WriteClass( writer, node, type ); looking = false; } else if( Attribute.IsDefined( type, typeof(JoinedSubclassAttribute), false ) ) { writer.WriteComment( GetShortTypeName( node.Type ) ); WriteJoinedSubclass( writer, node, type ); looking = false; } else if( Attribute.IsDefined( type, typeof(SubclassAttribute), false ) ) { writer.WriteComment( GetShortTypeName( node.Type ) ); WriteSubclass( writer, node, type ); looking = false; } else { type = type.BaseType; looking = true; } } } /// <summary> /// Writes the collection. /// </summary> /// <param name="writer"></param> /// <param name="type"></param> private void WriteCollections( XmlWriter writer, System.Type type, bool declaredOnly ) { PropertyInfo[] listProps = FindAttributedProperties( typeof(ListAttribute), type, declaredOnly ); foreach( PropertyInfo listProp in listProps ) { WriteList( writer, listProp ); } PropertyInfo[] setProps = FindAttributedProperties( typeof(SetAttribute), type, declaredOnly ); foreach( PropertyInfo setProp in setProps ) { WriteSet( writer, setProp ); } } /// <summary> /// Writes the list. /// </summary> /// <param name="writer"></param> /// <param name="parentNode"></param> private void WriteList( XmlWriter writer, PropertyInfo property ) { ListAttribute attribute = (ListAttribute)Attribute.GetCustomAttribute( property, typeof(ListAttribute) ); writer.WriteStartElement( "list" ); writer.WriteAttributeString( "name", property.Name ); writer.WriteAttributeString( "table", attribute.Table ); if( attribute.IsLazy ) writer.WriteAttributeString( "lazy", "true" ); if( attribute.IsInverse ) writer.WriteAttributeString( "inverse", "true" ); WriteCollectionKey( writer, property ); WriteCollectionIndex( writer, property ); WriteCollectionCompositeElement( writer, property ); WriteCollectionManyToMany( writer, property ); writer.WriteEndElement(); //<list> } /// <summary> /// Writes the list. /// </summary> /// <param name="writer"></param> /// <param name="parentNode"></param> private void WriteSet( XmlWriter writer, PropertyInfo property ) { SetAttribute attribute = (SetAttribute)Attribute.GetCustomAttribute( property, typeof(SetAttribute) ); writer.WriteStartElement( "set" ); writer.WriteAttributeString( "name", property.Name ); writer.WriteAttributeString( "table", attribute.Table ); if( attribute.IsLazy ) writer.WriteAttributeString( "lazy", "true" ); WriteCollectionKey( writer, property ); WriteCollectionCompositeElement( writer, property ); writer.WriteEndElement(); //<list> } /// <summary> /// Writes the collection key. /// </summary> /// <param name="writer"></param> /// <param name="property"></param> private void WriteCollectionKey( XmlWriter writer, PropertyInfo property ) { CollectionKeyAttribute attribute = (CollectionKeyAttribute)Attribute.GetCustomAttribute( property, typeof(CollectionKeyAttribute) ); if( attribute != null ) { writer.WriteStartElement( "key" ); writer.WriteAttributeString( "column", attribute.Column ); writer.WriteEndElement(); //</key> } } /// <summary> /// Writes the collection index. /// </summary> /// <param name="writer"></param> /// <param name="type"></param> private void WriteDiscriminator( XmlWriter writer, System.Type type ) { DiscriminatorAttribute attribute = (DiscriminatorAttribute)Attribute.GetCustomAttribute( type, typeof(DiscriminatorAttribute) ); if( attribute != null ) { writer.WriteStartElement( "discriminator" ); writer.WriteAttributeString( "column", attribute.Column ); writer.WriteAttributeString( "type", GetShortTypeName( attribute.Type ) ); if( attribute.Force ) writer.WriteAttributeString( "force", "true" ); writer.WriteEndElement(); //</discriminator> } } /// <summary> /// Writes the collection index. /// </summary> /// <param name="writer"></param> /// <param name="property"></param> private void WriteCollectionIndex( XmlWriter writer, PropertyInfo property ) { CollectionIndexAttribute attribute = (CollectionIndexAttribute)Attribute.GetCustomAttribute( property, typeof(CollectionIndexAttribute) ); if( attribute != null ) { writer.WriteStartElement( "index" ); writer.WriteAttributeString( "column", attribute.Column ); writer.WriteEndElement(); //</index> } } /// <summary> /// Writes the collection composite element. /// </summary> /// <param name="writer"></param> /// <param name="property"></param> private void WriteCollectionCompositeElement( XmlWriter writer, PropertyInfo property ) { CollectionCompositeElementAttribute attribute = (CollectionCompositeElementAttribute)Attribute.GetCustomAttribute( property, typeof(CollectionCompositeElementAttribute) ); if( attribute != null ) { writer.WriteStartElement( "composite-element" ); writer.WriteAttributeString( "class", GetShortTypeName( attribute.Type ) ); WriteProperties( writer, attribute.Type, false ); writer.WriteEndElement(); //</composite-element> } } /// <summary> /// Writes the collection many to many. /// </summary> /// <param name="writer"></param> /// <param name="property"></param> private void WriteCollectionManyToMany( XmlWriter writer, PropertyInfo property ) { CollectionManyToManyAttribute attribute = (CollectionManyToManyAttribute)Attribute.GetCustomAttribute( property, typeof(CollectionManyToManyAttribute) ); if( attribute != null ) { writer.WriteStartElement( "many-to-many" ); writer.WriteAttributeString( "column", attribute.Column ); writer.WriteAttributeString( "class", GetShortTypeName( attribute.Type ) ); writer.WriteEndElement(); //</many-to-many> } } /// <summary> /// Writes the subclass. /// </summary> private void WriteSubclass( XmlWriter writer, TypeNode node, System.Type type ) { SubclassAttribute attribute = (SubclassAttribute)Attribute.GetCustomAttribute( type, typeof(SubclassAttribute), true ); writer.WriteStartElement( "subclass" ); writer.WriteAttributeString( "name", GetShortTypeName( node.Type ) ); if( attribute.DiscriminatorValue != null ) writer.WriteAttributeString( "discriminator-value", attribute.DiscriminatorValue ); if( attribute.DynamicInsert ) writer.WriteAttributeString( "dynamic-insert", "true" ); if( attribute.DynamicUpdate ) writer.WriteAttributeString( "dynamic-update", "true" ); WriteProperties( writer, type, true ); WriteCollections( writer, type, true ); WriteAssociations( writer, type, true ); foreach( TypeNode childNode in node.Nodes ) { WriteTypeNode( writer, childNode ); } writer.WriteEndElement(); //</subclass> } /// <summary> /// Writes the class. /// </summary> private void WriteClass( XmlWriter writer, TypeNode node, System.Type type ) { ClassAttribute attribute = (ClassAttribute)Attribute.GetCustomAttribute( type, typeof(ClassAttribute), true ); writer.WriteStartElement( "class" ); writer.WriteAttributeString( "name", GetShortTypeName( node.Type ) ); writer.WriteAttributeString( "table", attribute.Table ); if( attribute.DiscriminatorValue != null ) writer.WriteAttributeString( "discriminator-value", attribute.DiscriminatorValue ); if( attribute.SqlWhere != null ) writer.WriteAttributeString( "where", attribute.SqlWhere ); WriteId( writer, node.Type ); WriteDiscriminator( writer, type ); WriteVersion( writer, type ); WriteProperties( writer, type, false ); WriteCollections( writer, type, false ); WriteAssociations( writer, type, false ); foreach( TypeNode childNode in node.Nodes ) { WriteTypeNode( writer, childNode ); } writer.WriteEndElement(); //</class> } /// <summary> /// Writes the property. /// </summary> /// <param name="writer"></param> /// <param name="property"></param> private void WriteProperty( XmlWriter writer, PropertyInfo property ) { PropertyAttribute attribute = (PropertyAttribute)Attribute.GetCustomAttribute( property, typeof(PropertyAttribute) ); writer.WriteStartElement( "property" ); writer.WriteAttributeString( "name", property.Name ); writer.WriteAttributeString( "column", attribute.Column == null ? property.Name : attribute.Column ); string typeName = null; if( attribute.Type != null ) typeName = GetShortTypeName( attribute.Type ); else typeName = GetShortTypeName( property.PropertyType ); if( attribute.Size > 0 ) { writer.WriteAttributeString( "type", String.Format( "{0}({1})", typeName, attribute.Size ) ); } else { writer.WriteAttributeString( "type", typeName ); } if( !attribute.Insert ) writer.WriteAttributeString( "insert", "false" ); if( !attribute.Update ) writer.WriteAttributeString( "update", "false" ); //if( attribute.Size > 0 ) // writer.WriteAttributeString( "length", attribute.Size.ToString() ); writer.WriteEndElement(); //</property> } /// <summary> /// Writers the properties. /// </summary> /// <param name="writer"></param> /// <param name="parentNode"></param> private void WriteProperties( XmlWriter writer, System.Type type, bool declaredOnly ) { PropertyInfo[] properties = FindAttributedProperties( typeof(PropertyAttribute), type, declaredOnly ); foreach( PropertyInfo property in properties ) { WriteProperty( writer, property ); } } /// <summary> /// Writes the assoications. /// </summary> /// <param name="writer"></param> /// <param name="type"></param> private void WriteAssociations( XmlWriter writer, System.Type type, bool declaredOnly ) { PropertyInfo[] properties = FindAttributedProperties( typeof(ManyToOneAttribute), type, declaredOnly ); foreach( PropertyInfo property in properties ) { WriteManyToOne( writer, property ); } } /// <summary> /// Writes the many to one association. /// </summary> /// <param name="writer"></param> /// <param name="property"></param> private void WriteManyToOne( XmlWriter writer, PropertyInfo property ) { ManyToOneAttribute attribute = (ManyToOneAttribute)Attribute.GetCustomAttribute( property, typeof(ManyToOneAttribute) ); if( attribute.Inheritable || ( !attribute.Inheritable && ( property.DeclaringType == property.ReflectedType ) ) ) { writer.WriteStartElement( "many-to-one" ); writer.WriteAttributeString( "name", property.Name ); writer.WriteAttributeString( "column", attribute.Column == null ? property.Name : attribute.Column ); string typeName = null; if( attribute.Type != null ) typeName = GetShortTypeName( attribute.Type ); else typeName = GetShortTypeName( property.PropertyType ); writer.WriteAttributeString( "class", typeName ); if( attribute.Cascade != CascadeType.None ) writer.WriteAttributeString( "cascade", GetXmlEnumValue( typeof(CascadeType), attribute.Cascade ) ); if( attribute.OuterJoin != OuterJoinType.Auto ) writer.WriteAttributeString( "outer-join", GetXmlEnumValue( typeof(OuterJoinType), attribute.OuterJoin ) ); if( !attribute.Insert ) writer.WriteAttributeString( "insert", "false" ); if( !attribute.Update ) writer.WriteAttributeString( "update", "false" ); writer.WriteEndElement(); //</many-to-one> } } /// <summary> /// Writes the version. /// </summary> /// <param name="writer"></param> /// <param name="parentNode"></param> private void WriteVersion( XmlWriter writer, System.Type type ) { PropertyInfo property = FindAttributedProperty( typeof(VersionAttribute), type ); if( property != null ) { VersionAttribute attribute = (VersionAttribute)Attribute.GetCustomAttribute( property, typeof(VersionAttribute), false ); writer.WriteStartElement( "version" ); writer.WriteAttributeString( "name", property.Name ); writer.WriteAttributeString( "column", attribute.Column ); writer.WriteAttributeString( "type", GetShortTypeName( property.PropertyType ) ); writer.WriteEndElement(); //</version> } } /// <summary> /// Writes the id. /// </summary> /// <param name="writer"></param> /// <param name="parentNode"></param> private void WriteId( XmlWriter writer, System.Type type ) { PropertyInfo property = FindAttributedProperty( typeof(IdAttribute), type ); if( property == null ) throw new Exception( "Missing required IdAttribute." ); IdAttribute attribute = (IdAttribute)Attribute.GetCustomAttribute( property, typeof(IdAttribute), false ); writer.WriteStartElement( "id" ); writer.WriteAttributeString( "name", property.Name ); writer.WriteAttributeString( "type", GetShortTypeName( property.PropertyType ) ); writer.WriteAttributeString( "column", attribute.Column ); if( attribute.UnsavedValueType == UnsavedValueType.Specified ) writer.WriteAttributeString( "unsaved-value", attribute.UnsavedValue ); else writer.WriteAttributeString( "unsaved-value", GetXmlEnumValue( typeof(UnsavedValueType), attribute.UnsavedValueType ) ); writer.WriteStartElement("generator"); writer.WriteAttributeString( "class", GetShortTypeName( attribute.Generator ) ); writer.WriteEndElement(); //</generator> writer.WriteEndElement(); //</id> } /// <summary> /// Writes the joined subclass. /// </summary> private void WriteJoinedSubclass( XmlWriter writer, TypeNode node, System.Type type ) { JoinedSubclassAttribute attribute = (JoinedSubclassAttribute)Attribute.GetCustomAttribute( type, typeof(JoinedSubclassAttribute), true ); writer.WriteStartElement( "joined-subclass" ); writer.WriteAttributeString( "name", GetShortTypeName( node.Type ) ); writer.WriteAttributeString( "table", attribute.Table ); WriteJoinedSubclassKey( writer, type ); WriteProperties( writer, type, true ); WriteCollections( writer, type, true ); WriteAssociations( writer, type, true ); foreach( TypeNode childNode in node.Nodes ) { WriteTypeNode( writer, childNode ); } writer.WriteEndElement(); //</joined-subclass> } /// <summary> /// Writes the joined subclass key. /// </summary> /// <param name="writer"></param> /// <param name="parentNode"></param> private void WriteJoinedSubclassKey( XmlWriter writer, System.Type type ) { JoinedSubclassKeyAttribute attribute = (JoinedSubclassKeyAttribute)Attribute.GetCustomAttribute( type, typeof(JoinedSubclassKeyAttribute), false ); writer.WriteStartElement( "key" ); writer.WriteAttributeString( "column", attribute.Column ); writer.WriteEndElement(); //</key> } /// <summary> /// Constructs an array of TypeNodes. /// </summary> /// <param name="list"></param> /// <returns></returns> private TypeNodeCollection BuildTypeDependencyTree( SortedList list ) { TypeNodeCollection nodes = new TypeNodeCollection(); Hashtable lookup = new Hashtable(); foreach( DictionaryEntry entry in list ) { TypeKey key = (TypeKey)entry.Key; TypeNode node = new TypeNode( key.Type ); lookup.Add( node.Type, node ); if( key.ExtendsType != null ) { TypeNode extendNode = (TypeNode)lookup[key.ExtendsType]; extendNode.Nodes.Add( node ); } else { nodes.Add( node ); } } return nodes; } /// <summary> /// Searches the members of the class for any member with the attribute defined. /// </summary> /// <param name="attribute"></param> /// <param name="type"></param> /// <returns></returns> private PropertyInfo FindAttributedProperty( System.Type attrType, System.Type classType ) { System.Type type = classType; while( ( type == classType ) || ( ( type != null ) && ( !type.IsDefined( typeof(ClassAttribute), false ) ) && ( !type.IsDefined( typeof(SubclassAttribute), false ) ) && ( !type.IsDefined( typeof(JoinedSubclassAttribute), false ) ) ) ) { PropertyInfo[] properties = type.GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic ); foreach( PropertyInfo property in properties ) { if( property.IsDefined( attrType, false ) ) { return property; } } type = type.BaseType; } return null; } /// <summary> /// Searches the members of the class for any member with the attribute defined. /// </summary> /// <param name="attrType"></param> /// <param name="classType"></param> /// <returns></returns> private PropertyInfo[] FindAttributedProperties( System.Type attrType, System.Type classType, bool declaredOnly ) { ArrayList list = new ArrayList(); BindingFlags bindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; /*if( declaredOnly )*/ bindings = bindings | BindingFlags.DeclaredOnly; System.Type type = classType; while( ( type == classType ) || ( ( type != null ) && ( !type.IsDefined( typeof(ClassAttribute), false ) ) && ( !type.IsDefined( typeof(SubclassAttribute), false ) ) && ( !type.IsDefined( typeof(JoinedSubclassAttribute), false ) ) ) ) { PropertyInfo[] properties = type.GetProperties( bindings ); foreach( PropertyInfo property in properties ) { if( property.IsDefined( attrType, false ) ) { list.Add( property ); } } type = type.BaseType; } PropertyInfo[] array = new PropertyInfo[list.Count]; list.CopyTo( array ); return array; } /// <summary> /// Converts the full name into a short name. /// </summary> /// <param name="type"></param> /// <returns></returns> private string GetShortTypeName( System.Type type ) { Match name = m_AssemblyQualifiedNameRegex.Match( type.AssemblyQualifiedName ); string typeName = name.Groups["type"].Value; string assemblyName = name.Groups["assembly"].Value; if( assemblyName == "mscorlib" && typeName.StartsWith( "System." ) && typeName.IndexOf(".") == typeName.LastIndexOf(".") ) { return typeName.Substring( typeName.LastIndexOf(".") + 1 ); } else { return String.Format( "{0}, {1}",typeName, assemblyName ); } } /// <summary> /// Gets the xml enum value from the associated attributed enum. /// </summary> /// <param name="enumType"></param> /// <param name="value"></param> /// <returns></returns> private string GetXmlEnumValue( System.Type enumType, object @value ) { FieldInfo[] fields = enumType.GetFields(); foreach( FieldInfo field in fields ) { if( field.Name == Enum.GetName( enumType, @value ) ) { XmlEnumAttribute attribute = (XmlEnumAttribute)Attribute.GetCustomAttribute( field, typeof(XmlEnumAttribute), false ); if( attribute != null ) { return attribute.Name; } else { throw new ApplicationException( String.Format( "{0} is missing XmlEnumAttribute on {1} value.", enumType, @value ) ); } } } throw new MissingFieldException( enumType.ToString(), @value.ToString() ); } } } --- NEW FILE: VersionAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for VersionAttribute. /// </summary> [AttributeUsage(AttributeTargets.Property)] public class VersionAttribute : Attribute { #region Member Variables private string m_Column; #endregion /// <summary> /// Class constructor. /// </summary> public VersionAttribute( string column ) { this.Column = column; } /// <summary> /// Gets and sets the Column. /// </summary> public string Column { get { return m_Column; } set { m_Column = value; } } } } --- NEW FILE: SubclassAttribute.cs --- using System; namespace NHibernate.Tool.Net2Hbm { /// <summary> /// Summary description for SubclassAttribute. /// </summary> [AttributeUsage(AttributeTargets.Class)] public class SubclassAttribute : Attribute { #region Member Variables private System.Type m_Extends; private string m_DiscriminatorValue; // private System.Type m_Proxy; private bool m_DynamicUpdate; private bool m_DynamicInsert; #endregion /// <summary> /// Class constructor. /// </summary> public SubclassAttribute() { } /// <summary> /// Class constructor. /// </summary> ... [truncated message content] |