/// <summary> /// 指定された型に対するマッピング情報を生成します。 /// </summary> /// <param name="type">対象となる型情報</param> /// <returns>テーブルマッピング情報</returns> public static This Create(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } This result = null; lock (This.cache) { //--- キャッシュから取得 if (!This.cache.TryGetValue(type, out result)) { //--- テーブル情報 var table = type.GetCustomAttribute <TableAttribute>(false); result = new This() { Schema = table?.Schema ?? null, Name = table?.Name ?? type.Name, Type = type }; //--- 列情報 var flags = BindingFlags.Instance | BindingFlags.Public; var notMapped = typeof(NotMappedAttribute); result.Columns = type.GetProperties(flags) .Where(x => x.CustomAttributes.All(y => y.AttributeType != notMapped)) .Select(ColumnMappingInfo.From) .ToArray(); //--- キャッシュ This.cache.Add(type, result); } } return(result); }
/// <summary> /// 指定された型に対するマッピング情報を生成します。 /// </summary> /// <typeparam name="T">対象となる型情報</typeparam> /// <returns>テーブルマッピング情報</returns> public static This Create <T>() => This.Create(typeof(T));