From: <fab...@us...> - 2009-06-09 23:08:15
|
Revision: 4437 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4437&view=rev Author: fabiomaulo Date: 2009-06-09 23:08:08 +0000 (Tue, 09 Jun 2009) Log Message: ----------- One more step First for injectable ICollectionTypeFactory Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-09 22:05:38 UTC (rev 4436) +++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-09 23:08:08 UTC (rev 4437) @@ -36,8 +36,7 @@ private static readonly char[] precisionScaleSplit = new char[] { '(', ')', ',' }; private static readonly char[] lengthSplit = new char[] { '(', ')' }; - - private static readonly ICollectionTypeFactory collectionTypeFactory; + private static readonly TypeFactory Instance; private static readonly System.Type[] GenericCollectionSimpleSignature = new[] { typeof(string), typeof(string), typeof(bool) }; /* @@ -96,9 +95,10 @@ /// <summary></summary> static TypeFactory() { - collectionTypeFactory = - (ICollectionTypeFactory) - Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(typeof (CollectionTypeFactory)); + Instance = + new TypeFactory( + (ICollectionTypeFactory) + Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(typeof (CollectionTypeFactory))); //basicTypes.Add(NHibernate.Blob.Name, NHibernate.Blob); //basicTypes.Add(NHibernate.Clob.Name, NHibernate.Clob); @@ -184,10 +184,11 @@ getTypeDelegatesWithPrecision.Add(NHibernateUtil.Decimal.Name, GetDecimalType); } + public ICollectionTypeFactory CollectionTypeFactory { get; private set; } - private TypeFactory() + private TypeFactory(ICollectionTypeFactory collectionTypeFactory) { - throw new NotSupportedException(); + CollectionTypeFactory = collectionTypeFactory; } /// <summary> @@ -656,52 +657,52 @@ public static CollectionType Array(string role, string propertyRef, bool embedded, System.Type elementClass) { - return collectionTypeFactory.Array(role, propertyRef, embedded, elementClass); + return Instance.CollectionTypeFactory.Array(role, propertyRef, embedded, elementClass); } public static CollectionType List(string role, string propertyRef, bool embedded) { - return collectionTypeFactory.List(role, propertyRef, embedded); + return Instance.CollectionTypeFactory.List(role, propertyRef, embedded); } public static CollectionType Bag(string role, string propertyRef, bool embedded) { - return collectionTypeFactory.Bag(role, propertyRef, embedded); + return Instance.CollectionTypeFactory.Bag(role, propertyRef, embedded); } public static CollectionType IdBag(string role, string propertyRef, bool embedded) { - return collectionTypeFactory.IdBag(role, propertyRef, embedded); + return Instance.CollectionTypeFactory.IdBag(role, propertyRef, embedded); } public static CollectionType Map(string role, string propertyRef, bool embedded) { - return collectionTypeFactory.Map(role, propertyRef, embedded); + return Instance.CollectionTypeFactory.Map(role, propertyRef, embedded); } public static CollectionType Set(string role, string propertyRef, bool embedded) { - return collectionTypeFactory.Set(role, propertyRef, embedded); + return Instance.CollectionTypeFactory.Set(role, propertyRef, embedded); } public static CollectionType SortedMap(string role, string propertyRef, bool embedded, IComparer comparer) { - return collectionTypeFactory.SortedMap(role, propertyRef, embedded, comparer); + return Instance.CollectionTypeFactory.SortedMap(role, propertyRef, embedded, comparer); } public static CollectionType OrderedMap(string role, string propertyRef, bool embedded) { - return collectionTypeFactory.OrderedMap(role, propertyRef, embedded); + return Instance.CollectionTypeFactory.OrderedMap(role, propertyRef, embedded); } public static CollectionType SortedSet(string role, string propertyRef, bool embedded, IComparer comparer) { - return collectionTypeFactory.SortedSet(role, propertyRef, embedded, comparer); + return Instance.CollectionTypeFactory.SortedSet(role, propertyRef, embedded, comparer); } public static CollectionType OrderedSet(string role, string propertyRef, bool embedded) { - return collectionTypeFactory.OrderedSet(role, propertyRef, embedded); + return Instance.CollectionTypeFactory.OrderedSet(role, propertyRef, embedded); } public static CollectionType GenericBag(string role, string propertyRef, System.Type elementClass) @@ -709,7 +710,7 @@ MethodInfo mi = ReflectHelper.GetGenericMethodFrom<ICollectionTypeFactory>("Bag", new[] {elementClass}, GenericCollectionSimpleSignature); - return (CollectionType) mi.Invoke(collectionTypeFactory, new object[] { role, propertyRef, false }); + return (CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new object[] { role, propertyRef, false }); } public static CollectionType GenericIdBag(string role, string propertyRef, System.Type elementClass) @@ -717,7 +718,7 @@ MethodInfo mi = ReflectHelper.GetGenericMethodFrom<ICollectionTypeFactory>("IdBag", new[] { elementClass }, GenericCollectionSimpleSignature); - return (CollectionType)mi.Invoke(collectionTypeFactory, new object[] { role, propertyRef, false }); + return (CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new object[] { role, propertyRef, false }); } public static CollectionType GenericList(string role, string propertyRef, System.Type elementClass) @@ -725,7 +726,7 @@ MethodInfo mi = ReflectHelper.GetGenericMethodFrom<ICollectionTypeFactory>("List", new[] { elementClass }, GenericCollectionSimpleSignature); - return (CollectionType)mi.Invoke(collectionTypeFactory, new object[] { role, propertyRef, false }); + return (CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new object[] { role, propertyRef, false }); } public static CollectionType GenericMap(string role, string propertyRef, System.Type indexClass, @@ -734,7 +735,7 @@ MethodInfo mi = ReflectHelper.GetGenericMethodFrom<ICollectionTypeFactory>("Map", new[] {indexClass, elementClass }, GenericCollectionSimpleSignature); - return (CollectionType)mi.Invoke(collectionTypeFactory, new object[] { role, propertyRef, false }); + return (CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new object[] { role, propertyRef, false }); } public static CollectionType GenericSortedList(string role, string propertyRef, object comparer, @@ -744,7 +745,7 @@ MethodInfo mi = ReflectHelper.GetGenericMethodFrom<ICollectionTypeFactory>("SortedList", new[] { indexClass, elementClass }, signature); - return (CollectionType)mi.Invoke(collectionTypeFactory, new[] { role, propertyRef, false, comparer }); + return (CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new[] { role, propertyRef, false, comparer }); } public static CollectionType GenericSortedDictionary(string role, string propertyRef, object comparer, @@ -754,7 +755,7 @@ MethodInfo mi = ReflectHelper.GetGenericMethodFrom<ICollectionTypeFactory>("SortedDictionary", new[] { indexClass, elementClass }, signature); - return (CollectionType)mi.Invoke(collectionTypeFactory, new[] { role, propertyRef, false, comparer }); + return (CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new[] { role, propertyRef, false, comparer }); } public static CollectionType GenericSet(string role, string propertyRef, System.Type elementClass) @@ -762,7 +763,7 @@ MethodInfo mi = ReflectHelper.GetGenericMethodFrom<ICollectionTypeFactory>("Set", new[] { elementClass }, GenericCollectionSimpleSignature); - return (CollectionType)mi.Invoke(collectionTypeFactory, new object[] { role, propertyRef, false }); + return (CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new object[] { role, propertyRef, false }); } public static CollectionType GenericSortedSet(string role, string propertyRef, object comparer, @@ -772,7 +773,7 @@ MethodInfo mi = ReflectHelper.GetGenericMethodFrom<ICollectionTypeFactory>("SortedSet", new[] { elementClass }, signature); - return (CollectionType)mi.Invoke(collectionTypeFactory, new[] { role, propertyRef, false, comparer }); + return (CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new[] { role, propertyRef, false, comparer }); } public static CollectionType GenericOrderedSet(string role, string propertyRef, @@ -781,7 +782,7 @@ MethodInfo mi = ReflectHelper.GetGenericMethodFrom<ICollectionTypeFactory>("OrderedSet", new[] { elementClass }, GenericCollectionSimpleSignature); - return (CollectionType)mi.Invoke(collectionTypeFactory, new object[] { role, propertyRef, false }); + return (CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new object[] { role, propertyRef, false }); } /// <summary> Deep copy a series of values from one array to another... </summary> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-06-15 05:12:57
|
Revision: 4474 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4474&view=rev Author: fabiomaulo Date: 2009-06-15 05:12:25 +0000 (Mon, 15 Jun 2009) Log Message: ----------- Refactoring of type registration (hopefully more clear for us) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-15 03:32:04 UTC (rev 4473) +++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-15 05:12:25 UTC (rev 4474) @@ -35,8 +35,8 @@ PrecisionScale } - private static readonly char[] precisionScaleSplit = new char[] { '(', ')', ',' }; - private static readonly char[] lengthSplit = new char[] { '(', ')' }; + private static readonly char[] PrecisionScaleSplit = new[] { '(', ')', ',' }; + private static readonly char[] LengthSplit = new[] { '(', ')' }; private static readonly TypeFactory Instance; private static readonly System.Type[] GenericCollectionSimpleSignature = new[] { typeof(string), typeof(string), typeof(bool) }; @@ -75,15 +75,18 @@ private delegate NullableType NullableTypeCreatorDelegate(SqlType sqlType); - private static void RegisterType(System.Type systemType, IType nhibernateType, string additionalName) + private static void RegisterType(System.Type systemType, IType nhibernateType, IEnumerable<string> aliases) { typeByTypeOfName[systemType.FullName] = nhibernateType; typeByTypeOfName[systemType.AssemblyQualifiedName] = nhibernateType; typeByTypeOfName[nhibernateType.Name] = nhibernateType; - if (additionalName != null) + if (aliases != null) { - typeByTypeOfName[additionalName] = nhibernateType; + foreach (var alias in aliases) + { + typeByTypeOfName[alias] = nhibernateType; + } } if (systemType.IsValueType) @@ -95,87 +98,30 @@ } } + private static void RegisterType(IType nhibernateType, IEnumerable<string> aliases) + { + typeByTypeOfName[nhibernateType.Name] = nhibernateType; + + if (aliases != null) + { + foreach (var alias in aliases) + { + typeByTypeOfName[alias] = nhibernateType; + } + } + } + /// <summary></summary> static TypeFactory() { Instance = new TypeFactory(); - //basicTypes.Add(NHibernate.Blob.Name, NHibernate.Blob); - //basicTypes.Add(NHibernate.Clob.Name, NHibernate.Clob); - - // the Timezone class .NET is not even close to the java.util.Timezone class - in - // .NET all you can do is get the local Timezone - there is no "factory" method to - // get a Timezone by name... - //basicTypes.Add(NHibernate.Timezone.Name, NHibernate.Timezone); - // set up the mappings of .NET Classes/Structs to their NHibernate types. - RegisterType(typeof(Byte[]), NHibernateUtil.Binary, "binary"); - RegisterType(typeof(Boolean), NHibernateUtil.Boolean, "boolean"); - RegisterType(typeof(Byte), NHibernateUtil.Byte, "byte"); - RegisterType(typeof(Char), NHibernateUtil.Character, "character"); - RegisterType(typeof(CultureInfo), NHibernateUtil.CultureInfo, "locale"); - /*registering "datetime" after of "datetime2", - NH will choose "datetime" when no type is specified in the mapping*/ - RegisterType(typeof(DateTime), NHibernateUtil.DateTime2, "datetime2"); - RegisterType(typeof(DateTime), NHibernateUtil.DateTime, "datetime"); - RegisterType(typeof(DateTimeOffset), NHibernateUtil.DateTimeOffset, "datetimeoffset"); - RegisterType(typeof(Decimal), NHibernateUtil.Decimal, "big_decimal"); - RegisterType(typeof(Double), NHibernateUtil.Double, "double"); - RegisterType(typeof(Guid), NHibernateUtil.Guid, "guid"); - RegisterType(typeof(Int16), NHibernateUtil.Int16, "short"); - RegisterType(typeof(Int32), NHibernateUtil.Int32, "integer"); - RegisterType(typeof(Int64), NHibernateUtil.Int64, "long"); - RegisterType(typeof(SByte), NHibernateUtil.SByte, null); - RegisterType(typeof(Single), NHibernateUtil.Single, "float"); - RegisterType(typeof(String), NHibernateUtil.String, "string"); - RegisterType(typeof(TimeSpan), NHibernateUtil.TimeAsTimeSpan, "TimeAsTimeSpan"); - RegisterType(typeof(TimeSpan), NHibernateUtil.TimeSpan,null); - RegisterType(typeof(System.Type), NHibernateUtil.Class, "class"); + RegisterDefaultNetTypes(); - RegisterType(typeof(UInt16), NHibernateUtil.UInt16, null); - RegisterType(typeof(UInt32), NHibernateUtil.UInt32, null); - RegisterType(typeof(UInt64), NHibernateUtil.UInt64, null); - // add the mappings of the NHibernate specific names that are used in type="" - typeByTypeOfName[NHibernateUtil.AnsiString.Name] = NHibernateUtil.AnsiString; - getTypeDelegatesWithLength.Add(NHibernateUtil.AnsiString.Name, GetAnsiStringType); + RegisterBuiltInTypes(); - typeByTypeOfName[NHibernateUtil.AnsiChar.Name] = NHibernateUtil.AnsiChar; - typeByTypeOfName[NHibernateUtil.BinaryBlob.Name] = NHibernateUtil.BinaryBlob; - typeByTypeOfName[NHibernateUtil.StringClob.Name] = NHibernateUtil.StringClob; - typeByTypeOfName[NHibernateUtil.Date.Name] = NHibernateUtil.Date; - typeByTypeOfName[NHibernateUtil.Timestamp.Name] = NHibernateUtil.Timestamp; - typeByTypeOfName[NHibernateUtil.Time.Name] = NHibernateUtil.Time; - typeByTypeOfName[NHibernateUtil.TrueFalse.Name] = NHibernateUtil.TrueFalse; - typeByTypeOfName[NHibernateUtil.YesNo.Name] = NHibernateUtil.YesNo; - typeByTypeOfName[NHibernateUtil.Ticks.Name] = NHibernateUtil.Ticks; - typeByTypeOfName[NHibernateUtil.TimeSpan.Name] = NHibernateUtil.TimeSpan; - typeByTypeOfName[NHibernateUtil.TimeAsTimeSpan.Name] = NHibernateUtil.TimeAsTimeSpan; - typeByTypeOfName[NHibernateUtil.Currency.Name] = NHibernateUtil.Currency; - - // need to do add the key "Serializable" because the hbm files will have a - // type="Serializable", but the SerializableType returns the Name as - // "serializable - System.Object for the default SerializableType. - typeByTypeOfName["Serializable"] = NHibernateUtil.Serializable; - typeByTypeOfName[NHibernateUtil.Serializable.Name] = NHibernateUtil.Serializable; - - // object needs to have both class and serializable setup before it can - // be created. - RegisterType(typeof(Object), NHibernateUtil.Object, "object"); - - // These are in here because needed to NO override default CLR types and be available in mappings - typeByTypeOfName["int"] = NHibernateUtil.Int32; - typeByTypeOfName["date"] = NHibernateUtil.Date; - typeByTypeOfName["time"] = NHibernateUtil.Time; - typeByTypeOfName["timestamp"] = NHibernateUtil.Timestamp; - typeByTypeOfName["decimal"] = NHibernateUtil.Decimal; - typeByTypeOfName["currency"] = NHibernateUtil.Currency; - - typeByTypeOfName["serializable"] = NHibernateUtil.Serializable; - typeByTypeOfName["true_false"] = NHibernateUtil.TrueFalse; - typeByTypeOfName["yes_no"] = NHibernateUtil.YesNo; - - getTypeDelegatesWithLength.Add(NHibernateUtil.Binary.Name, l => GetType(NHibernateUtil.Binary, l, len => new BinaryType(SqlTypeFactory.GetBinary(len)))); @@ -198,6 +144,9 @@ getTypeDelegatesWithLength.Add(NHibernateUtil.Class.Name, l => GetType(NHibernateUtil.Class, l, len => new TypeType(SqlTypeFactory.GetString(len)))); + getTypeDelegatesWithLength.Add(NHibernateUtil.AnsiString.Name, + l => + GetType(NHibernateUtil.AnsiString, l, len => new AnsiStringType(SqlTypeFactory.GetAnsiString(len)))); getTypeDelegatesWithPrecision.Add(NHibernateUtil.Decimal.Name, @@ -210,6 +159,66 @@ (p, s) => GetType(NHibernateUtil.Single, p, s, st => new SingleType(st))); } + /// <summary> + /// Register other Default .NET type + /// </summary> + /// <remarks> + /// These type will be used, as default, even when the "type" attribute was NOT specified in the mapping + /// </remarks> + private static void RegisterDefaultNetTypes() + { + // NOTE : each .NET type mut appear only one time + RegisterType(typeof (Byte[]), NHibernateUtil.Binary, new[] {"binary"}); + RegisterType(typeof(Boolean), NHibernateUtil.Boolean, new[] { "boolean", "bool" }); + RegisterType(typeof (Byte), NHibernateUtil.Byte, new[]{ "byte"}); + RegisterType(typeof (Char), NHibernateUtil.Character, new[] {"character", "char"}); + RegisterType(typeof (CultureInfo), NHibernateUtil.CultureInfo, new[]{ "locale"}); + RegisterType(typeof (DateTime), NHibernateUtil.DateTime, new[]{ "datetime"} ); + RegisterType(typeof (DateTimeOffset), NHibernateUtil.DateTimeOffset, new[]{ "datetimeoffset"}); + RegisterType(typeof (Decimal), NHibernateUtil.Decimal, new[] {"big_decimal", "decimal"}); + RegisterType(typeof (Double), NHibernateUtil.Double, new[]{ "double"}); + RegisterType(typeof (Guid), NHibernateUtil.Guid, new[]{ "guid"}); + RegisterType(typeof (Int16), NHibernateUtil.Int16, new[]{ "short"}); + RegisterType(typeof (Int32), NHibernateUtil.Int32, new[] {"integer", "int"}); + RegisterType(typeof (Int64), NHibernateUtil.Int64, new[]{ "long"}); + RegisterType(typeof (SByte), NHibernateUtil.SByte, null); + RegisterType(typeof (Single), NHibernateUtil.Single, new[] {"float", "single"}); + RegisterType(typeof (String), NHibernateUtil.String, new[]{ "string"}); + RegisterType(typeof (TimeSpan), NHibernateUtil.TimeSpan, new[] {"timespan"}); + RegisterType(typeof (System.Type), NHibernateUtil.Class, new[] {"class"}); + RegisterType(typeof (UInt16), NHibernateUtil.UInt16, new[] {"ushort"}); + RegisterType(typeof (UInt32), NHibernateUtil.UInt32, new[] {"uint"}); + RegisterType(typeof (UInt64), NHibernateUtil.UInt64, new[] {"ulong"}); + // object needs to have both class and serializable setup before it can + // be created. + RegisterType(typeof (Object), NHibernateUtil.Object, new[] {"object"}); + } + + /// <summary> + /// Register other NO Default .NET type + /// </summary> + /// <remarks> + /// These type will be used only when the "type" attribute was is specified in the mapping. + /// These are in here because needed to NO override default CLR types and be available in mappings + /// </remarks> + private static void RegisterBuiltInTypes() + { + RegisterType(NHibernateUtil.AnsiString, null); + RegisterType(NHibernateUtil.AnsiChar, null); + RegisterType(NHibernateUtil.BinaryBlob, null); + RegisterType(NHibernateUtil.StringClob, null); + RegisterType(NHibernateUtil.Date, new[] { "date" }); + RegisterType(NHibernateUtil.Timestamp, new[] { "timestamp" }); + RegisterType(NHibernateUtil.Time, new[] { "time" }); + RegisterType(NHibernateUtil.TrueFalse, new[] { "true_false" }); + RegisterType(NHibernateUtil.YesNo, new[] { "yes_no" }); + RegisterType(NHibernateUtil.Ticks, null); + RegisterType(NHibernateUtil.TimeAsTimeSpan, null); + RegisterType(NHibernateUtil.Currency, new[] { "currency" }); + RegisterType(NHibernateUtil.DateTime2, new[] { "datetime2" }); + RegisterType(NHibernateUtil.Serializable, new[] { "Serializable", "serializable" }); + } + public ICollectionTypeFactory CollectionTypeFactory { get @@ -302,7 +311,7 @@ { //precision/scale based - string[] parsedName = name.Split(precisionScaleSplit); + string[] parsedName = name.Split(PrecisionScaleSplit); if (parsedName.Length < 4) { throw new ArgumentOutOfRangeException("TypeClassification.PrecisionScale", name, @@ -313,19 +322,13 @@ byte precision = Byte.Parse(parsedName[1].Trim()); byte scale = Byte.Parse(parsedName[2].Trim()); - GetNullableTypeWithPrecision precisionDelegate; - if (!getTypeDelegatesWithPrecision.TryGetValue(typeName, out precisionDelegate)) - { - return null; - } - - return precisionDelegate(precision, scale); + return BuiltInType(typeName, precision, scale); } else if (typeClassification == TypeClassification.Length) { //length based - string[] parsedName = name.Split(lengthSplit); + string[] parsedName = name.Split(LengthSplit); if (parsedName.Length < 3) { throw new ArgumentOutOfRangeException("TypeClassification.Length", name, "It is not a valid Length name"); @@ -334,14 +337,7 @@ typeName = parsedName[0].Trim(); int length = Int32.Parse(parsedName[1].Trim()); - GetNullableTypeWithLength lengthDelegate; - - if (!getTypeDelegatesWithLength.TryGetValue(typeName, out lengthDelegate)) - { - // we were not able to find a delegate to get the Type - return null; - } - return lengthDelegate(length); + return BuiltInType(typeName, length); } else @@ -354,6 +350,21 @@ } } + internal static IType BuiltInType(string typeName, int length) + { + GetNullableTypeWithLength lengthDelegate; + + return !getTypeDelegatesWithLength.TryGetValue(typeName, out lengthDelegate) ? null : lengthDelegate(length); + } + + internal static IType BuiltInType(string typeName, byte precision, byte scale) + { + GetNullableTypeWithPrecision precisionDelegate; + return !getTypeDelegatesWithPrecision.TryGetValue(typeName, out precisionDelegate) + ? null + : precisionDelegate(precision, scale); + } + private static void AddToTypeOfName(string key, IType type) { typeByTypeOfName.Add(key, type); @@ -416,10 +427,10 @@ TypeClassification typeClassification = GetTypeClassification(typeName); if (typeClassification == TypeClassification.Length) { - parsedTypeName = typeName.Split(lengthSplit); + parsedTypeName = typeName.Split(LengthSplit); } else - parsedTypeName = typeClassification == TypeClassification.PrecisionScale ? typeName.Split(precisionScaleSplit) : new string[] { typeName }; + parsedTypeName = typeClassification == TypeClassification.PrecisionScale ? typeName.Split(PrecisionScaleSplit) : new[] { typeName }; System.Type typeClass; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-06-15 05:18:23
|
Revision: 4475 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4475&view=rev Author: fabiomaulo Date: 2009-06-15 05:17:20 +0000 (Mon, 15 Jun 2009) Log Message: ----------- Minor (variable type registration) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-15 05:12:25 UTC (rev 4474) +++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-15 05:17:20 UTC (rev 4475) @@ -122,41 +122,9 @@ // add the mappings of the NHibernate specific names that are used in type="" RegisterBuiltInTypes(); - getTypeDelegatesWithLength.Add(NHibernateUtil.Binary.Name, - l => - GetType(NHibernateUtil.Binary, l, len => new BinaryType(SqlTypeFactory.GetBinary(len)))); - getTypeDelegatesWithLength.Add(NHibernateUtil.BinaryBlob.Name, - l => - GetType(NHibernateUtil.BinaryBlob, l, len => new BinaryBlobType(SqlTypeFactory.GetBinaryBlob(len)))); - getTypeDelegatesWithLength.Add(NHibernateUtil.Serializable.Name, - l => - GetType(NHibernateUtil.Serializable, l, - len => new SerializableType(typeof (object), SqlTypeFactory.GetBinary(len)))); - getTypeDelegatesWithLength.Add(NHibernateUtil.String.Name, - l => - GetType(NHibernateUtil.String, l, len => new StringType(SqlTypeFactory.GetString(len)))); + RegisterTypeWithVariableLength(); - getTypeDelegatesWithLength.Add(NHibernateUtil.StringClob.Name, - l => - GetType(NHibernateUtil.StringClob, l, - len => new StringClobType(SqlTypeFactory.GetStringClob(len)))); - - getTypeDelegatesWithLength.Add(NHibernateUtil.Class.Name, - l => - GetType(NHibernateUtil.Class, l, len => new TypeType(SqlTypeFactory.GetString(len)))); - getTypeDelegatesWithLength.Add(NHibernateUtil.AnsiString.Name, - l => - GetType(NHibernateUtil.AnsiString, l, len => new AnsiStringType(SqlTypeFactory.GetAnsiString(len)))); - - - getTypeDelegatesWithPrecision.Add(NHibernateUtil.Decimal.Name, - (p, s) => GetType(NHibernateUtil.Decimal, p, s, st => new DecimalType(st))); - getTypeDelegatesWithPrecision.Add(NHibernateUtil.Currency.Name, - (p, s) => GetType(NHibernateUtil.Currency, p, s, st => new CurrencyType(st))); - getTypeDelegatesWithPrecision.Add(NHibernateUtil.Double.Name, - (p, s) => GetType(NHibernateUtil.Double, p, s, st => new DoubleType(st))); - getTypeDelegatesWithPrecision.Add(NHibernateUtil.Single.Name, - (p, s) => GetType(NHibernateUtil.Single, p, s, st => new SingleType(st))); + RegisterTypesWithVariablePrecision(); } /// <summary> @@ -219,6 +187,49 @@ RegisterType(NHibernateUtil.Serializable, new[] { "Serializable", "serializable" }); } + private static void RegisterTypesWithVariablePrecision() + { + getTypeDelegatesWithPrecision.Add(NHibernateUtil.Decimal.Name, + (p, s) => GetType(NHibernateUtil.Decimal, p, s, st => new DecimalType(st))); + getTypeDelegatesWithPrecision.Add(NHibernateUtil.Currency.Name, + (p, s) => GetType(NHibernateUtil.Currency, p, s, st => new CurrencyType(st))); + getTypeDelegatesWithPrecision.Add(NHibernateUtil.Double.Name, + (p, s) => GetType(NHibernateUtil.Double, p, s, st => new DoubleType(st))); + getTypeDelegatesWithPrecision.Add(NHibernateUtil.Single.Name, + (p, s) => GetType(NHibernateUtil.Single, p, s, st => new SingleType(st))); + } + + private static void RegisterTypeWithVariableLength() + { + getTypeDelegatesWithLength.Add(NHibernateUtil.Binary.Name, + l => + GetType(NHibernateUtil.Binary, l, len => new BinaryType(SqlTypeFactory.GetBinary(len)))); + getTypeDelegatesWithLength.Add(NHibernateUtil.BinaryBlob.Name, + l => + GetType(NHibernateUtil.BinaryBlob, l, + len => new BinaryBlobType(SqlTypeFactory.GetBinaryBlob(len)))); + getTypeDelegatesWithLength.Add(NHibernateUtil.Serializable.Name, + l => + GetType(NHibernateUtil.Serializable, l, + len => new SerializableType(typeof(object), SqlTypeFactory.GetBinary(len)))); + getTypeDelegatesWithLength.Add(NHibernateUtil.String.Name, + l => + GetType(NHibernateUtil.String, l, len => new StringType(SqlTypeFactory.GetString(len)))); + + getTypeDelegatesWithLength.Add(NHibernateUtil.StringClob.Name, + l => + GetType(NHibernateUtil.StringClob, l, + len => new StringClobType(SqlTypeFactory.GetStringClob(len)))); + + getTypeDelegatesWithLength.Add(NHibernateUtil.Class.Name, + l => + GetType(NHibernateUtil.Class, l, len => new TypeType(SqlTypeFactory.GetString(len)))); + getTypeDelegatesWithLength.Add(NHibernateUtil.AnsiString.Name, + l => + GetType(NHibernateUtil.AnsiString, l, + len => new AnsiStringType(SqlTypeFactory.GetAnsiString(len)))); + } + public ICollectionTypeFactory CollectionTypeFactory { get This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-06-15 05:52:19
|
Revision: 4476 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4476&view=rev Author: fabiomaulo Date: 2009-06-15 05:51:19 +0000 (Mon, 15 Jun 2009) Log Message: ----------- Minor (refactoring NRY) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-15 05:17:20 UTC (rev 4475) +++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-15 05:51:19 UTC (rev 4476) @@ -34,6 +34,7 @@ Length, PrecisionScale } + private static readonly string[] EmptyAliases= new string[0]; private static readonly char[] PrecisionScaleSplit = new[] { '(', ')', ',' }; private static readonly char[] LengthSplit = new[] { '(', ')' }; @@ -77,37 +78,28 @@ private static void RegisterType(System.Type systemType, IType nhibernateType, IEnumerable<string> aliases) { - typeByTypeOfName[systemType.FullName] = nhibernateType; - typeByTypeOfName[systemType.AssemblyQualifiedName] = nhibernateType; - typeByTypeOfName[nhibernateType.Name] = nhibernateType; - - if (aliases != null) - { - foreach (var alias in aliases) - { - typeByTypeOfName[alias] = nhibernateType; - } - } - + var typeAliases = new List<string>(aliases) + { + systemType.FullName, + systemType.AssemblyQualifiedName, + }; if (systemType.IsValueType) { // Also register Nullable<systemType> for ValueTypes System.Type nullableType = typeof(Nullable<>).MakeGenericType(systemType); - typeByTypeOfName[nullableType.FullName] = nhibernateType; - typeByTypeOfName[nullableType.AssemblyQualifiedName] = nhibernateType; + typeAliases.Add(nullableType.FullName); + typeAliases.Add(nullableType.AssemblyQualifiedName); } + + RegisterType(nhibernateType, typeAliases); } private static void RegisterType(IType nhibernateType, IEnumerable<string> aliases) { - typeByTypeOfName[nhibernateType.Name] = nhibernateType; - - if (aliases != null) + var typeAliases = new List<string>(aliases) { nhibernateType.Name }; + foreach (var alias in typeAliases) { - foreach (var alias in aliases) - { - typeByTypeOfName[alias] = nhibernateType; - } + typeByTypeOfName[alias] = nhibernateType; } } @@ -149,7 +141,7 @@ RegisterType(typeof (Int16), NHibernateUtil.Int16, new[]{ "short"}); RegisterType(typeof (Int32), NHibernateUtil.Int32, new[] {"integer", "int"}); RegisterType(typeof (Int64), NHibernateUtil.Int64, new[]{ "long"}); - RegisterType(typeof (SByte), NHibernateUtil.SByte, null); + RegisterType(typeof(SByte), NHibernateUtil.SByte, EmptyAliases); RegisterType(typeof (Single), NHibernateUtil.Single, new[] {"float", "single"}); RegisterType(typeof (String), NHibernateUtil.String, new[]{ "string"}); RegisterType(typeof (TimeSpan), NHibernateUtil.TimeSpan, new[] {"timespan"}); @@ -171,17 +163,17 @@ /// </remarks> private static void RegisterBuiltInTypes() { - RegisterType(NHibernateUtil.AnsiString, null); - RegisterType(NHibernateUtil.AnsiChar, null); - RegisterType(NHibernateUtil.BinaryBlob, null); - RegisterType(NHibernateUtil.StringClob, null); + RegisterType(NHibernateUtil.AnsiString, EmptyAliases); + RegisterType(NHibernateUtil.AnsiChar, EmptyAliases); + RegisterType(NHibernateUtil.BinaryBlob, EmptyAliases); + RegisterType(NHibernateUtil.StringClob, EmptyAliases); RegisterType(NHibernateUtil.Date, new[] { "date" }); RegisterType(NHibernateUtil.Timestamp, new[] { "timestamp" }); RegisterType(NHibernateUtil.Time, new[] { "time" }); RegisterType(NHibernateUtil.TrueFalse, new[] { "true_false" }); RegisterType(NHibernateUtil.YesNo, new[] { "yes_no" }); - RegisterType(NHibernateUtil.Ticks, null); - RegisterType(NHibernateUtil.TimeAsTimeSpan, null); + RegisterType(NHibernateUtil.Ticks, new[] { "ticks" }); + RegisterType(NHibernateUtil.TimeAsTimeSpan, EmptyAliases); RegisterType(NHibernateUtil.Currency, new[] { "currency" }); RegisterType(NHibernateUtil.DateTime2, new[] { "datetime2" }); RegisterType(NHibernateUtil.Serializable, new[] { "Serializable", "serializable" }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-06-15 05:53:40
|
Revision: 4477 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4477&view=rev Author: fabiomaulo Date: 2009-06-15 05:52:40 +0000 (Mon, 15 Jun 2009) Log Message: ----------- Minor (Typo) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-15 05:51:19 UTC (rev 4476) +++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-15 05:52:40 UTC (rev 4477) @@ -114,7 +114,7 @@ // add the mappings of the NHibernate specific names that are used in type="" RegisterBuiltInTypes(); - RegisterTypeWithVariableLength(); + RegisterTypesWithVariableLength(); RegisterTypesWithVariablePrecision(); } @@ -191,7 +191,7 @@ (p, s) => GetType(NHibernateUtil.Single, p, s, st => new SingleType(st))); } - private static void RegisterTypeWithVariableLength() + private static void RegisterTypesWithVariableLength() { getTypeDelegatesWithLength.Add(NHibernateUtil.Binary.Name, l => This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-06-15 06:23:04
|
Revision: 4478 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4478&view=rev Author: fabiomaulo Date: 2009-06-15 06:22:40 +0000 (Mon, 15 Jun 2009) Log Message: ----------- Refactoring : Now the registration of each type should be more consistent. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-15 05:52:40 UTC (rev 4477) +++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-15 06:22:40 UTC (rev 4478) @@ -78,7 +78,33 @@ private static void RegisterType(System.Type systemType, IType nhibernateType, IEnumerable<string> aliases) { - var typeAliases = new List<string>(aliases) + var typeAliases = new List<string>(aliases); + typeAliases.AddRange(GetClrTypeAliases(systemType)); + + RegisterType(nhibernateType, typeAliases); + } + + private static void RegisterType(System.Type systemType, IType nhibernateType, + IEnumerable<string> aliases, GetNullableTypeWithLength ctorLength) + { + var typeAliases = new List<string>(aliases); + typeAliases.AddRange(GetClrTypeAliases(systemType)); + + RegisterType(nhibernateType, typeAliases, ctorLength); + } + + private static void RegisterType(System.Type systemType, IType nhibernateType, + IEnumerable<string> aliases, GetNullableTypeWithPrecision ctorPrecision) + { + var typeAliases = new List<string>(aliases); + typeAliases.AddRange(GetClrTypeAliases(systemType)); + + RegisterType(nhibernateType, typeAliases, ctorPrecision); + } + + private static IEnumerable<string> GetClrTypeAliases(System.Type systemType) + { + var typeAliases = new List<string> { systemType.FullName, systemType.AssemblyQualifiedName, @@ -90,8 +116,7 @@ typeAliases.Add(nullableType.FullName); typeAliases.Add(nullableType.AssemblyQualifiedName); } - - RegisterType(nhibernateType, typeAliases); + return typeAliases; } private static void RegisterType(IType nhibernateType, IEnumerable<string> aliases) @@ -103,6 +128,26 @@ } } + private static void RegisterType(IType nhibernateType, IEnumerable<string> aliases, GetNullableTypeWithLength ctorLength) + { + var typeAliases = new List<string>(aliases) { nhibernateType.Name }; + foreach (var alias in typeAliases) + { + typeByTypeOfName[alias] = nhibernateType; + getTypeDelegatesWithLength.Add(alias, ctorLength); + } + } + + private static void RegisterType(IType nhibernateType, IEnumerable<string> aliases, GetNullableTypeWithPrecision ctorPrecision) + { + var typeAliases = new List<string>(aliases) { nhibernateType.Name }; + foreach (var alias in typeAliases) + { + typeByTypeOfName[alias] = nhibernateType; + getTypeDelegatesWithPrecision.Add(alias, ctorPrecision); + } + } + /// <summary></summary> static TypeFactory() { @@ -113,10 +158,6 @@ // add the mappings of the NHibernate specific names that are used in type="" RegisterBuiltInTypes(); - - RegisterTypesWithVariableLength(); - - RegisterTypesWithVariablePrecision(); } /// <summary> @@ -128,24 +169,39 @@ private static void RegisterDefaultNetTypes() { // NOTE : each .NET type mut appear only one time - RegisterType(typeof (Byte[]), NHibernateUtil.Binary, new[] {"binary"}); + RegisterType(typeof (Byte[]), NHibernateUtil.Binary, new[] {"binary"}, + l => GetType(NHibernateUtil.Binary, l, len => new BinaryType(SqlTypeFactory.GetBinary(len)))); + RegisterType(typeof(Boolean), NHibernateUtil.Boolean, new[] { "boolean", "bool" }); RegisterType(typeof (Byte), NHibernateUtil.Byte, new[]{ "byte"}); RegisterType(typeof (Char), NHibernateUtil.Character, new[] {"character", "char"}); RegisterType(typeof (CultureInfo), NHibernateUtil.CultureInfo, new[]{ "locale"}); RegisterType(typeof (DateTime), NHibernateUtil.DateTime, new[]{ "datetime"} ); RegisterType(typeof (DateTimeOffset), NHibernateUtil.DateTimeOffset, new[]{ "datetimeoffset"}); - RegisterType(typeof (Decimal), NHibernateUtil.Decimal, new[] {"big_decimal", "decimal"}); - RegisterType(typeof (Double), NHibernateUtil.Double, new[]{ "double"}); + + RegisterType(typeof (Decimal), NHibernateUtil.Decimal, new[] {"big_decimal", "decimal"}, + (p, s) => GetType(NHibernateUtil.Decimal, p, s, st => new DecimalType(st))); + + RegisterType(typeof (Double), NHibernateUtil.Double, new[] {"double"}, + (p, s) => GetType(NHibernateUtil.Double, p, s, st => new DoubleType(st))); + RegisterType(typeof (Guid), NHibernateUtil.Guid, new[]{ "guid"}); RegisterType(typeof (Int16), NHibernateUtil.Int16, new[]{ "short"}); RegisterType(typeof (Int32), NHibernateUtil.Int32, new[] {"integer", "int"}); RegisterType(typeof (Int64), NHibernateUtil.Int64, new[]{ "long"}); RegisterType(typeof(SByte), NHibernateUtil.SByte, EmptyAliases); - RegisterType(typeof (Single), NHibernateUtil.Single, new[] {"float", "single"}); - RegisterType(typeof (String), NHibernateUtil.String, new[]{ "string"}); + + RegisterType(typeof (Single), NHibernateUtil.Single, new[] {"float", "single"}, + (p, s) => GetType(NHibernateUtil.Single, p, s, st => new SingleType(st))); + + RegisterType(typeof (String), NHibernateUtil.String, new[] {"string"}, + l => GetType(NHibernateUtil.String, l, len => new StringType(SqlTypeFactory.GetString(len)))); + RegisterType(typeof (TimeSpan), NHibernateUtil.TimeSpan, new[] {"timespan"}); - RegisterType(typeof (System.Type), NHibernateUtil.Class, new[] {"class"}); + + RegisterType(typeof (System.Type), NHibernateUtil.Class, new[] {"class"}, + l => GetType(NHibernateUtil.Class, l, len => new TypeType(SqlTypeFactory.GetString(len)))); + RegisterType(typeof (UInt16), NHibernateUtil.UInt16, new[] {"ushort"}); RegisterType(typeof (UInt32), NHibernateUtil.UInt32, new[] {"uint"}); RegisterType(typeof (UInt64), NHibernateUtil.UInt64, new[] {"ulong"}); @@ -163,10 +219,17 @@ /// </remarks> private static void RegisterBuiltInTypes() { - RegisterType(NHibernateUtil.AnsiString, EmptyAliases); + RegisterType(NHibernateUtil.AnsiString, EmptyAliases, + l => GetType(NHibernateUtil.AnsiString, l, len => new AnsiStringType(SqlTypeFactory.GetAnsiString(len)))); + RegisterType(NHibernateUtil.AnsiChar, EmptyAliases); - RegisterType(NHibernateUtil.BinaryBlob, EmptyAliases); - RegisterType(NHibernateUtil.StringClob, EmptyAliases); + + RegisterType(NHibernateUtil.BinaryBlob, EmptyAliases, + l => GetType(NHibernateUtil.BinaryBlob, l, len => new BinaryBlobType(SqlTypeFactory.GetBinaryBlob(len)))); + + RegisterType(NHibernateUtil.StringClob, EmptyAliases, + l => GetType(NHibernateUtil.StringClob, l, len => new StringClobType(SqlTypeFactory.GetStringClob(len)))); + RegisterType(NHibernateUtil.Date, new[] { "date" }); RegisterType(NHibernateUtil.Timestamp, new[] { "timestamp" }); RegisterType(NHibernateUtil.Time, new[] { "time" }); @@ -174,60 +237,20 @@ RegisterType(NHibernateUtil.YesNo, new[] { "yes_no" }); RegisterType(NHibernateUtil.Ticks, new[] { "ticks" }); RegisterType(NHibernateUtil.TimeAsTimeSpan, EmptyAliases); - RegisterType(NHibernateUtil.Currency, new[] { "currency" }); + + RegisterType(NHibernateUtil.Currency, new[] { "currency" }, + (p, s) => GetType(NHibernateUtil.Currency, p, s, st => new CurrencyType(st))); + RegisterType(NHibernateUtil.DateTime2, new[] { "datetime2" }); - RegisterType(NHibernateUtil.Serializable, new[] { "Serializable", "serializable" }); + RegisterType(NHibernateUtil.Serializable, new[] {"Serializable", "serializable"}, + l => + GetType(NHibernateUtil.Serializable, l, + len => new SerializableType(typeof (object), SqlTypeFactory.GetBinary(len)))); } - private static void RegisterTypesWithVariablePrecision() - { - getTypeDelegatesWithPrecision.Add(NHibernateUtil.Decimal.Name, - (p, s) => GetType(NHibernateUtil.Decimal, p, s, st => new DecimalType(st))); - getTypeDelegatesWithPrecision.Add(NHibernateUtil.Currency.Name, - (p, s) => GetType(NHibernateUtil.Currency, p, s, st => new CurrencyType(st))); - getTypeDelegatesWithPrecision.Add(NHibernateUtil.Double.Name, - (p, s) => GetType(NHibernateUtil.Double, p, s, st => new DoubleType(st))); - getTypeDelegatesWithPrecision.Add(NHibernateUtil.Single.Name, - (p, s) => GetType(NHibernateUtil.Single, p, s, st => new SingleType(st))); - } - - private static void RegisterTypesWithVariableLength() - { - getTypeDelegatesWithLength.Add(NHibernateUtil.Binary.Name, - l => - GetType(NHibernateUtil.Binary, l, len => new BinaryType(SqlTypeFactory.GetBinary(len)))); - getTypeDelegatesWithLength.Add(NHibernateUtil.BinaryBlob.Name, - l => - GetType(NHibernateUtil.BinaryBlob, l, - len => new BinaryBlobType(SqlTypeFactory.GetBinaryBlob(len)))); - getTypeDelegatesWithLength.Add(NHibernateUtil.Serializable.Name, - l => - GetType(NHibernateUtil.Serializable, l, - len => new SerializableType(typeof(object), SqlTypeFactory.GetBinary(len)))); - getTypeDelegatesWithLength.Add(NHibernateUtil.String.Name, - l => - GetType(NHibernateUtil.String, l, len => new StringType(SqlTypeFactory.GetString(len)))); - - getTypeDelegatesWithLength.Add(NHibernateUtil.StringClob.Name, - l => - GetType(NHibernateUtil.StringClob, l, - len => new StringClobType(SqlTypeFactory.GetStringClob(len)))); - - getTypeDelegatesWithLength.Add(NHibernateUtil.Class.Name, - l => - GetType(NHibernateUtil.Class, l, len => new TypeType(SqlTypeFactory.GetString(len)))); - getTypeDelegatesWithLength.Add(NHibernateUtil.AnsiString.Name, - l => - GetType(NHibernateUtil.AnsiString, l, - len => new AnsiStringType(SqlTypeFactory.GetAnsiString(len)))); - } - public ICollectionTypeFactory CollectionTypeFactory { - get - { - return Cfg.Environment.BytecodeProvider.CollectionTypeFactory; - } + get { return Cfg.Environment.BytecodeProvider.CollectionTypeFactory; } } private TypeFactory() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jul...@us...> - 2010-07-19 17:28:59
|
Revision: 5015 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5015&view=rev Author: julian-maughan Date: 2010-07-19 17:28:53 +0000 (Mon, 19 Jul 2010) Log Message: ----------- Fix for failing test Components/Basic/TestMergeComponent. Refinement of contributed patch (see NH-2011 and NH-2061) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2010-07-19 15:31:18 UTC (rev 5014) +++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2010-07-19 17:28:53 UTC (rev 5015) @@ -1121,14 +1121,14 @@ // need to extract the component values and check for subtype replacements... IAbstractComponentType componentType = (IAbstractComponentType)types[i]; IType[] subtypes = componentType.Subtypes; - object[] origComponentValues = original[i] == null - ? new object[subtypes.Length] - : componentType.GetPropertyValues(original[i], session); - object[] targetComponentValues = componentType.GetPropertyValues(target[i], session); - object[] componentCopy = ReplaceAssociations(origComponentValues, targetComponentValues, subtypes, session, null, copyCache, - foreignKeyDirection); - if (!componentType.IsAnyType) + object[] origComponentValues = original[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(original[i], session); + object[] targetComponentValues = target[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(target[i], session); + + object[] componentCopy = ReplaceAssociations(origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection); + + if (!componentType.IsAnyType && target[i] != null) componentType.SetPropertyValues(target[i], componentCopy, session.EntityMode); + copied[i] = target[i]; } else if (!types[i].IsAssociationType) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |