Skip to content

Commit e2f52b5

Browse files
committed
C#10 changes
2 parents a85dea0 + 76c3dac commit e2f52b5

28 files changed

+419
-464
lines changed

sources/OpenMcdf.Extensions/OLEProperties/DictionaryEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void Write(BinaryWriter bw)
5454

5555
private string GetName()
5656
{
57-
var result = Encoding.GetEncoding(this.codePage).GetString(nameBytes);
57+
var result = Encoding.GetEncoding(codePage).GetString(nameBytes);
5858

5959
result = result.Trim('\0');
6060

sources/OpenMcdf.Extensions/OLEProperties/DictionaryProperty.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class DictionaryProperty : IDictionaryProperty
1212
public DictionaryProperty(int codePage)
1313
{
1414
this.codePage = codePage;
15-
this.entries = new Dictionary<uint, string>();
15+
entries = new Dictionary<uint, string>();
1616
}
1717

1818
public PropertyType PropertyType => PropertyType.DictionaryProperty;
@@ -36,7 +36,7 @@ public void Read(BinaryReader br)
3636
DictionaryEntry de = new DictionaryEntry(codePage);
3737

3838
de.Read(br);
39-
this.entries.Add(de.PropertyIdentifier, de.Name);
39+
entries.Add(de.PropertyIdentifier, de.Name);
4040
}
4141

4242
int m = (int)(br.BaseStream.Position - curPos) % 4;
@@ -79,7 +79,7 @@ private void WriteEntry(BinaryWriter bw, uint propertyIdentifier, string name)
7979
bw.Write(propertyIdentifier);
8080

8181
// Encode string data with the current codepage
82-
var nameBytes = Encoding.GetEncoding(this.codePage).GetBytes(name);
82+
var nameBytes = Encoding.GetEncoding(codePage).GetBytes(name);
8383
uint byteLength = (uint)nameBytes.Length;
8484

8585
// If the code page is WINUNICODE, write the length as the number of characters and pad the length to a multiple of 4 bytes

sources/OpenMcdf.Extensions/OLEProperties/OLEPropertiesContainer.cs

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public OLEPropertiesContainer(int codePage, ContainerType containerType)
7676
Behavior = Behavior.CaseInsensitive
7777
};
7878

79-
this.ContainerType = containerType;
79+
ContainerType = containerType;
8080
}
8181

8282
internal OLEPropertiesContainer(CFStream cfStream)
@@ -86,25 +86,18 @@ internal OLEPropertiesContainer(CFStream cfStream)
8686
this.cfStream = cfStream;
8787
pStream.Read(new BinaryReader(new StreamDecorator(cfStream)));
8888

89-
switch (pStream.FMTID0.ToString("B").ToUpperInvariant())
89+
ContainerType = pStream.FMTID0.ToString("B").ToUpperInvariant() switch
9090
{
91-
case WellKnownFMTID.FMTID_SummaryInformation:
92-
this.ContainerType = ContainerType.SummaryInfo;
93-
break;
94-
case WellKnownFMTID.FMTID_DocSummaryInformation:
95-
this.ContainerType = ContainerType.DocumentSummaryInfo;
96-
break;
97-
default:
98-
this.ContainerType = ContainerType.AppSpecific;
99-
break;
100-
}
101-
102-
this.FmtID0 = pStream.FMTID0;
91+
WellKnownFMTID.FMTID_SummaryInformation => ContainerType.SummaryInfo,
92+
WellKnownFMTID.FMTID_DocSummaryInformation => ContainerType.DocumentSummaryInfo,
93+
_ => ContainerType.AppSpecific,
94+
};
95+
FmtID0 = pStream.FMTID0;
10396

104-
this.PropertyNames = (Dictionary<uint, string>)pStream.PropertySet0.Properties
97+
PropertyNames = (Dictionary<uint, string>)pStream.PropertySet0.Properties
10598
.Where(p => p.PropertyType == PropertyType.DictionaryProperty).FirstOrDefault()?.Value;
10699

