Skip to content

Commit 0fe8319

Browse files
committed
TypeHelper class code formatting and performance improvements
1 parent 4bb2ba0 commit 0fe8319

4 files changed

Lines changed: 497 additions & 389 deletions

File tree

Orm/Xtensive.Orm.Tests.Core/Reflection/TypeHelperTest.cs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,64 @@ public void IsNumericTest()
421421
this.GetType(),
422422
};
423423

424-
foreach (var numericType in numericTypes)
424+
foreach (var numericType in numericTypes) {
425425
Assert.IsTrue(numericType.IsNumericType());
426+
}
426427

427-
foreach (var nonNumericType in nonNumericTypes)
428+
foreach (var nonNumericType in nonNumericTypes) {
428429
Assert.IsFalse(nonNumericType.IsNumericType());
430+
}
431+
}
432+
433+
[Test]
434+
public void IsNullableTest()
435+
{
436+
var nullableTypes = new[] {
437+
typeof (Nullable<>),
438+
typeof (byte?),
439+
typeof (sbyte?),
440+
typeof (short?),
441+
typeof (ushort?),
442+
typeof (int?),
443+
typeof (uint?),
444+
typeof (long?),
445+
typeof (ulong?),
446+
typeof (float?),
447+
typeof (double?),
448+
typeof (decimal?),
449+
typeof (Guid?)
450+
};
451+
452+
var nonNullableTypes = new[] {
453+
typeof (string),
454+
typeof (char),
455+
typeof (bool),
456+
typeof (DateTime),
457+
typeof (TimeSpan),
458+
typeof (Guid),
459+
typeof (TypeCode),
460+
typeof (byte[]),
461+
typeof (Key),
462+
this.GetType()
463+
};
464+
465+
foreach (var type in nullableTypes) {
466+
Assert.IsTrue(type.IsNullable());
467+
}
468+
469+
foreach (var type in nonNullableTypes) {
470+
Assert.IsFalse(type.IsNullable());
471+
}
472+
}
473+
474+
[Test]
475+
public void GenericIsNullableTest()
476+
{
477+
Assert.IsTrue(TypeHelper.IsNullable<Guid?>());
478+
Assert.IsTrue(TypeHelper.IsNullable<int?>());
479+
480+
Assert.IsFalse(TypeHelper.IsNullable<int>());
481+
Assert.IsFalse(TypeHelper.IsNullable<string>());
429482
}
430483
}
431484
}

Orm/Xtensive.Orm/Orm/Upgrade/Internals/DomainModelConverter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,7 @@ private static void CreateHierarchyForeignKey(TableInfo referencingTable, TableI
463463

464464
private static Type ToNullable(Type type, bool isNullable)
465465
{
466-
return isNullable && type.IsValueType && !type.IsNullable()
467-
? type.ToNullable()
468-
: type;
466+
return isNullable ? type.ToNullable() : type;
469467
}
470468

471469
private void ProcessDirectAssociation(TypeInfo ownerType, FieldInfo ownerField, TypeInfo targetType)

Orm/Xtensive.Orm/Orm/Upgrade/Internals/SqlModelConverter.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,10 @@ private StorageTypeInfo ExtractType(TableColumn column)
263263
return StorageTypeInfo.Undefined;
264264
}
265265

266-
if (column.IsNullable
267-
&& type.IsValueType
268-
&& !type.IsNullable())
266+
if (column.IsNullable) {
269267
type = type.ToNullable();
270-
268+
}
269+
271270
return new StorageTypeInfo(type, sqlValueType, column.IsNullable, sqlValueType.Length, sqlValueType.Precision, sqlValueType.Scale);
272271
}
273272

0 commit comments

Comments
 (0)