Skip to content

Commit

Permalink
reorder to simplify doc comment review and reinforce logical grouping…
Browse files Browse the repository at this point in the history
…s of related methods and overloads.

no code changes present in this commit; only code locality changes and region scope naming.
  • Loading branch information
Ste1io committed Jul 27, 2023
1 parent b11ff37 commit e294f5b
Show file tree
Hide file tree
Showing 15 changed files with 774 additions and 685 deletions.
24 changes: 12 additions & 12 deletions PetaPoco/Core/ColumnInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ public class ColumnInfo
/// <seealso cref="ColumnAttribute.UpdateTemplate"/>
public string UpdateTemplate { get; set; }

/// <summary>
/// Creates and populates a ColumnInfo from the attributes of a POCO property.
/// </summary>
/// <param name="propertyInfo">The POCO property to use for initializing the ColumnInfo.</param>
/// <returns>A ColumnInfo instance.</returns>
public static ColumnInfo FromProperty(PropertyInfo propertyInfo)
{
var ci = new ColumnInfo();
PopulateFromProperty(propertyInfo, ref ci, out _);
return ci;
}

internal static void PopulateFromProperty(PropertyInfo pi, ref ColumnInfo ci, out ColumnAttribute columnAttr)
{
// Check if declaring poco has [Explicit] attribute
Expand Down Expand Up @@ -123,17 +135,5 @@ internal static void PopulateFromProperty(PropertyInfo pi, ref ColumnInfo ci, ou
}
}
}

/// <summary>
/// Creates and populates a ColumnInfo from the attributes of a POCO property.
/// </summary>
/// <param name="propertyInfo">The POCO property to use for initializing the ColumnInfo.</param>
/// <returns>A ColumnInfo instance.</returns>
public static ColumnInfo FromProperty(PropertyInfo propertyInfo)
{
var ci = new ColumnInfo();
PopulateFromProperty(propertyInfo, ref ci, out _);
return ci;
}
}
}
12 changes: 12 additions & 0 deletions PetaPoco/Core/IGridReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ namespace PetaPoco
/// </summary>
public interface IGridReader : IDisposable
{
#region ReadSinglePoco

/// <summary>
/// Performs a read, returning the results as an <see cref="IEnumerable{T}"/> collection.
/// </summary>
/// <typeparam name="T">The POCO type representing a row in the result set.</typeparam>
/// <returns>An enumerable collection of <typeparamref name="T"/> POCOs containing the result records.</returns>
IEnumerable<T> Read<T>();

#endregion

#region ReadMultiPoco : auto-mapping

/// <inheritdoc cref="Read{T1,T2,T3,T4}()"/>
IEnumerable<T1> Read<T1, T2>();

Expand All @@ -31,6 +37,10 @@ public interface IGridReader : IDisposable
/// <returns>An enumerable collection of <typeparamref name="T1"/> POCOs containing the result records.</returns>
IEnumerable<T1> Read<T1, T2, T3, T4>();

#endregion

#region ReadMultiPoco : custom-mapping

/// <inheritdoc cref="Read{T1, T2, T3, T4, TRet}(Func{T1,T2,T3,T4,TRet})"/>
IEnumerable<TRet> Read<T1, T2, TRet>(Func<T1, T2, TRet> func);

Expand All @@ -48,5 +58,7 @@ public interface IGridReader : IDisposable
/// <param name="func">A callback function to used to connect the POCO instances, or <see langword="null"/> to let PetaPoco automatically deduce the relationships.</param>
/// <returns>An enumerable collection of <typeparamref name="TRet"/> POCOs containing the result records.</returns>
IEnumerable<TRet> Read<T1, T2, T3, T4, TRet>(Func<T1, T2, T3, T4, TRet> func);

#endregion
}
}
28 changes: 14 additions & 14 deletions PetaPoco/Core/PocoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public PocoData(Type type, IMapper defaultMapper)
QueryColumns = (from c in Columns where !c.Value.ResultColumn || c.Value.AutoSelectedResultColumn select c.Key).ToArray();
}

public static PocoData ForType(Type type, IMapper defaultMapper)
{
if (type == typeof(System.Dynamic.ExpandoObject))
throw new InvalidOperationException("Can't use dynamic types with this method");

return _pocoDatas.GetOrAdd(type, () => new PocoData(type, defaultMapper));
}

public static PocoData ForObject(object obj, string primaryKeyName, IMapper defaultMapper)
{
var t = obj.GetType();
Expand All @@ -97,20 +105,6 @@ public static PocoData ForObject(object obj, string primaryKeyName, IMapper defa
return ForType(t, defaultMapper);
}

public static PocoData ForType(Type type, IMapper defaultMapper)
{
if (type == typeof(System.Dynamic.ExpandoObject))
throw new InvalidOperationException("Can't use dynamic types with this method");

return _pocoDatas.GetOrAdd(type, () => new PocoData(type, defaultMapper));
}

private static bool IsIntegralType(Type type)
{
var tc = Type.GetTypeCode(type);
return tc >= TypeCode.SByte && tc <= TypeCode.UInt64;
}

// Create factory function that can convert a IDataReader record into a POCO
public Delegate GetFactory(string sql, string connectionString, int firstColumn, int countColumns, IDataReader reader, IMapper defaultMapper)
{
Expand Down Expand Up @@ -393,6 +387,12 @@ private static Func<object, object> GetConverter(IMapper mapper, PocoColumn pc,
return null;
}

private static bool IsIntegralType(Type type)
{
var tc = Type.GetTypeCode(type);
return tc >= TypeCode.SByte && tc <= TypeCode.UInt64;
}

private static T RecurseInheritedTypes<T>(Type t, Func<Type, T> cb)
{
while (t != null)
Expand Down
Loading

0 comments on commit e294f5b

Please sign in to comment.