Esempio n. 1
0
        private void OnLoad(object sender, EventArgs e)
        {
            var storageEnumerable = typeof(StorageEnumerable <>).MakeGenericType(RecordType);

            foreach (var propInfo in RecordType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (!propInfo.PropertyType.IsArray)
                {
                    var colGen = new OLVColumn
                    {
                        AspectName = propInfo.Name,
                        Text       = propInfo.Name
                    };

                    if (propInfo.IsDefined(typeof(IndexAttribute), false))
                    {
                        fastObjectListView1.Columns.Insert(0, colGen);
                    }
                    else
                    {
                        fastObjectListView1.Columns.Add(colGen);
                    }
                }
                else
                {
                    var arity = propInfo.GetCustomAttribute <CardinalityAttribute>();
                    for (var i = 0; i < arity.SizeConst; ++i)
                    {
                        OLVColumn colGen = null;
                        colGen = new OLVColumn
                        {
                            AspectGetter = (o) => ((Array)o).GetValue((int)colGen.Tag),
                            Text         = $"{propInfo.Name}[{i}]",
                            Tag          = i,
                        };

                        fastObjectListView1.Columns.Add(colGen);
                    }
                }
            }

            var options = new StorageOptions()
            {
                CopyToMemory       = false,
                LoadMask           = LoadMask.Records,
                InternStrings      = true,
                MemberType         = MemberTypes.Property,
                IgnoreSignedChecks = true
            };

            Stream.Position = 0;
            var enumerable = (IEnumerable)Activator.CreateInstance(storageEnumerable, Stream, options);

            fastObjectListView1.Objects = enumerable;
        }