107-
this.Context = new PropertyContext()
100+
Context = new PropertyContext()
108101
{
109102
CodePage = pStream.PropertySet0.PropertyContext.CodePage
110103
};
@@ -131,7 +124,7 @@ internal OLEPropertiesContainer(CFStream cfStream)
131124
if (pStream.NumPropertySets == 2)
132125
{
133126
UserDefinedProperties = new OLEPropertiesContainer(pStream.PropertySet1.PropertyContext.CodePage, ContainerType.UserDefinedProperties);
134-
this.HasUserDefinedProperties = true;
127+
HasUserDefinedProperties = true;
135128

136129
UserDefinedProperties.ContainerType = ContainerType.UserDefinedProperties;
137130

@@ -144,11 +137,12 @@ internal OLEPropertiesContainer(CFStream cfStream)
144137
var p = (ITypedPropertyValue)pStream.PropertySet1.Properties[i];
145138
var poi = pStream.PropertySet1.PropertyIdentifierAndOffsets[i];
146139

147-
var op = new OLEProperty(UserDefinedProperties);
148-
149-
op.VTType = p.VTType;
150-
op.PropertyIdentifier = pStream.PropertySet1.PropertyIdentifierAndOffsets[i].PropertyIdentifier;
151-
op.Value = p.Value;
140+
var op = new OLEProperty(UserDefinedProperties)
141+
{
142+
VTType = p.VTType,
143+
PropertyIdentifier = pStream.PropertySet1.PropertyIdentifierAndOffsets[i].PropertyIdentifier,
144+
Value = p.Value
145+
};
152146

153147
UserDefinedProperties.properties.Add(op);
154148
}
@@ -201,9 +195,9 @@ public void RemoveProperty(uint propertyIdentifier)
201195
public OLEPropertiesContainer CreateUserDefinedProperties(int codePage)
202196
{
203197
// Only the DocumentSummaryInfo stream can contain a UserDefinedProperties
204-
if (this.ContainerType != ContainerType.DocumentSummaryInfo)
198+
if (ContainerType != ContainerType.DocumentSummaryInfo)
205199
{
206-
throw new CFInvalidOperation($"Only a DocumentSummaryInfo can contain user defined properties. Current container type is {this.ContainerType}");
200+
throw new CFInvalidOperation($"Only a DocumentSummaryInfo can contain user defined properties. Current container type is {ContainerType}");
207201
}
208202

209203
// Create the container, and add the codepage to the initial set of properties
@@ -220,7 +214,7 @@ public OLEPropertiesContainer CreateUserDefinedProperties(int codePage)
220214
};
221215

222216
UserDefinedProperties.properties.Add(op);
223-
this.HasUserDefinedProperties = true;
217+
HasUserDefinedProperties = true;
224218

225219
return UserDefinedProperties;
226220
}
@@ -233,7 +227,7 @@ public void Save(CFStream cfStream)
233227
Stream s = new StreamDecorator(cfStream);
234228
BinaryWriter bw = new BinaryWriter(s);
235229

236-
Guid fmtId0 = this.FmtID0 ?? (this.ContainerType == ContainerType.SummaryInfo ? new Guid(WellKnownFMTID.FMTID_SummaryInformation) : new Guid(WellKnownFMTID.FMTID_DocSummaryInformation));
230+
Guid fmtId0 = FmtID0 ?? (ContainerType == ContainerType.SummaryInfo ? new Guid(WellKnownFMTID.FMTID_SummaryInformation) : new Guid(WellKnownFMTID.FMTID_DocSummaryInformation));
237231

238232
PropertySetStream ps = new PropertySetStream
239233
{
@@ -252,26 +246,26 @@ public void Save(CFStream cfStream)
252246

253247
PropertySet0 = new PropertySet
254248
{
255-
NumProperties = (uint)this.Properties.Count(),
249+
NumProperties = (uint)Properties.Count(),
256250
PropertyIdentifierAndOffsets = new List<PropertyIdentifierAndOffset>(),
257-
Properties = new List<Interfaces.IProperty>(),
258-
PropertyContext = this.Context
251+
Properties = new List<IProperty>(),
252+
PropertyContext = Context
259253
}
260254
};
261255

