Beispiel #1
0
        private T GetProperty <T>(uint fileIndex, ItemPropId name)
        {
            PropVariant propVariant = new PropVariant();

            this.archive.GetProperty(fileIndex, name, ref propVariant);
            object value = propVariant.GetObject();

            if (propVariant.VarType == VarEnum.VT_EMPTY)
            {
                propVariant.Clear();
                return(default(T));
            }

            propVariant.Clear();

            if (value == null)
            {
                return(default(T));
            }

            Type type           = typeof(T);
            bool isNullable     = type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>);
            Type underlyingType = isNullable ? Nullable.GetUnderlyingType(type) : type;

            T result = (T)Convert.ChangeType(value.ToString(), underlyingType);

            return(result);
        }
Beispiel #2
0
        private T GetProperty <T>(uint fileIndex, ItemPropId name)
        {
            PropVariant propVariant = new PropVariant();

            this.archive.GetProperty(fileIndex, name, ref propVariant);

            T result = propVariant.VarType != VarEnum.VT_EMPTY
                ? (T)propVariant.GetObject()
                : default(T);

            propVariant.Clear();

            return(result);
        }