Skip to content

Commit cb58df3

Browse files
committed
bug fixes
1 parent 3be73e9 commit cb58df3

4 files changed

Lines changed: 30 additions & 11 deletions

File tree

src/WebExpress.WebIndex.Wi/Model/ViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ public bool DropIndexFile()
148148
var runtimeClass = CurrentObjectType.BuildRuntimeClass();
149149
var document = IndexManager.GetIndexDocument(runtimeClass);
150150
var fieldProperty = runtimeClass.GetProperty(CurrentIndexField?.Name);
151+
var fieldData = new IndexFieldData(fieldProperty);
151152
var methodInfo = document.GetType().GetMethod("GetReverseIndex");
152-
var reverseIndex = methodInfo.Invoke(document, [fieldProperty]);
153+
var reverseIndex = methodInfo.Invoke(document, [fieldData]);
153154
var termProperty = reverseIndex.GetType().GetProperty("Term");
154155
var term = termProperty.GetValue(reverseIndex) as IndexStorageSegmentTerm;
155156

src/WebExpress.WebIndex.WiUI/Model/MainViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ public ObservableCollection<Term> GetIndexTerms()
263263
var runtimeClass = _selectedObjectType?.BuildRuntimeClass();
264264
var document = IndexManager?.GetIndexDocument(runtimeClass!);
265265
var fieldProperty = runtimeClass?.GetProperty(_selectedIndexField?.Name!);
266+
var fieldData = new IndexFieldData(fieldProperty);
266267
var methodInfo = document?.GetType().GetMethod("GetReverseIndex");
267-
var reverseIndex = methodInfo?.Invoke(document, [fieldProperty]);
268+
var reverseIndex = methodInfo?.Invoke(document, [fieldData]);
268269
var termProperty = reverseIndex?.GetType().GetProperty("Term");
269270
var term = termProperty?.GetValue(reverseIndex) as IndexStorageSegmentTerm;
270271

src/WebExpress.WebIndex/IndexFieldData.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ public class IndexFieldData
3535
/// </value>
3636
public bool Enabled => PropertyInfo.GetCustomAttribute<IndexIgnoreAttribute>() == null;
3737

38+
/// <summary>
39+
/// Initializes a new instance of the <see cref="IndexFieldData"/> class.
40+
/// </summary>
41+
public IndexFieldData()
42+
{
43+
}
44+
45+
/// <summary>
46+
/// Initializes a new instance of the <see cref="IndexFieldData"/> class with the specified property.
47+
/// </summary>
48+
/// <param name="property">The property information to initialize the index field
49+
public IndexFieldData(PropertyInfo property)
50+
{
51+
Name = property?.Name;
52+
Type = property?.PropertyType;
53+
PropertyInfo = property;
54+
}
55+
3856
/// <summary>
3957
/// Retrieves the value of a property from an object based on the specified field.
4058
/// </summary>

src/WebExpress.WebIndex/Storage/IndexStorageSchema.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class IndexStorageSchema<TIndexItem> : IIndexSchema<TIndexItem>
1616
{
1717
private readonly string _extentions = "ws";
1818
private readonly int _version = 1;
19+
private static readonly JsonSerializerOptions _jsonSerializerOptions = new() { WriteIndented = true };
20+
private static readonly JsonSerializerOptions _jsonDeserializerOptions = new() { PropertyNameCaseInsensitive = true };
1921

2022
/// <summary>
2123
/// Returns the file name.
@@ -61,9 +63,8 @@ public bool HasSchemaChanged()
6163
var currentSchema = GetSchema();
6264
var storedSchema = Read();
6365

64-
var options = new JsonSerializerOptions { WriteIndented = true };
65-
var currentJson = JsonSerializer.Serialize(currentSchema, options);
66-
var storedJson = JsonSerializer.Serialize(storedSchema, options);
66+
var currentJson = JsonSerializer.Serialize(currentSchema, _jsonSerializerOptions);
67+
var storedJson = JsonSerializer.Serialize(storedSchema, _jsonSerializerOptions);
6768

6869
return !currentJson.Equals(storedJson);
6970
}
@@ -133,23 +134,21 @@ private object GetType(PropertyInfo property)
133134
private void Write()
134135
{
135136
var schema = GetSchema();
136-
var options = new JsonSerializerOptions { WriteIndented = true };
137-
var json = JsonSerializer.Serialize(schema, options);
137+
var json = JsonSerializer.Serialize(schema, _jsonSerializerOptions);
138138

139139
File.WriteAllText(FileName, json);
140140
}
141141

142142
/// <summary>
143143
/// Reads the object schema from the storage medium.
144144
/// </summary>
145-
/// /// <returns>
145+
/// <returns>
146146
/// The deserialized schema as an dynamic object.
147147
/// </returns>
148148
private dynamic Read()
149149
{
150150
var json = File.ReadAllText(FileName);
151-
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
152-
var schema = JsonSerializer.Deserialize<dynamic>(json, options);
151+
var schema = JsonSerializer.Deserialize<dynamic>(json, _jsonDeserializerOptions);
153152

154153
return schema;
155154
}
@@ -169,7 +168,7 @@ public void Drop()
169168
/// </summary>
170169
public virtual void Dispose()
171170
{
172-
171+
GC.SuppressFinalize(this);
173172
}
174173
}
175174
}

0 commit comments

Comments
 (0)