Navigation Menu

Skip to content

Commit

Permalink
make ApplyDefaultValues return row for chaining, add unassignedOnly flag
Browse files Browse the repository at this point in the history
  • Loading branch information
volkanceylan committed Aug 12, 2018
1 parent c02c600 commit 0588d78
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions Serenity.Data.Entity/Extensions/RowExtensions.cs
@@ -1,37 +1,32 @@
using Serenity.Data.Mapping;
using System;
using System;
using System.Globalization;

namespace Serenity.Data
{
public static class RowExtensions
{
/// <summary>
/// <see cref="Row"/> türevi nesnenin bir kopyasını çıkarır</summary>
/// <remarks>
/// Bu fonksiyon bir extension metodu olduğundan direk olarak <c>row.Clone()</c> şeklinde
/// kullanılabilir. <see cref="Row.CloneRow()"/> metodu da bir row un kopyasını çıkarır, fakat
/// sonuç Row türündendir, tekrar asıl Row türevine typecast yapmak gerekir. Bu yardımcı
/// fonksiyonla explicit olarak typecast yapmaya gerek kalmaz.</remarks>
/// <typeparam name="TRow">
/// Row'dan türemiş herhangi bir Row sınıfı</typeparam>
/// <param name="row">
/// Kopyalanacak Row türevi nesne</param>
/// <returns>
/// Fonksiyonun uygulandığı Row türevinin, bir kopyası (sadece alan değerleri)</returns>
public static TRow Clone<TRow>(this TRow row) where TRow : Row
{
return (TRow)(row.CloneRow());
}

public static void ApplyDefaultValues(this Row row)
public static TRow ApplyDefaultValues<TRow>(this TRow row, bool unassignedOnly = false)
where TRow: Row
{
if (row == null)
throw new ArgumentNullException("row");

foreach (var field in row.GetFields())
{
if (unassignedOnly && row.IsAssigned(field))
continue;

var value = field.DefaultValue;
if (value != null)
field.AsObject(row, field.ConvertValue(value, CultureInfo.InvariantCulture));
}

return row;
}

public static TRowFields Init<TRowFields>(this TRowFields rowFields)
Expand Down

0 comments on commit 0588d78

Please sign in to comment.