From: Kevin W. <kev...@us...> - 2005-01-01 02:40:13
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25964 Modified Files: PropertiesHelper.cs ReflectHelper.cs SequencedHashMap.cs Log Message: fix xml documentation and allow ReSharper to reformat Index: SequencedHashMap.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Util/SequencedHashMap.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SequencedHashMap.cs 14 Aug 2004 20:59:35 -0000 1.7 --- SequencedHashMap.cs 1 Jan 2005 02:40:02 -0000 1.8 *************** *** 1,3 **** --- 1,4 ---- #region The Apache Software License, Version 1.1 + /* This is a port from the Jakarta commons project */ *************** *** 58,68 **** * */ #endregion [...1130 lines suppressed...] } ! public object Key { get { return _pos.Key; } } ! public object Value { get { return _pos.Value; } *************** *** 675,677 **** } } ! } --- 715,717 ---- } } ! } \ No newline at end of file Index: ReflectHelper.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Util/ReflectHelper.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** ReflectHelper.cs 4 Dec 2004 22:41:30 -0000 1.19 --- ReflectHelper.cs 1 Jan 2005 02:40:02 -0000 1.20 *************** *** 2,10 **** using System.Collections; using System.Reflection; - using NHibernate.Property; using NHibernate.Type; ! namespace NHibernate.Util { /// <summary> --- 2,9 ---- using System.Collections; using System.Reflection; using NHibernate.Property; using NHibernate.Type; ! namespace NHibernate.Util { /// <summary> *************** *** 13,24 **** public sealed class ReflectHelper { ! private ReflectHelper() { // not creatable } ! private static System.Type[] NoClasses = new System.Type[0]; ! private static System.Type[] Object = new System.Type[] { typeof(object) }; ! /// <summary> /// Determine if the specified <see cref="System.Type"/> overrides the --- 12,23 ---- public sealed class ReflectHelper { ! private ReflectHelper() { // not creatable } ! private static System.Type[ ] NoClasses = new System.Type[0]; ! // private static System.Type[ ] Object = new System.Type[ ] {typeof( object )}; // not used !?! ! /// <summary> /// Determine if the specified <see cref="System.Type"/> overrides the *************** *** 27,47 **** /// <param name="clazz">The <see cref="System.Type"/> to reflect.</param> /// <returns><c>true</c> if any type in the heirarchy overrides Equals(object).</returns> ! public static bool OverridesEquals(System.Type clazz) { ! try { ! MethodInfo equals = clazz.GetMethod("Equals", new System.Type[] { typeof(object) }); ! if( equals==null ) { return false; } ! else { // make sure that the DeclaringType is not System.Object - if that is the // declaring type then there is no override. ! return !equals.DeclaringType.Equals( typeof(object) ); } ! } ! catch( AmbiguousMatchException ) { // an ambigious match means that there is an override and it --- 26,46 ---- /// <param name="clazz">The <see cref="System.Type"/> to reflect.</param> /// <returns><c>true</c> if any type in the heirarchy overrides Equals(object).</returns> ! public static bool OverridesEquals( System.Type clazz ) { ! try { ! MethodInfo equals = clazz.GetMethod( "Equals", new System.Type[ ] {typeof( object )} ); ! if( equals == null ) { return false; } ! else { // make sure that the DeclaringType is not System.Object - if that is the // declaring type then there is no override. ! return !equals.DeclaringType.Equals( typeof( object ) ); } ! } ! catch( AmbiguousMatchException ) { // an ambigious match means that there is an override and it *************** *** 49,57 **** return true; } ! catch (Exception ) { return false; } ! } --- 48,56 ---- return true; } ! catch( Exception ) { return false; } ! } *************** *** 75,79 **** /// No Property or Field with the <c>propertyName</c> could be found. /// </exception> ! public static IGetter GetGetter(System.Type theClass, string propertyName) { IPropertyAccessor accessor = null; --- 74,78 ---- /// No Property or Field with the <c>propertyName</c> could be found. /// </exception> ! public static IGetter GetGetter( System.Type theClass, string propertyName ) { IPropertyAccessor accessor = null; *************** *** 81,100 **** // first try the basicPropertyAccessor since that will be the most likely // strategy used. ! try { ! accessor = (IPropertyAccessor)PropertyAccessorFactory.PropertyAccessors["property"]; ! return accessor.GetGetter(theClass, propertyName); } ! catch( PropertyNotFoundException pnfe ) { // the basic "property" strategy did not work so try the rest of them ! foreach( DictionaryEntry de in Property.PropertyAccessorFactory.PropertyAccessors ) { ! try { ! accessor = (IPropertyAccessor)de.Value; return accessor.GetGetter( theClass, propertyName ); } ! catch( PropertyNotFoundException ) { // ignore this exception because we want to try and move through --- 80,99 ---- // first try the basicPropertyAccessor since that will be the most likely // strategy used. ! try { ! accessor = ( IPropertyAccessor ) PropertyAccessorFactory.PropertyAccessors[ "property" ]; ! return accessor.GetGetter( theClass, propertyName ); } ! catch( PropertyNotFoundException ) { // the basic "property" strategy did not work so try the rest of them ! foreach( DictionaryEntry de in PropertyAccessorFactory.PropertyAccessors ) { ! try { ! accessor = ( IPropertyAccessor ) de.Value; return accessor.GetGetter( theClass, propertyName ); } ! catch( PropertyNotFoundException ) { // ignore this exception because we want to try and move through *************** *** 112,118 **** ! public static IType ReflectedPropertyType(System.Type theClass, string name) { ! return TypeFactory.HueristicType( GetGetter(theClass, name).ReturnType.AssemblyQualifiedName ); } --- 111,123 ---- ! /// <summary> ! /// ! /// </summary> ! /// <param name="theClass"></param> ! /// <param name="name"></param> ! /// <returns></returns> ! public static IType ReflectedPropertyType( System.Type theClass, string name ) { ! return TypeFactory.HueristicType( GetGetter( theClass, name ).ReturnType.AssemblyQualifiedName ); } *************** *** 122,128 **** /// <param name="name">The name of the class. Can be a name with the assembly included or just the name of the class.</param> /// <returns>The Type for the Class.</returns> ! public static System.Type ClassForName(string name) { ! return System.Type.GetType(name, true); } --- 127,133 ---- /// <param name="name">The name of the class. Can be a name with the assembly included or just the name of the class.</param> /// <returns>The Type for the Class.</returns> ! public static System.Type ClassForName( string name ) { ! return System.Type.GetType( name, true ); } *************** *** 133,147 **** /// <param name="fieldName">The name of the Field in the <see cref="System.Type"/>.</param> /// <returns>The value contained in that field or <c>null</c> if the Type or Field does not exist.</returns> ! public static object GetConstantValue(string typeName, string fieldName) { ! System.Type clazz = System.Type.GetType( typeName, false ); ! ! if( clazz==null ) return null; ! try { return clazz.GetField( fieldName ).GetValue( null ); ! } ! catch (Exception) { return null; --- 138,152 ---- /// <param name="fieldName">The name of the Field in the <see cref="System.Type"/>.</param> /// <returns>The value contained in that field or <c>null</c> if the Type or Field does not exist.</returns> ! public static object GetConstantValue( string typeName, string fieldName ) { ! System.Type clazz = System.Type.GetType( typeName, false ); ! if( clazz == null ) return null; ! ! try { return clazz.GetField( fieldName ).GetValue( null ); ! } ! catch( Exception ) { return null; *************** *** 149,162 **** } ! public static ConstructorInfo GetDefaultConstructor(System.Type type) { ! if (IsAbstractClass(type)) return null; ! ! try { ! ConstructorInfo contructor = type.GetConstructor(BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic, null, CallingConventions.HasThis, NoClasses, null); return contructor; ! } ! catch (Exception) { throw new PropertyNotFoundException( --- 154,172 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="type"></param> ! /// <returns></returns> ! public static ConstructorInfo GetDefaultConstructor( System.Type type ) { ! if( IsAbstractClass( type ) ) return null; ! ! try { ! ConstructorInfo contructor = type.GetConstructor( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, CallingConventions.HasThis, NoClasses, null ); return contructor; ! } ! catch( Exception ) { throw new PropertyNotFoundException( *************** *** 166,174 **** } ! public static bool IsAbstractClass(System.Type type) { ! return (type.IsAbstract || type.IsInterface); } } ! } --- 176,189 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="type"></param> ! /// <returns></returns> ! public static bool IsAbstractClass( System.Type type ) { ! return ( type.IsAbstract || type.IsInterface ); } } ! } \ No newline at end of file Index: PropertiesHelper.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Util/PropertiesHelper.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PropertiesHelper.cs 29 Oct 2004 05:54:34 -0000 1.7 --- PropertiesHelper.cs 1 Jan 2005 02:40:02 -0000 1.8 *************** *** 1,49 **** using System; - using System.Xml; using System.Collections; ! using System.Collections.Specialized; ! namespace NHibernate.Util { //Much of this code is taken from Maverick.NET ! public class PropertiesHelper { ! public static bool GetBoolean(string property, IDictionary properties, bool defaultValue) { ! return properties[ property ]==null ? defaultValue : ! bool.Parse( properties[property] as string ); } ! public static bool GetBoolean(string property, IDictionary properties) { ! return properties[property] == null ? false : ! bool.Parse(properties[property] as string); } ! ! public static int GetInt32(string property, IDictionary properties, int defaultValue) { ! string propValue = properties[property] as string; ! return (propValue==null) ? defaultValue : int.Parse(propValue); } ! ! public static string GetString(string property, IDictionary properties, string defaultValue) { ! string propValue = properties[property] as string; ! return (propValue==null) ? defaultValue : propValue; } ! ! public static IDictionary ToDictionary(string property, string delim, IDictionary properties) { IDictionary map = new Hashtable(); ! string propValue = (string) properties[ property ]; ! if (propValue!=null) { ! StringTokenizer tokens = new StringTokenizer(propValue, delim, false); IEnumerator en = tokens.GetEnumerator(); ! while ( en.MoveNext() ) { ! string key = (string) en.Current; ! ! string value = en.MoveNext() ? (string) en.Current : String.Empty; ! map[key] = value; } } --- 1,86 ---- using System; using System.Collections; ! using System.Xml; ! namespace NHibernate.Util { //Much of this code is taken from Maverick.NET ! /// <summary></summary> ! public class PropertiesHelper { ! /// <summary> ! /// ! /// </summary> ! /// <param name="property"></param> ! /// <param name="properties"></param> ! /// <param name="defaultValue"></param> ! /// <returns></returns> ! public static bool GetBoolean( string property, IDictionary properties, bool defaultValue ) { ! return properties[ property ] == null ? defaultValue : ! bool.Parse( properties[ property ] as string ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="property"></param> ! /// <param name="properties"></param> ! /// <returns></returns> ! public static bool GetBoolean( string property, IDictionary properties ) ! { ! return properties[ property ] == null ? false : ! bool.Parse( properties[ property ] as string ); } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="property"></param> ! /// <param name="properties"></param> ! /// <param name="defaultValue"></param> ! /// <returns></returns> ! public static int GetInt32( string property, IDictionary properties, int defaultValue ) ! { ! string propValue = properties[ property ] as string; ! return ( propValue == null ) ? defaultValue : int.Parse( propValue ); } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="property"></param> ! /// <param name="properties"></param> ! /// <param name="defaultValue"></param> ! /// <returns></returns> ! public static string GetString( string property, IDictionary properties, string defaultValue ) ! { ! string propValue = properties[ property ] as string; ! return ( propValue == null ) ? defaultValue : propValue; } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="property"></param> ! /// <param name="delim"></param> ! /// <param name="properties"></param> ! /// <returns></returns> ! public static IDictionary ToDictionary( string property, string delim, IDictionary properties ) { IDictionary map = new Hashtable(); ! string propValue = ( string ) properties[ property ]; ! if( propValue != null ) { ! StringTokenizer tokens = new StringTokenizer( propValue, delim, false ); IEnumerator en = tokens.GetEnumerator(); ! while( en.MoveNext() ) { ! string key = ( string ) en.Current; ! ! string value = en.MoveNext() ? ( string ) en.Current : String.Empty; ! map[ key ] = value; } } *************** *** 51,62 **** } ! public static string[] ToStringArray(string property, string delim, IDictionary properties) { ! return ToStringArray( (string) properties[ property ], delim ); } ! public static string[] ToStringArray(string propValue, string delim) { ! if (propValue!=null) { ! return StringHelper.Split(delim, propValue); ! } else { return new string[0]; } --- 88,117 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="property"></param> ! /// <param name="delim"></param> ! /// <param name="properties"></param> ! /// <returns></returns> ! public static string[ ] ToStringArray( string property, string delim, IDictionary properties ) ! { ! return ToStringArray( ( string ) properties[ property ], delim ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="propValue"></param> ! /// <param name="delim"></param> ! /// <returns></returns> ! public static string[ ] ToStringArray( string propValue, string delim ) ! { ! if( propValue != null ) ! { ! return StringHelper.Split( delim, propValue ); ! } ! else ! { return new string[0]; } *************** *** 64,69 **** --- 119,127 ---- + /// <summary></summary> public const string TagParam = "param"; + /// <summary></summary> public const string AttrValue = "value"; + /// <summary></summary> public const string AttrName = "name"; *************** *** 74,98 **** /// <param name="node">Parent element.</param> /// <returns>null if no parameters are found</returns> ! public static IDictionary GetParams(XmlElement node) { IDictionary result = new Hashtable(); ! ! foreach( XmlElement paramNode in node.GetElementsByTagName(TagParam) ) { ! string name = GetAttribute(paramNode, AttrName); ! string val = GetAttribute(paramNode, AttrValue); ! if (val == null) ! if (paramNode.HasChildNodes) { val = paramNode.InnerText; //TODO: allow for multiple values? ! } else { val = paramNode.InnerText; } ! result.Add(name, val); } return result; } ! private static string GetAttribute(XmlElement node, string attr) { ! string result = node.GetAttribute(attr); ! if (result!=null && result.Trim().Length == 0) result = null; --- 132,162 ---- /// <param name="node">Parent element.</param> /// <returns>null if no parameters are found</returns> ! public static IDictionary GetParams( XmlElement node ) ! { IDictionary result = new Hashtable(); ! ! foreach( XmlElement paramNode in node.GetElementsByTagName( TagParam ) ) ! { ! string name = GetAttribute( paramNode, AttrName ); ! string val = GetAttribute( paramNode, AttrValue ); ! if( val == null ) ! if( paramNode.HasChildNodes ) ! { val = paramNode.InnerText; //TODO: allow for multiple values? ! } ! else ! { val = paramNode.InnerText; } ! result.Add( name, val ); } return result; } ! private static string GetAttribute( XmlElement node, string attr ) ! { ! string result = node.GetAttribute( attr ); ! if( result != null && result.Trim().Length == 0 ) result = null; *************** *** 100,102 **** } } ! } --- 164,166 ---- } } ! } \ No newline at end of file |