コード例 #1
0
ファイル: ColumnInfo.cs プロジェクト: bamboo82/AsyncPoco
        /// <summary>
        /// Creates and populates a ColumnInfo from the attributes of a POCO property.
        /// </summary>
        /// <param name="pi">The property whose column info is required</param>
        /// <returns>A ColumnInfo instance</returns>
        public static ColumnInfo FromProperty(PropertyInfo pi)
        {
            // Check if declaring poco has [Explicit] attribute
            bool ExplicitColumns = pi.DeclaringType.GetCustomAttributes(typeof(ExplicitColumnsAttribute), true).Length > 0;

            // Check for [Column]/[Ignore] Attributes
            var ColAttrs = pi.GetCustomAttributes(typeof(ColumnAttribute), true);
            if (ExplicitColumns)
            {
                if (ColAttrs.Length == 0)
                    return null;
            }
            else
            {
                if (pi.GetCustomAttributes(typeof(IgnoreAttribute), true).Length != 0)
                    return null;
            }

            ColumnInfo ci = new ColumnInfo();

            // Read attribute
            if (ColAttrs.Length > 0)
            {
                var colattr = (ColumnAttribute)ColAttrs[0];

                ci.ColumnName = colattr.Name==null ? pi.Name : colattr.Name;
                ci.ForceToUtc = colattr.ForceToUtc;
                if ((colattr as ResultColumnAttribute) != null)
                    ci.ResultColumn = true;
                if ((colattr as ComputedColumnAttribute) != null)
                    ci.ComputedColumn = true;

            }
            else
            {
                ci.ColumnName = pi.Name;
                ci.ForceToUtc = false;
                ci.ResultColumn = false;
                ci.ComputedColumn = false;
            }

            return ci;
        }
コード例 #2
0
 /// <summary>
 /// Constructs a ColumnInfo for a POCO property by reading its attribute data
 /// </summary>
 /// <param name="pocoProperty"></param>
 /// <returns></returns>
 public ColumnInfo GetColumnInfo(PropertyInfo pocoProperty)
 {
     return(ColumnInfo.FromProperty(pocoProperty));
 }