From 9ff2f41f204c1f675e43e354a8b348cbf18a44af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= <12201973+fredericDelaporte@users.noreply.github.com> Date: Sat, 23 Jun 2018 15:35:04 +0200 Subject: [PATCH 1/2] Obsolete unused "xml" type methods --- .../NHSpecific/NullableInt32Type.cs | 7 +--- .../NHSpecific/NullableTypesType.cs | 7 +--- .../TypesTest/AbstractDateTimeTypeFixture.cs | 1 + src/NHibernate/Async/Type/ByteType.cs | 2 +- src/NHibernate/Async/Type/EnumStringType.cs | 2 +- src/NHibernate/Async/Type/Int16Type.cs | 2 +- src/NHibernate/Async/Type/Int64Type.cs | 2 +- src/NHibernate/Async/Type/SerializableType.cs | 3 +- src/NHibernate/Async/Type/TicksType.cs | 2 +- src/NHibernate/Async/Type/TimeSpanType.cs | 2 +- src/NHibernate/Async/Type/UInt16Type.cs | 2 +- src/NHibernate/Async/Type/UInt32Type.cs | 2 +- src/NHibernate/Async/Type/UInt64Type.cs | 2 +- src/NHibernate/Type/AbstractBinaryType.cs | 20 +++++++++- src/NHibernate/Type/AbstractCharType.cs | 7 +++- src/NHibernate/Type/AbstractDateTimeType.cs | 29 ++++++++++++-- src/NHibernate/Type/AbstractEnumType.cs | 9 +++-- src/NHibernate/Type/AbstractStringType.cs | 19 +++++++++- src/NHibernate/Type/BooleanType.cs | 10 ++++- src/NHibernate/Type/ByteType.cs | 11 +++++- src/NHibernate/Type/CharBooleanType.cs | 8 ++-- src/NHibernate/Type/CultureInfoType.cs | 14 ++++++- src/NHibernate/Type/CustomType.cs | 30 ++++++++++----- src/NHibernate/Type/DateTimeOffSetType.cs | 27 ++++++++++++- src/NHibernate/Type/DateType.cs | 13 +++++++ src/NHibernate/Type/DecimalType.cs | 10 ++++- src/NHibernate/Type/DoubleType.cs | 4 +- src/NHibernate/Type/EnumCharType.cs | 15 +++++++- src/NHibernate/Type/EnumStringType.cs | 19 +++++++--- src/NHibernate/Type/GuidType.cs | 13 ++++++- src/NHibernate/Type/IIdentifierType.cs | 16 +++++--- src/NHibernate/Type/IVersionType.cs | 10 +++++ src/NHibernate/Type/Int16Type.cs | 14 ++++++- src/NHibernate/Type/Int32Type.cs | 12 ++++++ src/NHibernate/Type/Int64Type.cs | 14 ++++++- src/NHibernate/Type/NullableType.cs | 38 ++++++++++--------- src/NHibernate/Type/PersistentEnumType.cs | 14 +++++++ src/NHibernate/Type/PrimitiveType.cs | 14 ++++++- src/NHibernate/Type/SByteType.cs | 8 ++++ src/NHibernate/Type/SerializableType.cs | 17 ++++++++- src/NHibernate/Type/SingleType.cs | 6 ++- src/NHibernate/Type/TicksType.cs | 22 ++++++++++- src/NHibernate/Type/TimeAsTimeSpanType.cs | 20 ++++++++++ src/NHibernate/Type/TimeSpanType.cs | 22 ++++++++++- src/NHibernate/Type/TimeType.cs | 23 ++++++++++- src/NHibernate/Type/TimestampType.cs | 13 +++++++ src/NHibernate/Type/TypeType.cs | 20 +++++++++- src/NHibernate/Type/UInt16Type.cs | 14 ++++++- src/NHibernate/Type/UInt32Type.cs | 14 ++++++- src/NHibernate/Type/UInt64Type.cs | 14 ++++++- src/NHibernate/Type/UriType.cs | 23 ++++++++++- src/NHibernate/Type/XDocType.cs | 17 +++++++++ src/NHibernate/Type/XmlDocType.cs | 17 +++++++++ src/NHibernate/UserTypes/IEnhancedUserType.cs | 21 +++++++--- 54 files changed, 591 insertions(+), 106 deletions(-) diff --git a/src/NHibernate.DomainModel/NHSpecific/NullableInt32Type.cs b/src/NHibernate.DomainModel/NHSpecific/NullableInt32Type.cs index f0b1ce525fd..3f535590e54 100644 --- a/src/NHibernate.DomainModel/NHSpecific/NullableInt32Type.cs +++ b/src/NHibernate.DomainModel/NHSpecific/NullableInt32Type.cs @@ -46,14 +46,9 @@ public override void Set(DbCommand cmd, object value, int index, ISessionImpleme } } - public override object FromStringValue(string xml) - { - return NullableInt32.Parse(xml); - } - public override bool[] ToColumnNullness(object value, Engine.IMapping mapping) { return value == null || NullableInt32.Default.Equals(value) ? new bool[] { false } : new bool[] { true }; } } -} \ No newline at end of file +} diff --git a/src/NHibernate.DomainModel/NHSpecific/NullableTypesType.cs b/src/NHibernate.DomainModel/NHSpecific/NullableTypesType.cs index bd04787c2a9..748697b6eec 100644 --- a/src/NHibernate.DomainModel/NHSpecific/NullableTypesType.cs +++ b/src/NHibernate.DomainModel/NHSpecific/NullableTypesType.cs @@ -35,11 +35,6 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses return Get(rs, rs.GetOrdinal(name), session); } - public override string ToString(object value) - { - return value.ToString(); - } - public override string Name { get { return ReturnedClass.Name; } @@ -52,4 +47,4 @@ public override bool IsEqual(object x, object y) public abstract object NullValue { get; } } -} \ No newline at end of file +} diff --git a/src/NHibernate.Test/TypesTest/AbstractDateTimeTypeFixture.cs b/src/NHibernate.Test/TypesTest/AbstractDateTimeTypeFixture.cs index e190dbd32c0..d04cc6693aa 100644 --- a/src/NHibernate.Test/TypesTest/AbstractDateTimeTypeFixture.cs +++ b/src/NHibernate.Test/TypesTest/AbstractDateTimeTypeFixture.cs @@ -368,6 +368,7 @@ public virtual void QueryUseExpectedSqlType() [TestCase("2011-01-27T15:50:59.6220000+02:00")] [TestCase("2011-01-27T14:50:59.6220000+01:00")] [TestCase("2011-01-27T13:50:59.6220000Z")] + [Obsolete] public void FromStringValue_ParseValidValues(string timestampValue) { var timestamp = DateTime.Parse(timestampValue); diff --git a/src/NHibernate/Async/Type/ByteType.cs b/src/NHibernate/Async/Type/ByteType.cs index 76aff60f108..c908d33432e 100644 --- a/src/NHibernate/Async/Type/ByteType.cs +++ b/src/NHibernate/Async/Type/ByteType.cs @@ -54,4 +54,4 @@ public virtual Task SeedAsync(ISessionImplementor session, CancellationT } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Async/Type/EnumStringType.cs b/src/NHibernate/Async/Type/EnumStringType.cs index 597df89fda0..3da2325af89 100644 --- a/src/NHibernate/Async/Type/EnumStringType.cs +++ b/src/NHibernate/Async/Type/EnumStringType.cs @@ -61,4 +61,4 @@ public override Task DisassembleAsync(object value, ISessionImplementor } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Async/Type/Int16Type.cs b/src/NHibernate/Async/Type/Int16Type.cs index 2f6680d1a4b..95cec493791 100644 --- a/src/NHibernate/Async/Type/Int16Type.cs +++ b/src/NHibernate/Async/Type/Int16Type.cs @@ -59,4 +59,4 @@ public virtual Task SeedAsync(ISessionImplementor session, CancellationT #endregion } -} \ No newline at end of file +} diff --git a/src/NHibernate/Async/Type/Int64Type.cs b/src/NHibernate/Async/Type/Int64Type.cs index a6fd90ee765..a4dae360662 100644 --- a/src/NHibernate/Async/Type/Int64Type.cs +++ b/src/NHibernate/Async/Type/Int64Type.cs @@ -59,4 +59,4 @@ public virtual Task SeedAsync(ISessionImplementor session, CancellationT #endregion } -} \ No newline at end of file +} diff --git a/src/NHibernate/Async/Type/SerializableType.cs b/src/NHibernate/Async/Type/SerializableType.cs index 9275f6a4247..b4ee750691f 100644 --- a/src/NHibernate/Async/Type/SerializableType.cs +++ b/src/NHibernate/Async/Type/SerializableType.cs @@ -16,7 +16,6 @@ using System.Runtime.Serialization.Formatters.Binary; using NHibernate.Engine; using NHibernate.SqlTypes; -using NHibernate.Util; namespace NHibernate.Type { @@ -57,4 +56,4 @@ public override Task DisassembleAsync(object value, ISessionImplementor } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Async/Type/TicksType.cs b/src/NHibernate/Async/Type/TicksType.cs index 15d7175d96f..e0cb8d1ba08 100644 --- a/src/NHibernate/Async/Type/TicksType.cs +++ b/src/NHibernate/Async/Type/TicksType.cs @@ -52,4 +52,4 @@ public virtual Task SeedAsync(ISessionImplementor session, CancellationT #endregion } -} \ No newline at end of file +} diff --git a/src/NHibernate/Async/Type/TimeSpanType.cs b/src/NHibernate/Async/Type/TimeSpanType.cs index c35f1998000..0917413671c 100644 --- a/src/NHibernate/Async/Type/TimeSpanType.cs +++ b/src/NHibernate/Async/Type/TimeSpanType.cs @@ -53,4 +53,4 @@ public virtual Task SeedAsync(ISessionImplementor session, CancellationT #endregion } -} \ No newline at end of file +} diff --git a/src/NHibernate/Async/Type/UInt16Type.cs b/src/NHibernate/Async/Type/UInt16Type.cs index 6fc970c3283..b30c8ee87a4 100644 --- a/src/NHibernate/Async/Type/UInt16Type.cs +++ b/src/NHibernate/Async/Type/UInt16Type.cs @@ -59,4 +59,4 @@ public virtual Task SeedAsync(ISessionImplementor session, CancellationT #endregion } -} \ No newline at end of file +} diff --git a/src/NHibernate/Async/Type/UInt32Type.cs b/src/NHibernate/Async/Type/UInt32Type.cs index 3b2a1cc2b60..b5aa62179c0 100644 --- a/src/NHibernate/Async/Type/UInt32Type.cs +++ b/src/NHibernate/Async/Type/UInt32Type.cs @@ -59,4 +59,4 @@ public virtual Task SeedAsync(ISessionImplementor session, CancellationT #endregion } -} \ No newline at end of file +} diff --git a/src/NHibernate/Async/Type/UInt64Type.cs b/src/NHibernate/Async/Type/UInt64Type.cs index 796b8920d8c..08e7c68a1e6 100644 --- a/src/NHibernate/Async/Type/UInt64Type.cs +++ b/src/NHibernate/Async/Type/UInt64Type.cs @@ -59,4 +59,4 @@ public virtual Task SeedAsync(ISessionImplementor session, CancellationT #endregion } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/AbstractBinaryType.cs b/src/NHibernate/Type/AbstractBinaryType.cs index a7098616266..2e5882731e6 100644 --- a/src/NHibernate/Type/AbstractBinaryType.cs +++ b/src/NHibernate/Type/AbstractBinaryType.cs @@ -127,6 +127,18 @@ public override int Compare(object x, object y) return 0; } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { // convert to HEX string @@ -150,12 +162,18 @@ public override object DeepCopyNotNull(object value) return ToExternalFormat(result); } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { if (xml == null) return null; if (xml.Length % 2 != 0) - throw new ArgumentException("The string is not a valid xml representation of a binary content."); + throw new ArgumentException("The string is not a valid representation of a binary content."); byte[] bytes = new byte[xml.Length / 2]; for (int i = 0; i < bytes.Length; i++) diff --git a/src/NHibernate/Type/AbstractCharType.cs b/src/NHibernate/Type/AbstractCharType.cs index 8105eec51bd..5efb630c16c 100644 --- a/src/NHibernate/Type/AbstractCharType.cs +++ b/src/NHibernate/Type/AbstractCharType.cs @@ -55,6 +55,9 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return '\'' + value.ToString() + '\''; } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public virtual object StringToObject(string xml) { if (xml.Length != 1) @@ -63,9 +66,11 @@ public virtual object StringToObject(string xml) return xml[0]; } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return xml[0]; } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/AbstractDateTimeType.cs b/src/NHibernate/Type/AbstractDateTimeType.cs index 78d1423f8e7..8f95323cb78 100644 --- a/src/NHibernate/Type/AbstractDateTimeType.cs +++ b/src/NHibernate/Type/AbstractDateTimeType.cs @@ -129,15 +129,38 @@ public override bool IsEqual(object x, object y) => (Kind == DateTimeKind.Unspecified || x == null || ((DateTime) x).Kind == ((DateTime) y).Kind); /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + /// + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) => ((DateTime) val).ToString(CultureInfo.CurrentCulture); + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. /// public object StringToObject(string xml) => - string.IsNullOrEmpty(xml) ? null : FromStringValue(xml); - - /// + string.IsNullOrEmpty(xml) ? null : + // 6.0 TODO: remove warning disable/restore +#pragma warning disable 618 + FromStringValue(xml); +#pragma warning restore 618 + + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { // Parsing with .Net always yield a Local date. var date = DateTime.Parse(xml); diff --git a/src/NHibernate/Type/AbstractEnumType.cs b/src/NHibernate/Type/AbstractEnumType.cs index 0b6ab128392..5454b680884 100644 --- a/src/NHibernate/Type/AbstractEnumType.cs +++ b/src/NHibernate/Type/AbstractEnumType.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using NHibernate.SqlTypes; namespace NHibernate.Type @@ -34,9 +32,11 @@ public override System.Type ReturnedClass get { return enumType; } } - #region IIdentifierType Members + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { return Enum.Parse(enumType, xml); @@ -44,7 +44,8 @@ public object StringToObject(string xml) #endregion - + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return StringToObject(xml); diff --git a/src/NHibernate/Type/AbstractStringType.cs b/src/NHibernate/Type/AbstractStringType.cs index 277b29e4f2b..505eed0ee0a 100644 --- a/src/NHibernate/Type/AbstractStringType.cs +++ b/src/NHibernate/Type/AbstractStringType.cs @@ -34,11 +34,25 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses return Convert.ToString(rs[name]); } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { return (string)val; } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return xml; @@ -51,6 +65,9 @@ public override System.Type ReturnedClass #region IIdentifierType Members + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { return xml; @@ -67,4 +84,4 @@ public string ObjectToSQLString(object value, Dialect.Dialect dialect) #endregion } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/BooleanType.cs b/src/NHibernate/Type/BooleanType.cs index 3945a618ba0..f3333f805b9 100644 --- a/src/NHibernate/Type/BooleanType.cs +++ b/src/NHibernate/Type/BooleanType.cs @@ -74,14 +74,22 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return dialect.ToBooleanValueString((bool)value); } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public virtual object StringToObject(string xml) { + // 6.0 TODO: inline the call +#pragma warning disable 618 return FromStringValue(xml); +#pragma warning restore 618 } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return bool.Parse(xml); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/ByteType.cs b/src/NHibernate/Type/ByteType.cs index 6a0bce5ab6a..36e57aba713 100644 --- a/src/NHibernate/Type/ByteType.cs +++ b/src/NHibernate/Type/ByteType.cs @@ -56,12 +56,21 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return value.ToString(); } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public virtual object StringToObject(string xml) { return Byte.Parse(xml); } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { return byte.Parse(xml); } @@ -86,4 +95,4 @@ public override object DefaultValue get { return ZERO; } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/CharBooleanType.cs b/src/NHibernate/Type/CharBooleanType.cs index 162482e67fd..9cde87c6697 100644 --- a/src/NHibernate/Type/CharBooleanType.cs +++ b/src/NHibernate/Type/CharBooleanType.cs @@ -61,11 +61,9 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return "'" + ToCharacter(value) + "'"; } - /// - /// - /// - /// - /// + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public override object StringToObject(String xml) { if (string.Equals(TrueString, xml, StringComparison.InvariantCultureIgnoreCase)) diff --git a/src/NHibernate/Type/CultureInfoType.cs b/src/NHibernate/Type/CultureInfoType.cs index 2dfffee4b76..c0d82361913 100644 --- a/src/NHibernate/Type/CultureInfoType.cs +++ b/src/NHibernate/Type/CultureInfoType.cs @@ -41,12 +41,24 @@ public override void Set(DbCommand cmd, object value, int index, ISessionImpleme } /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object value) { return GetStringRepresentation(value); } - /// + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return CultureInfo.CreateSpecificCulture(xml); diff --git a/src/NHibernate/Type/CustomType.cs b/src/NHibernate/Type/CustomType.cs index fe904a8d5c8..77a5ac262aa 100644 --- a/src/NHibernate/Type/CustomType.cs +++ b/src/NHibernate/Type/CustomType.cs @@ -107,22 +107,20 @@ public override void NullSafeSet(DbCommand cmd, object value, int index, ISessio userType.NullSafeSet(cmd, value, index, session); } - /// - /// - /// - /// - /// - /// + /// public override string ToLoggableString(object value, ISessionFactoryImplementor factory) { if (value == null) { return "null"; } - IEnhancedUserType eut = userType as IEnhancedUserType; - if (eut != null) + + if (userType is IEnhancedUserType eut) { + // 6.0 TODO: remove warning disable/restore +#pragma warning disable 618 return eut.ToXMLString(value); +#pragma warning restore 618 } return value.ToString(); } @@ -169,14 +167,26 @@ public override bool IsDirty(object old, object current, bool[] checkable, ISess return checkable[0] && IsDirty(old, current, session); } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { + // 6.0 TODO: remove warning disable/restore +#pragma warning disable 618 return ((IEnhancedUserType) userType).FromXMLString(xml); +#pragma warning restore 618 } - + + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object FromStringValue(string xml) { - return ((IEnhancedUserType)userType).FromXMLString(xml); + // 6.0 TODO: remove warning disable/restore +#pragma warning disable 618 + return ((IEnhancedUserType) userType).FromXMLString(xml); +#pragma warning restore 618 } public virtual string ObjectToSQLString(object value, Dialect.Dialect dialect) diff --git a/src/NHibernate/Type/DateTimeOffSetType.cs b/src/NHibernate/Type/DateTimeOffSetType.cs index ac1cbea167a..37837aec289 100644 --- a/src/NHibernate/Type/DateTimeOffSetType.cs +++ b/src/NHibernate/Type/DateTimeOffSetType.cs @@ -114,17 +114,42 @@ public override bool IsEqual(object x, object y) return date1.Equals(date2); } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { - return string.IsNullOrEmpty(xml) ? null : FromStringValue(xml); + return string.IsNullOrEmpty(xml) ? null : + // 6.0 TODO: remove warning disable/restore +#pragma warning disable 618 + FromStringValue(xml); +#pragma warning restore 618 + } + + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { return ((DateTimeOffset) val).ToString(); } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { return DateTimeOffset.Parse(xml); } diff --git a/src/NHibernate/Type/DateType.cs b/src/NHibernate/Type/DateType.cs index 59599596dc5..08e4097a7a7 100644 --- a/src/NHibernate/Type/DateType.cs +++ b/src/NHibernate/Type/DateType.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using NHibernate.Engine; using NHibernate.SqlTypes; using NHibernate.UserTypes; @@ -73,6 +74,18 @@ public override int GetHashCode(object x) } /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + /// + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) => ((DateTime) val).ToShortDateString(); diff --git a/src/NHibernate/Type/DecimalType.cs b/src/NHibernate/Type/DecimalType.cs index 3231815e8d3..57e02314afb 100644 --- a/src/NHibernate/Type/DecimalType.cs +++ b/src/NHibernate/Type/DecimalType.cs @@ -57,6 +57,8 @@ public override object DefaultValue get { return 0m; } } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return Decimal.Parse(xml); @@ -67,9 +69,15 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return value.ToString(); } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { + // 6.0 TODO: inline the call. +#pragma warning disable 618 return FromStringValue(xml); +#pragma warning restore 618 } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/DoubleType.cs b/src/NHibernate/Type/DoubleType.cs index 4c42b6af9e6..f3a54138234 100644 --- a/src/NHibernate/Type/DoubleType.cs +++ b/src/NHibernate/Type/DoubleType.cs @@ -47,6 +47,8 @@ public override string Name get { return "Double"; } } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return double.Parse(xml); @@ -67,4 +69,4 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return value.ToString(); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/EnumCharType.cs b/src/NHibernate/Type/EnumCharType.cs index 2fe6a47e396..0fd8d3cf23c 100644 --- a/src/NHibernate/Type/EnumCharType.cs +++ b/src/NHibernate/Type/EnumCharType.cs @@ -131,6 +131,18 @@ public override string Name get { return "enumchar - " + this.ReturnedClass.Name; } } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object value) { return (value == null) ? null : GetValue(value).ToString(); @@ -153,7 +165,8 @@ public override object Disassemble(object value, ISessionImplementor session, ob return (value == null) ? null : GetValue(value); } - + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return GetInstance(xml); diff --git a/src/NHibernate/Type/EnumStringType.cs b/src/NHibernate/Type/EnumStringType.cs index 3cfaedc6239..168ce03291f 100644 --- a/src/NHibernate/Type/EnumStringType.cs +++ b/src/NHibernate/Type/EnumStringType.cs @@ -153,11 +153,18 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses return Get(rs, rs.GetOrdinal(name), session); } - /// - /// - /// - /// - /// + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object value) { return (value == null) ? null : GetValue(value).ToString(); @@ -210,4 +217,4 @@ public override string Name get { return typeName; } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/GuidType.cs b/src/NHibernate/Type/GuidType.cs index 2c0df5c25eb..a883f3a6b5a 100644 --- a/src/NHibernate/Type/GuidType.cs +++ b/src/NHibernate/Type/GuidType.cs @@ -57,14 +57,23 @@ public override string Name get { return "Guid"; } } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return new Guid(xml); } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { - return string.IsNullOrEmpty(xml) ? null : FromStringValue(xml); + return string.IsNullOrEmpty(xml) ? null : + // 6.0 TODO: inline the call. +#pragma warning disable 618 + FromStringValue(xml); +#pragma warning restore 618 } public override System.Type PrimitiveClass @@ -82,4 +91,4 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return "'" + value + "'"; } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/IIdentifierType.cs b/src/NHibernate/Type/IIdentifierType.cs index b7afde0e03f..a17601986a7 100644 --- a/src/NHibernate/Type/IIdentifierType.cs +++ b/src/NHibernate/Type/IIdentifierType.cs @@ -5,17 +5,21 @@ namespace NHibernate.Type /// public interface IIdentifierType : IType { + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. /// - /// When implemented by a class, converts the xml string from the - /// mapping file to the .NET object. + /// Parse the string representation of a value to convert it to the .NET object. /// - /// The value of discriminator-value or unsaved-value attribute. + /// A string representation. /// The string converted to the object. /// - /// This method needs to be able to handle any string. It should not just + /// This method needs to be able to handle any string. It should not just /// call System.Type.Parse without verifying that it is a parsable value - /// for the System.Type. + /// for the System.Type. + /// Notably meant for parsing discriminator-value or unsaved-value mapping attribute value. + /// Contrary to what could be expected due to its current name, must be a plain string, + /// not n xml encoded string. /// object StringToObject(string xml); } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/IVersionType.cs b/src/NHibernate/Type/IVersionType.cs index a0ecdaac84f..c12cbf66fa8 100644 --- a/src/NHibernate/Type/IVersionType.cs +++ b/src/NHibernate/Type/IVersionType.cs @@ -28,6 +28,16 @@ public partial interface IVersionType : IType /// IComparer Comparator { get; } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// + /// Parse the string representation of a value to convert it to the .NET object. + /// + /// A string representation. + /// The value. + /// Notably meant for parsing unsave-value mapping attribute value. Contrary to what could + /// be expected due to its current name, must be a plain string, not a xml encoded + /// string. object FromStringValue(string xml); } } diff --git a/src/NHibernate/Type/Int16Type.cs b/src/NHibernate/Type/Int16Type.cs index dfdb25a56b9..42f0c2e8b6f 100644 --- a/src/NHibernate/Type/Int16Type.cs +++ b/src/NHibernate/Type/Int16Type.cs @@ -61,12 +61,24 @@ public override void Set(DbCommand rs, object value, int index, ISessionImplemen rs.Parameters[index].Value = value; } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { + // 6.0 TODO: remove warning disable/restore +#pragma warning disable 618 return FromStringValue(xml); +#pragma warning restore 618 } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { return Int16.Parse(xml); } @@ -105,4 +117,4 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return value.ToString(); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/Int32Type.cs b/src/NHibernate/Type/Int32Type.cs index c128d8020fc..e68164aad27 100644 --- a/src/NHibernate/Type/Int32Type.cs +++ b/src/NHibernate/Type/Int32Type.cs @@ -61,12 +61,24 @@ public override void Set(DbCommand rs, object value, int index, ISessionImplemen rs.Parameters[index].Value = value; } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { + // 6.0 TODO: remove warning disable/restore +#pragma warning disable 618 return FromStringValue(xml); +#pragma warning restore 618 } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { return Int32.Parse(xml); } diff --git a/src/NHibernate/Type/Int64Type.cs b/src/NHibernate/Type/Int64Type.cs index c6727abb0e8..6aa6bdaa21c 100644 --- a/src/NHibernate/Type/Int64Type.cs +++ b/src/NHibernate/Type/Int64Type.cs @@ -61,12 +61,24 @@ public override void Set(DbCommand rs, object value, int index, ISessionImplemen rs.Parameters[index].Value = value; } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { + // 6.0 TODO: remove warning disable/restore +#pragma warning disable 618 return FromStringValue(xml); +#pragma warning restore 618 } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { return Int64.Parse(xml); } @@ -105,4 +117,4 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return value.ToString(); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/NullableType.cs b/src/NHibernate/Type/NullableType.cs index da6597f9094..9d5d8d89deb 100644 --- a/src/NHibernate/Type/NullableType.cs +++ b/src/NHibernate/Type/NullableType.cs @@ -82,30 +82,27 @@ protected NullableType(SqlType sqlType) /// public abstract object Get(DbDataReader rs, string name, ISessionImplementor session); - /// /// A representation of the value to be embedded in an XML element /// /// The object that contains the values. /// /// An Xml formatted string. - public abstract string ToString(object val); + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] + public virtual string ToString(object val) + { + return val.ToString(); + } /// - /// - /// - /// This implementation forwards the call to if the parameter - /// value is not null. - /// - /// - /// It has been "sealed" because the Types inheriting from - /// do not need and should not override this method. All of their implementation - /// should be in . - /// - /// - public override sealed string ToLoggableString(object value, ISessionFactoryImplementor factory) + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) { - return (value == null) ? null : ToString(value); + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 } /// @@ -113,7 +110,12 @@ public override sealed string ToLoggableString(object value, ISessionFactoryImpl /// /// XML string to parse, guaranteed to be non-empty /// - public abstract object FromStringValue(string xml); + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] + public virtual object FromStringValue(string xml) + { + throw new NotImplementedException(); + } public override void NullSafeSet(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session) { @@ -154,7 +156,7 @@ public sealed override void NullSafeSet(DbCommand st, object value, int index, I { if (IsDebugEnabled) { - Log.Debug("binding '{0}' to parameter: {1}", ToString(value), index); + Log.Debug("binding '{0}' to parameter: {1}", ToLoggableString(value, session.Factory), index); } Set(st, value, index, session); @@ -242,7 +244,7 @@ public virtual object NullSafeGet(DbDataReader rs, string name, ISessionImplemen if (IsDebugEnabled) { - Log.Debug("returning '{0}' as column: {1}", ToString(val), name); + Log.Debug("returning '{0}' as column: {1}", ToLoggableString(val, session.Factory), name); } return val; diff --git a/src/NHibernate/Type/PersistentEnumType.cs b/src/NHibernate/Type/PersistentEnumType.cs index bb1cf6703f2..9fca2648cc8 100644 --- a/src/NHibernate/Type/PersistentEnumType.cs +++ b/src/NHibernate/Type/PersistentEnumType.cs @@ -237,11 +237,25 @@ public override string Name get { return ReturnedClass.FullName; } } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object value) { return (value == null) ? null : GetValue(value).ToString(); } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return GetInstance(long.Parse(xml)); diff --git a/src/NHibernate/Type/PrimitiveType.cs b/src/NHibernate/Type/PrimitiveType.cs index cc1d9a7be5a..879d6b39715 100644 --- a/src/NHibernate/Type/PrimitiveType.cs +++ b/src/NHibernate/Type/PrimitiveType.cs @@ -1,4 +1,5 @@ using System; +using NHibernate.Engine; using NHibernate.SqlTypes; namespace NHibernate.Type @@ -33,6 +34,16 @@ protected PrimitiveType(SqlType sqlType) #endregion + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + /// /// A representation of the value to be embedded in an XML element /// @@ -44,7 +55,8 @@ protected PrimitiveType(SqlType sqlType) /// a possibility of this PrimitiveType having any characters /// that need to be encoded then this method should be overridden. /// - // TODO: figure out if this is used to build Xml strings or will have encoding done automatically. + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { return val.ToString(); diff --git a/src/NHibernate/Type/SByteType.cs b/src/NHibernate/Type/SByteType.cs index 5f612d2414f..d85ffa4d731 100644 --- a/src/NHibernate/Type/SByteType.cs +++ b/src/NHibernate/Type/SByteType.cs @@ -61,11 +61,19 @@ public override void Set(DbCommand rs, object value, int index, ISessionImplemen rs.Parameters[index].Value = value; } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { + // 6.0 TODO: inline the call. +#pragma warning disable 618 return FromStringValue(xml); +#pragma warning restore 618 } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return SByte.Parse(xml); diff --git a/src/NHibernate/Type/SerializableType.cs b/src/NHibernate/Type/SerializableType.cs index 2da257ce4b2..31017691017 100644 --- a/src/NHibernate/Type/SerializableType.cs +++ b/src/NHibernate/Type/SerializableType.cs @@ -6,7 +6,6 @@ using System.Runtime.Serialization.Formatters.Binary; using NHibernate.Engine; using NHibernate.SqlTypes; -using NHibernate.Util; namespace NHibernate.Type { @@ -92,11 +91,25 @@ public override int GetHashCode(Object x) return binaryType.GetHashCode(ToBytes(x)); } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object value) { return binaryType.ToString(ToBytes(value)); } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return FromBytes((byte[])binaryType.FromStringValue(xml)); @@ -169,4 +182,4 @@ public override object Disassemble(object value, ISessionImplementor session, ob return (value == null) ? null : ToBytes(value); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/SingleType.cs b/src/NHibernate/Type/SingleType.cs index cf45e09fd54..bf719e3832b 100644 --- a/src/NHibernate/Type/SingleType.cs +++ b/src/NHibernate/Type/SingleType.cs @@ -65,11 +65,15 @@ public override void Set(DbCommand rs, object value, int index, ISessionImplemen rs.Parameters[index].Value = value; } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public object StringToObject(string xml) { return FromStringValue(xml); } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return Single.Parse(xml); @@ -90,4 +94,4 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return value.ToString(); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/TicksType.cs b/src/NHibernate/Type/TicksType.cs index c25eb6d7dab..4048d216d1a 100644 --- a/src/NHibernate/Type/TicksType.cs +++ b/src/NHibernate/Type/TicksType.cs @@ -50,12 +50,30 @@ public override string Name get { return "Ticks"; } } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { return ((DateTime)val).Ticks.ToString(); } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { return new DateTime(Int64.Parse(xml)); } @@ -72,6 +90,8 @@ public virtual object Seed(ISessionImplementor session) return DateTime.Now; } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public object StringToObject(string xml) { return Int64.Parse(xml); @@ -99,4 +119,4 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return '\'' + ((DateTime)value).Ticks.ToString() + '\''; } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/TimeAsTimeSpanType.cs b/src/NHibernate/Type/TimeAsTimeSpanType.cs index a946f9bef3a..51fa6745b57 100644 --- a/src/NHibernate/Type/TimeAsTimeSpanType.cs +++ b/src/NHibernate/Type/TimeAsTimeSpanType.cs @@ -72,6 +72,18 @@ public override System.Type ReturnedClass get { return typeof(TimeSpan); } } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { return ((TimeSpan)val).Ticks.ToString(); @@ -89,6 +101,8 @@ public virtual object Seed(ISessionImplementor session) return new TimeSpan(DateTime.Now.Ticks); } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public object StringToObject(string xml) { return TimeSpan.Parse(xml); @@ -101,7 +115,13 @@ public IComparer Comparator #endregion + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { return TimeSpan.Parse(xml); } diff --git a/src/NHibernate/Type/TimeSpanType.cs b/src/NHibernate/Type/TimeSpanType.cs index 124209c3586..5ca576454b9 100644 --- a/src/NHibernate/Type/TimeSpanType.cs +++ b/src/NHibernate/Type/TimeSpanType.cs @@ -61,6 +61,18 @@ public override void Set(DbCommand st, object value, int index, ISessionImplemen st.Parameters[index].Value = ((TimeSpan)value).Ticks; } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { return ((TimeSpan)val).Ticks.ToString(); @@ -79,6 +91,8 @@ public virtual object Seed(ISessionImplementor session) return new TimeSpan(DateTime.Now.Ticks); } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public object StringToObject(string xml) { return TimeSpan.Parse(xml); @@ -91,7 +105,13 @@ public IComparer Comparator #endregion + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { return TimeSpan.Parse(xml); } @@ -111,4 +131,4 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return '\'' + ((TimeSpan)value).Ticks.ToString() + '\''; } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/TimeType.cs b/src/NHibernate/Type/TimeType.cs index e3e85d44f66..be487f81cff 100644 --- a/src/NHibernate/Type/TimeType.cs +++ b/src/NHibernate/Type/TimeType.cs @@ -124,16 +124,37 @@ public override int GetHashCode(object x) return hashCode; } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { return ((DateTime)val).ToString("T"); } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { - return string.IsNullOrEmpty(xml) ? null : FromStringValue(xml); + return string.IsNullOrEmpty(xml) ? null : + // 6.0 TODO: inline the call. +#pragma warning disable 618 + FromStringValue(xml); +#pragma warning restore 618 } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return DateTime.Parse(xml); diff --git a/src/NHibernate/Type/TimestampType.cs b/src/NHibernate/Type/TimestampType.cs index e15f3afe0b7..1c0977bcaaa 100644 --- a/src/NHibernate/Type/TimestampType.cs +++ b/src/NHibernate/Type/TimestampType.cs @@ -1,4 +1,5 @@ using System; +using NHibernate.Engine; namespace NHibernate.Type { @@ -33,12 +34,24 @@ public class TimestampType : AbstractDateTimeType /// public override string Name => "Timestamp"; + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + /// /// Retrieve the string representation of the timestamp object. This is in the following format: /// /// 2011-01-27T14:50:59.6220000Z /// /// + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) => ((DateTime) val).ToString("O"); } diff --git a/src/NHibernate/Type/TypeType.cs b/src/NHibernate/Type/TypeType.cs index 043ae1e8ee3..243ba4708f7 100644 --- a/src/NHibernate/Type/TypeType.cs +++ b/src/NHibernate/Type/TypeType.cs @@ -84,6 +84,23 @@ public override void Set(DbCommand cmd, object value, int index, ISessionImpleme } /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + /// + /// A representation of the value to be embedded in an XML element + /// + /// The that contains the values. + /// + /// An Xml formatted string that contains the Assembly Qualified Name. + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object value) { return GetStringRepresentation(value); @@ -107,7 +124,8 @@ public override string Name get { return "Type"; } } - /// + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return ParseStringRepresentation(xml); diff --git a/src/NHibernate/Type/UInt16Type.cs b/src/NHibernate/Type/UInt16Type.cs index 98ed3cd41df..5bd39b02e0d 100644 --- a/src/NHibernate/Type/UInt16Type.cs +++ b/src/NHibernate/Type/UInt16Type.cs @@ -61,12 +61,24 @@ public override void Set(DbCommand rs, object value, int index, ISessionImplemen rs.Parameters[index].Value = value; } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { + // 6.0 TODO: remove warning disable/restore +#pragma warning disable 618 return FromStringValue(xml); +#pragma warning restore 618 } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { return UInt16.Parse(xml); } @@ -105,4 +117,4 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return value.ToString(); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/UInt32Type.cs b/src/NHibernate/Type/UInt32Type.cs index b0c7104e834..27f65faed30 100644 --- a/src/NHibernate/Type/UInt32Type.cs +++ b/src/NHibernate/Type/UInt32Type.cs @@ -61,12 +61,24 @@ public override void Set(DbCommand rs, object value, int index, ISessionImplemen rs.Parameters[index].Value = value; } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { + // 6.0 TODO: remove warning disable/restore +#pragma warning disable 618 return FromStringValue(xml); +#pragma warning restore 618 } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { return UInt32.Parse(xml); } @@ -105,4 +117,4 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return value.ToString(); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/UInt64Type.cs b/src/NHibernate/Type/UInt64Type.cs index 05356574bd4..44066ded9cc 100644 --- a/src/NHibernate/Type/UInt64Type.cs +++ b/src/NHibernate/Type/UInt64Type.cs @@ -60,12 +60,24 @@ public override void Set(DbCommand rs, object value, int index, ISessionImplemen rs.Parameters[index].Value = value; } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { + // 6.0 TODO: remove warning disable/restore +#pragma warning disable 618 return FromStringValue(xml); +#pragma warning restore 618 } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. Replace override keyword by virtual after having + // removed the obsoleted base. + /// +#pragma warning disable 672 public override object FromStringValue(string xml) +#pragma warning restore 672 { return UInt64.Parse(xml); } @@ -104,4 +116,4 @@ public override string ObjectToSQLString(object value, Dialect.Dialect dialect) return value.ToString(); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Type/UriType.cs b/src/NHibernate/Type/UriType.cs index a02efb84640..e0c8d5c4329 100644 --- a/src/NHibernate/Type/UriType.cs +++ b/src/NHibernate/Type/UriType.cs @@ -27,6 +27,9 @@ public override System.Type ReturnedClass get { return typeof(Uri); } } + // 6.0 TODO: rename "xml" parameter as "value": it is not a xml string. The fact it generally comes from a xml + // attribute value is irrelevant to the method behavior. + /// public object StringToObject(string xml) { return new Uri(xml, UriKind.RelativeOrAbsolute); @@ -34,7 +37,11 @@ public object StringToObject(string xml) public override void Set(DbCommand cmd, object value, int index, ISessionImplementor session) { - cmd.Parameters[index].Value = ToString(value); + cmd.Parameters[index].Value = + // 6.0 TODO: inline the call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 } public override object Get(DbDataReader rs, int index, ISessionImplementor session) @@ -47,11 +54,25 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses return StringToObject(Convert.ToString(rs[name])); } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { return ((Uri)val).OriginalString; } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { return StringToObject(xml); diff --git a/src/NHibernate/Type/XDocType.cs b/src/NHibernate/Type/XDocType.cs index 53d9a784518..19b031b0026 100644 --- a/src/NHibernate/Type/XDocType.cs +++ b/src/NHibernate/Type/XDocType.cs @@ -41,7 +41,10 @@ public override object Get(DbDataReader rs, int index, ISessionImplementor sessi // according to documentation, GetValue should return a string, at least for MsSQL // hopefully all DataProvider has the same behaviour string xmlString = Convert.ToString(rs.GetValue(index)); + // 6.0 TODO: inline the call. +#pragma warning disable 618 return FromStringValue(xmlString); +#pragma warning restore 618 } public override object Get(DbDataReader rs, string name, ISessionImplementor session) @@ -49,11 +52,25 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses return Get(rs, rs.GetOrdinal(name), session); } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { return val == null ? null : val.ToString(); } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { if (xml != null) diff --git a/src/NHibernate/Type/XmlDocType.cs b/src/NHibernate/Type/XmlDocType.cs index b38e5122567..066b6e499da 100644 --- a/src/NHibernate/Type/XmlDocType.cs +++ b/src/NHibernate/Type/XmlDocType.cs @@ -40,7 +40,10 @@ public override object Get(DbDataReader rs, int index, ISessionImplementor sessi // according to documentation, GetValue should return a string, at least for MsSQL // hopefully all DataProvider has the same behaviour string xmlString = Convert.ToString(rs.GetValue(index)); + // 6.0 TODO: inline the call. +#pragma warning disable 618 return FromStringValue(xmlString); +#pragma warning restore 618 } public override object Get(DbDataReader rs, string name, ISessionImplementor session) @@ -48,11 +51,25 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses return Get(rs, rs.GetOrdinal(name), session); } + /// + public override string ToLoggableString(object value, ISessionFactoryImplementor factory) + { + return (value == null) ? null : + // 6.0 TODO: inline this call. +#pragma warning disable 618 + ToString(value); +#pragma warning restore 618 + } + + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { return GetStringRepresentation(val); } + // Since 5.2 + [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { if (xml != null) diff --git a/src/NHibernate/UserTypes/IEnhancedUserType.cs b/src/NHibernate/UserTypes/IEnhancedUserType.cs index a750a07b594..4a088ad8a68 100644 --- a/src/NHibernate/UserTypes/IEnhancedUserType.cs +++ b/src/NHibernate/UserTypes/IEnhancedUserType.cs @@ -1,3 +1,5 @@ +using System; + namespace NHibernate.UserTypes { /// @@ -7,9 +9,14 @@ namespace NHibernate.UserTypes public interface IEnhancedUserType : IUserType { /// - /// Parse a string representation of this value, as it appears - /// in an XML document. + /// Parse a string representation of this value. /// + // 6.0 TODO: rename "FromString(string value)". + // Since 5.2 + [Obsolete("This method was not used for parsing xml strings, but instead used for parsing already de-encoded " + + "strings originating from xml (so indeed, plain text strings). It will be renamed \"FromString\" in a " + + "future version. Implement a \"object FromString(string value)\" without any xml de-coding, called by your" + + "\"object FromXMLString(string xml)\", in order to get ready for the rename.")] object FromXMLString(string xml); /// @@ -18,9 +25,13 @@ public interface IEnhancedUserType : IUserType string ObjectToSQLString(object value); /// - /// Return a string representation of this value, as it - /// should appear in an XML document + /// Return a string representation of this value. It does not need to be xml encoded. /// + // 6.0 TODO: rename "ToString". + // Since 5.2 + [Obsolete("This method was not used in a xml context, but instead just used for logs. It will be renamed " + + "\"ToString\" in a future version. Implement a \"string ToString(object value)\", called by your " + + "\"string ToXMLString(object value)\", in order to get ready for the rename.")] string ToXMLString(object value); } -} \ No newline at end of file +} From 800f1b179a7ba88cb64d67daacbd2c492e782678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= <12201973+fredericDelaporte@users.noreply.github.com> Date: Fri, 29 Jun 2018 15:18:13 +0200 Subject: [PATCH 2/2] fixup! Obsolete unused "xml" type methods Resolving conflicts is not enough... --- src/NHibernate/Type/CultureInfoType.cs | 5 ++--- src/NHibernate/Type/TypeType.cs | 2 +- src/NHibernate/Type/UriType.cs | 9 +++++++-- src/NHibernate/Type/XDocType.cs | 16 ++++++++-------- src/NHibernate/Type/XmlDocType.cs | 22 +++++++++++++--------- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/NHibernate/Type/CultureInfoType.cs b/src/NHibernate/Type/CultureInfoType.cs index c0d82361913..47daf666588 100644 --- a/src/NHibernate/Type/CultureInfoType.cs +++ b/src/NHibernate/Type/CultureInfoType.cs @@ -93,15 +93,14 @@ public override object Disassemble(object value, ISessionImplementor session, ob return GetStringRepresentation(value); } - private string GetStringRepresentation(object value) + private static string GetStringRepresentation(object value) { return ((CultureInfo) value)?.Name; } private static object ParseStringRepresentation(object value) { - var str = value as string; - return str == null ? null : new CultureInfo(str); + return value is string str ? new CultureInfo(str) : null; } } } diff --git a/src/NHibernate/Type/TypeType.cs b/src/NHibernate/Type/TypeType.cs index 243ba4708f7..6d5b541257a 100644 --- a/src/NHibernate/Type/TypeType.cs +++ b/src/NHibernate/Type/TypeType.cs @@ -143,7 +143,7 @@ public override object Disassemble(object value, ISessionImplementor session, ob return GetStringRepresentation(value); } - private string GetStringRepresentation(object value) + private static string GetStringRepresentation(object value) { return ((System.Type) value)?.AssemblyQualifiedName; } diff --git a/src/NHibernate/Type/UriType.cs b/src/NHibernate/Type/UriType.cs index e0c8d5c4329..68f319606d3 100644 --- a/src/NHibernate/Type/UriType.cs +++ b/src/NHibernate/Type/UriType.cs @@ -35,6 +35,11 @@ public object StringToObject(string xml) return new Uri(xml, UriKind.RelativeOrAbsolute); } + private static string GetStringRepresentation(object value) + { + return ((Uri)value).OriginalString; + } + public override void Set(DbCommand cmd, object value, int index, ISessionImplementor session) { cmd.Parameters[index].Value = @@ -68,7 +73,7 @@ public override string ToLoggableString(object value, ISessionFactoryImplementor [Obsolete("This method has no more usages and will be removed in a future version. Override ToLoggableString instead.")] public override string ToString(object val) { - return ((Uri)val).OriginalString; + return GetStringRepresentation(val); } // Since 5.2 @@ -93,7 +98,7 @@ public override object Assemble(object cached, ISessionImplementor session, obje /// public override object Disassemble(object value, ISessionImplementor session, object owner) { - return value == null ? null : ToString(value); + return value == null ? null : GetStringRepresentation(value); } } } diff --git a/src/NHibernate/Type/XDocType.cs b/src/NHibernate/Type/XDocType.cs index 19b031b0026..fc29eaf478f 100644 --- a/src/NHibernate/Type/XDocType.cs +++ b/src/NHibernate/Type/XDocType.cs @@ -73,12 +73,7 @@ public override string ToString(object val) [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { - if (xml != null) - { - return XDocument.Parse(xml); - } - - return null; + return ParseStringRepresentation(xml); } public override object DeepCopyNotNull(object value) @@ -105,7 +100,7 @@ public override bool IsEqual(object x, object y) /// public override object Assemble(object cached, ISessionImplementor session, object owner) { - return FromStringValue(cached as string); + return ParseStringRepresentation(cached as string); } /// @@ -114,9 +109,14 @@ public override object Disassemble(object value, ISessionImplementor session, ob return GetStringRepresentation(value); } - private string GetStringRepresentation(object value) + private static string GetStringRepresentation(object value) { return ((XDocument) value)?.ToString(SaveOptions.DisableFormatting); } + + private static object ParseStringRepresentation(string value) + { + return value != null ? XDocument.Parse(value) : null; + } } } diff --git a/src/NHibernate/Type/XmlDocType.cs b/src/NHibernate/Type/XmlDocType.cs index 066b6e499da..a138ee56b46 100644 --- a/src/NHibernate/Type/XmlDocType.cs +++ b/src/NHibernate/Type/XmlDocType.cs @@ -72,13 +72,7 @@ public override string ToString(object val) [Obsolete("This method has no more usages and will be removed in a future version.")] public override object FromStringValue(string xml) { - if (xml != null) - { - var xmlDocument = new XmlDocument(); - xmlDocument.LoadXml(xml); - return xmlDocument; - } - return null; + return ParseStringRepresentation(xml); } public override object DeepCopyNotNull(object value) @@ -105,7 +99,7 @@ public override bool IsEqual(object x, object y) /// public override object Assemble(object cached, ISessionImplementor session, object owner) { - return FromStringValue(cached as string); + return ParseStringRepresentation(cached as string); } /// @@ -114,9 +108,19 @@ public override object Disassemble(object value, ISessionImplementor session, ob return GetStringRepresentation(value); } - private string GetStringRepresentation(object value) + private static string GetStringRepresentation(object value) { return ((XmlDocument) value)?.OuterXml; } + + private static object ParseStringRepresentation(string value) + { + if (value == null) + return null; + + var xmlDocument = new XmlDocument(); + xmlDocument.LoadXml(value); + return xmlDocument; + } } }