Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply most fixups #197

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions sources/OpenMcdf.Extensions/OLEProperties/Common.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace OpenMcdf.Extensions.OLEProperties
namespace OpenMcdf.Extensions.OLEProperties
{
public enum Behavior
{
Expand Down
3 changes: 1 addition & 2 deletions sources/OpenMcdf.Extensions/OLEProperties/DictionaryEntry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using System.Text;

namespace OpenMcdf.Extensions.OLEProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public DictionaryProperty(int codePage)

public object Value
{
get { return entries; }
set { entries = (Dictionary<uint, string>)value; }
get => entries;
set => entries = (Dictionary<uint, string>)value;
}

public void Read(BinaryReader br)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OpenMcdf.Extensions.OLEProperties
{
public class OLEPropertiesContainer
{
public Dictionary<uint, string> PropertyNames = null;
public Dictionary<uint, string> PropertyNames;

public OLEPropertiesContainer UserDefinedProperties { get; private set; }

Expand All @@ -19,7 +19,7 @@ public class OLEPropertiesContainer

public PropertyContext Context { get; }

private readonly List<OLEProperty> properties = new List<OLEProperty>();
private readonly List<OLEProperty> properties = new();
internal CFStream cfStream;

/*
Expand Down Expand Up @@ -98,7 +98,7 @@ internal OLEPropertiesContainer(CFStream cfStream)
FmtID0 = pStream.FMTID0;

PropertyNames = (Dictionary<uint, string>)pStream.PropertySet0.Properties
.Where(p => p.PropertyType == PropertyType.DictionaryProperty).FirstOrDefault()?.Value;
.FirstOrDefault(p => p.PropertyType == PropertyType.DictionaryProperty)?.Value;

Context = new PropertyContext()
{
Expand Down Expand Up @@ -149,7 +149,7 @@ internal OLEPropertiesContainer(CFStream cfStream)
}

var existingPropertyNames = (Dictionary<uint, string>)pStream.PropertySet1.Properties
.Where(p => p.PropertyType == PropertyType.DictionaryProperty).FirstOrDefault()?.Value;
.FirstOrDefault(p => p.PropertyType == PropertyType.DictionaryProperty)?.Value;

UserDefinedProperties.PropertyNames = existingPropertyNames ?? new Dictionary<uint, string>();
}
Expand Down Expand Up @@ -178,7 +178,7 @@ public void AddProperty(OLEProperty property)
public void RemoveProperty(uint propertyIdentifier)
{
//throw new NotImplementedException("API Unstable - Work in progress - Milestone 2.3.0.0");
var toRemove = properties.Where(o => o.PropertyIdentifier == propertyIdentifier).FirstOrDefault();
var toRemove = properties.FirstOrDefault(o => o.PropertyIdentifier == propertyIdentifier);

if (toRemove != null)
properties.Remove(toRemove);
Expand Down
10 changes: 2 additions & 8 deletions sources/OpenMcdf.Extensions/OLEProperties/OLEProperty.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

using System;

namespace OpenMcdf.Extensions.OLEProperties
namespace OpenMcdf.Extensions.OLEProperties
{
public class OLEProperty
{
Expand Down Expand Up @@ -47,10 +44,7 @@ public object Value

return value;
}
set
{
this.value = value;
}
set => this.value = value;
}

public override bool Equals(object obj)
Expand Down
54 changes: 26 additions & 28 deletions sources/OpenMcdf.Extensions/OLEProperties/PropertyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected virtual ITypedPropertyValue CreateLpstrProperty(VTPropertyType vType,

#region Property implementations

private class VT_EMPTY_Property : TypedPropertyValue<object>
private sealed class VT_EMPTY_Property : TypedPropertyValue<object>
{
public VT_EMPTY_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -70,7 +70,7 @@ public override void WriteScalarValue(BinaryWriter bw, object pValue)
}
}

private class VT_I1_Property : TypedPropertyValue<sbyte>
private sealed class VT_I1_Property : TypedPropertyValue<sbyte>
{
public VT_I1_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -88,7 +88,7 @@ public override void WriteScalarValue(BinaryWriter bw, sbyte pValue)
}
}

private class VT_UI1_Property : TypedPropertyValue<byte>
private sealed class VT_UI1_Property : TypedPropertyValue<byte>
{
public VT_UI1_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -106,7 +106,7 @@ public override void WriteScalarValue(BinaryWriter bw, byte pValue)
}
}

private class VT_UI4_Property : TypedPropertyValue<uint>
private sealed class VT_UI4_Property : TypedPropertyValue<uint>
{
public VT_UI4_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -124,7 +124,7 @@ public override void WriteScalarValue(BinaryWriter bw, uint pValue)
}
}

private class VT_UI8_Property : TypedPropertyValue<ulong>
private sealed class VT_UI8_Property : TypedPropertyValue<ulong>
{
public VT_UI8_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -142,7 +142,7 @@ public override void WriteScalarValue(BinaryWriter bw, ulong pValue)
}
}

private class VT_I2_Property : TypedPropertyValue<short>
private sealed class VT_I2_Property : TypedPropertyValue<short>
{
public VT_I2_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -160,7 +160,7 @@ public override void WriteScalarValue(BinaryWriter bw, short pValue)
}
}

private class VT_UI2_Property : TypedPropertyValue<ushort>
private sealed class VT_UI2_Property : TypedPropertyValue<ushort>
{
public VT_UI2_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -178,7 +178,7 @@ public override void WriteScalarValue(BinaryWriter bw, ushort pValue)
}
}

private class VT_I4_Property : TypedPropertyValue<int>
private sealed class VT_I4_Property : TypedPropertyValue<int>
{
public VT_I4_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -196,7 +196,7 @@ public override void WriteScalarValue(BinaryWriter bw, int pValue)
}
}

private class VT_I8_Property : TypedPropertyValue<long>
private sealed class VT_I8_Property : TypedPropertyValue<long>
{
public VT_I8_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -214,7 +214,7 @@ public override void WriteScalarValue(BinaryWriter bw, long pValue)
}
}

private class VT_INT_Property : TypedPropertyValue<int>
private sealed class VT_INT_Property : TypedPropertyValue<int>
{
public VT_INT_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -232,7 +232,7 @@ public override void WriteScalarValue(BinaryWriter bw, int pValue)
}
}

private class VT_UINT_Property : TypedPropertyValue<uint>
private sealed class VT_UINT_Property : TypedPropertyValue<uint>
{
public VT_UINT_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -250,7 +250,7 @@ public override void WriteScalarValue(BinaryWriter bw, uint pValue)
}
}

private class VT_R4_Property : TypedPropertyValue<float>
private sealed class VT_R4_Property : TypedPropertyValue<float>
{
public VT_R4_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -268,7 +268,7 @@ public override void WriteScalarValue(BinaryWriter bw, float pValue)
}
}

private class VT_R8_Property : TypedPropertyValue<double>
private sealed class VT_R8_Property : TypedPropertyValue<double>
{
public VT_R8_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -286,7 +286,7 @@ public override void WriteScalarValue(BinaryWriter bw, double pValue)
}
}

private class VT_CY_Property : TypedPropertyValue<long>
private sealed class VT_CY_Property : TypedPropertyValue<long>
{
public VT_CY_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -307,7 +307,7 @@ public override void WriteScalarValue(BinaryWriter bw, long pValue)
}
}

private class VT_DATE_Property : TypedPropertyValue<DateTime>
private sealed class VT_DATE_Property : TypedPropertyValue<DateTime>
{
public VT_DATE_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand Down Expand Up @@ -402,8 +402,6 @@ public override void WriteScalarValue(BinaryWriter bw, string pValue)
//if (addNullTerminator)
dataLength += 1; // null terminator \u+0000

var mod = dataLength % 4; // pad to multiple of 4 bytes

bw.Write(dataLength); // datalength of string + null char (unicode)
bw.Write(data); // string

Expand All @@ -418,15 +416,15 @@ public override void WriteScalarValue(BinaryWriter bw, string pValue)
}
}

protected class VT_Unaligned_LPSTR_Property : VT_LPSTR_Property
protected sealed class VT_Unaligned_LPSTR_Property : VT_LPSTR_Property
{
public VT_Unaligned_LPSTR_Property(VTPropertyType vType, int codePage, bool isVariant) : base(vType, codePage, isVariant)
{
NeedsPadding = false;
}
}

private class VT_LPWSTR_Property : TypedPropertyValue<string>
private sealed class VT_LPWSTR_Property : TypedPropertyValue<string>
{
private byte[] data;
private readonly int codePage;
Expand Down Expand Up @@ -476,7 +474,7 @@ public override void WriteScalarValue(BinaryWriter bw, string pValue)
}
}

private class VT_FILETIME_Property : TypedPropertyValue<DateTime>
private sealed class VT_FILETIME_Property : TypedPropertyValue<DateTime>
{
public VT_FILETIME_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -495,7 +493,7 @@ public override void WriteScalarValue(BinaryWriter bw, DateTime pValue)
}
}

private class VT_DECIMAL_Property : TypedPropertyValue<decimal>
private sealed class VT_DECIMAL_Property : TypedPropertyValue<decimal>
{
public VT_DECIMAL_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand Down Expand Up @@ -538,15 +536,15 @@ public override void WriteScalarValue(BinaryWriter bw, decimal pValue)
}
}

private class VT_BOOL_Property : TypedPropertyValue<bool>
private sealed class VT_BOOL_Property : TypedPropertyValue<bool>
{
public VT_BOOL_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
}

public override bool ReadScalarValue(BinaryReader br)
{
propertyValue = br.ReadUInt16() == 0xFFFF ? true : false;
propertyValue = br.ReadUInt16() == 0xFFFF;
return (bool)propertyValue;
//br.ReadUInt16();//padding
}
Expand All @@ -557,7 +555,7 @@ public override void WriteScalarValue(BinaryWriter bw, bool pValue)
}
}

private class VT_CF_Property : TypedPropertyValue<object>
private sealed class VT_CF_Property : TypedPropertyValue<object>
{
public VT_CF_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand Down Expand Up @@ -585,7 +583,7 @@ public override void WriteScalarValue(BinaryWriter bw, object pValue)
}
}

private class VT_BLOB_Property : TypedPropertyValue<object>
private sealed class VT_BLOB_Property : TypedPropertyValue<object>
{
public VT_BLOB_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -612,7 +610,7 @@ public override void WriteScalarValue(BinaryWriter bw, object pValue)
}
}

private class VT_CLSID_Property : TypedPropertyValue<object>
private sealed class VT_CLSID_Property : TypedPropertyValue<object>
{
public VT_CLSID_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{
Expand All @@ -631,7 +629,7 @@ public override void WriteScalarValue(BinaryWriter bw, object pValue)
}
}

private class VT_VariantVector : TypedPropertyValue<object>
private sealed class VT_VariantVector : TypedPropertyValue<object>
{
private readonly int codePage;
private readonly PropertyFactory factory;
Expand Down Expand Up @@ -681,7 +679,7 @@ internal sealed class DocumentSummaryInfoPropertyFactory : PropertyFactory
protected override ITypedPropertyValue CreateLpstrProperty(VTPropertyType vType, int codePage, uint propertyIdentifier, bool isVariant)
{
// PIDDSI_HEADINGPAIR and PIDDSI_DOCPARTS use unaligned (unpadded) strings - the others are padded
if (propertyIdentifier == 0x0000000C || propertyIdentifier == 0x0000000D)
if (propertyIdentifier is 0x0000000C or 0x0000000D)
{
return new VT_Unaligned_LPSTR_Property(vType, codePage, isVariant);
}
Expand Down
2 changes: 1 addition & 1 deletion sources/OpenMcdf.Extensions/OLEProperties/PropertySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void LoadContext(int propertySetOffset, BinaryReader br)
var currPos = br.BaseStream.Position;

PropertyContext = new PropertyContext();
var codePageOffset = (int)(propertySetOffset + PropertyIdentifierAndOffsets.Where(pio => pio.PropertyIdentifier == 1).First().Offset);
var codePageOffset = (int)(propertySetOffset + PropertyIdentifierAndOffsets.First(pio => pio.PropertyIdentifier == 1).Offset);
br.BaseStream.Seek(codePageOffset, SeekOrigin.Begin);

VTPropertyType vType = (VTPropertyType)br.ReadUInt16();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void Read(BinaryReader br)
}
}

private class OffsetContainer
private sealed class OffsetContainer
{
public int OffsetPS { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;

namespace OpenMcdf.Extensions.OLEProperties
{
Expand All @@ -16,7 +15,7 @@ public enum ContainerType

public static class CommonIdentifiers
{
public static Dictionary<uint, string> PropertyIdentifiersSummaryInfo = new Dictionary<uint, string>()
public static Dictionary<uint, string> PropertyIdentifiersSummaryInfo = new()
{
{0x00000001, "CodePageString" },
{0x00000002, "PIDSI_TITLE" },
Expand All @@ -38,7 +37,7 @@ public static class CommonIdentifiers
{0x00000013, "PIDSI_DOC_SECURITY" }
};

public static Dictionary<uint, string> PropertyIdentifiersDocumentSummaryInfo = new Dictionary<uint, string>()
public static Dictionary<uint, string> PropertyIdentifiersDocumentSummaryInfo = new()
{
{0x00000001, "CodePageString" },
{0x00000002, "PIDDSI_CATEGORY" },
Expand Down
Loading