コード例 #1
0
        public static T ReadObject <T>(hid_t groupId, T readValue, string groupName)
        {
            if (readValue == null)
            {
                throw new ArgumentNullException(nameof(readValue));
            }
            bool isGroupName = !string.IsNullOrWhiteSpace(groupName);

            if (isGroupName)
            {
                groupId = H5G.open(groupId, groupName);
            }

            Type tyObject = readValue.GetType();

            foreach (Attribute attr in Attribute.GetCustomAttributes(tyObject))
            {
                if (attr is Hdf5GroupName)
                {
                    groupName = (attr as Hdf5GroupName).Name;
                }
                if (attr is Hdf5SaveAttribute)
                {
                    Hdf5SaveAttribute atLeg = attr as Hdf5SaveAttribute;
                    if (atLeg.SaveKind == Hdf5Save.DoNotSave)
                    {
                        return(readValue);
                    }
                }
            }


            ReadFields(tyObject, readValue, groupId);
            ReadProperties(tyObject, readValue, groupId);

            if (isGroupName)
            {
                Hdf5.CloseGroup(groupId);
            }
            return(readValue);
        }
コード例 #2
0
        public static object WriteObject(hid_t groupId, object writeValue, string groupName = null)
        {
            if (writeValue == null)
            {
                throw new ArgumentNullException(nameof(writeValue));
            }

            bool createGroupName = !string.IsNullOrWhiteSpace(groupName);

            if (createGroupName)
            {
                groupId = Hdf5.CreateGroup(groupId, groupName);
            }

            Type tyObject = writeValue.GetType();

            foreach (Attribute attr in Attribute.GetCustomAttributes(tyObject))
            {
                Hdf5SaveAttribute legAt = attr as Hdf5SaveAttribute;
                if (legAt != null)
                {
                    Hdf5Save kind = legAt.SaveKind;
                    if (kind == Hdf5Save.DoNotSave)
                    {
                        return(writeValue);
                    }
                }
            }

            WriteProperties(tyObject, writeValue, groupId);
            WriteFields(tyObject, writeValue, groupId);
            WriteHdf5Attributes(tyObject, groupId, groupName);
            if (createGroupName)
            {
                Hdf5.CloseGroup(groupId);
            }
            return(writeValue);
        }