262256
// If we're writing an AppSpecific property set and have property names, then add a dictionary property
263-
if (this.ContainerType == ContainerType.AppSpecific && this.PropertyNames != null && this.PropertyNames.Count > 0)
257+
if (ContainerType == ContainerType.AppSpecific && PropertyNames != null && PropertyNames.Count > 0)
264258
{
265-
AddDictionaryPropertyToPropertySet(this.PropertyNames, ps.PropertySet0);
259+
AddDictionaryPropertyToPropertySet(PropertyNames, ps.PropertySet0);
266260
ps.PropertySet0.NumProperties += 1;
267261
}
268262

269263
PropertyFactory factory =
270-
this.ContainerType == ContainerType.DocumentSummaryInfo ? DocumentSummaryInfoPropertyFactory.Instance : DefaultPropertyFactory.Instance;
264+
ContainerType == ContainerType.DocumentSummaryInfo ? DocumentSummaryInfoPropertyFactory.Instance : DefaultPropertyFactory.Instance;
271265

272-
foreach (var op in this.Properties)
266+
foreach (var op in Properties)
273267
{
274-
ITypedPropertyValue p = factory.NewProperty(op.VTType, this.Context.CodePage, op.PropertyIdentifier);
268+
ITypedPropertyValue p = factory.NewProperty(op.VTType, Context.CodePage, op.PropertyIdentifier);
275269
p.Value = op.Value;
276270
ps.PropertySet0.Properties.Add(p);
277271
ps.PropertySet0.PropertyIdentifierAndOffsets.Add(new PropertyIdentifierAndOffset() { PropertyIdentifier = op.PropertyIdentifier, Offset = 0 });
@@ -284,20 +278,20 @@ public void Save(CFStream cfStream)
284278
ps.PropertySet1 = new PropertySet
285279
{
286280
// Number of user defined properties, plus 1 for the name dictionary
287-
NumProperties = (uint)this.UserDefinedProperties.Properties.Count() + 1,
281+
NumProperties = (uint)UserDefinedProperties.Properties.Count() + 1,
288282
PropertyIdentifierAndOffsets = new List<PropertyIdentifierAndOffset>(),
289-
Properties = new List<Interfaces.IProperty>(),
283+
Properties = new List<IProperty>(),
290284
PropertyContext = UserDefinedProperties.Context
291285
};
292286

293287
ps.FMTID1 = new Guid(WellKnownFMTID.FMTID_UserDefinedProperties);
294288
ps.Offset1 = 0;
295289

296290
// Add the dictionary containing the property names
297-
AddDictionaryPropertyToPropertySet(this.UserDefinedProperties.PropertyNames, ps.PropertySet1);
291+
AddDictionaryPropertyToPropertySet(UserDefinedProperties.PropertyNames, ps.PropertySet1);
298292

299293
// Add the properties themselves
300-
foreach (var op in this.UserDefinedProperties.Properties)
294+
foreach (var op in UserDefinedProperties.Properties)
301295
{
302296
ITypedPropertyValue p = DefaultPropertyFactory.Instance.NewProperty(op.VTType, ps.PropertySet1.PropertyContext.CodePage, op.PropertyIdentifier);
303297
p.Value = op.Value;

sources/OpenMcdf.Extensions/OLEProperties/OLEProperty.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal OLEProperty(OLEPropertiesContainer container)
1616

1717
private string DecodePropertyIdentifier()
1818
{
19-
return PropertyIdentifier.GetDescription(this.container.ContainerType, this.container.PropertyNames);
19+
return PropertyIdentifier.GetDescription(container.ContainerType, container.PropertyNames);
2020
}
2121

2222
//public string Description { get { return description; }
@@ -42,10 +42,10 @@ public object Value
4242
return str.Trim('\0');
4343
break;
4444
default:
45-
return this.value;
45+
return value;
4646
}
4747

48-
return this.value;
48+
return value;
4949
}
5050
set
5151
{
@@ -58,12 +58,12 @@ public override bool Equals(object obj)
5858
var other = obj as OLEProperty;
5959
if (other == null) return false;
6060

61-
return other.PropertyIdentifier == this.PropertyIdentifier;
61+
return other.PropertyIdentifier == PropertyIdentifier;
6262
}
6363

6464
public override int GetHashCode()
6565
{
66-
return (int)this.PropertyIdentifier;
66+
return (int)PropertyIdentifier;
6767
}
6868
}
6969
}

0 commit comments

Comments
 (0)