コード例 #1
0
        private static PropertyInfo GetPropertyInfoBase(List <PropertyInfo> properties, Predicate <SystemCsvColumnAttribute> predicate)
        {
            PropertyInfo result = null;

            foreach (PropertyInfo pi in properties)
            {
                if (pi.CanWrite)
                {
                    object[] attrs = pi.GetCustomAttributes(typeof(SystemCsvColumnAttribute), false);
                    if (attrs.Count() == 1)
                    {
                        SystemCsvColumnAttribute attr = (SystemCsvColumnAttribute)attrs[0];
                        if (predicate.Invoke(attr))
                        {
                            result = pi;
                        }
                    }
                }
            }
            if (result != null)
            {
                properties.Remove(result);
            }

            return(result);
        }
コード例 #2
0
ファイル: CsvConfig.cs プロジェクト: EricWebsmith/TankWorld
        public CsvConfig(Type csvType)
            : this()
        {
            CsvObjectAttribute objAttr = csvType.GetAttribute <CsvObjectAttribute>();

            if (objAttr != null)
            {
                this.CodePage    = objAttr.CodePage;
                this.HasHeader   = objAttr.HasHeader;
                this.MappingType = objAttr.MappingType;
                this.Delimiter   = objAttr.Delimiter;
                this.Name        = objAttr.Name;
                this.ObjectType  = csvType.Name + ", " + csvType.Assembly.GetName().Name;
            }
            else
            {
                this.Name = csvType.Name;
            }

            this.IsChanged = false;

            this.Columns.Clear();
            foreach (PropertyInfo pi in csvType.GetProperties())
            {
                SystemCsvColumnAttribute colAttr = pi.GetAttribute <SystemCsvColumnAttribute>();
                if (colAttr != null)
                {
                    this.Columns.Add(colAttr.Column);
                }
            }
        }