Skip to content

Commit

Permalink
remove:移除重复方法Obj2Dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
wangx036 committed Sep 23, 2024
1 parent f4c2ea7 commit 5b6be1c
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions src/MiniWord/MiniWord.Implment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ private static void ReplaceForeachStatements(OpenXmlElement xmlElement,Wordproce
for (var i = 0; i < list.Count; i++)
{
var item = list[i];
var foreachDataDict = item.Obj2Dictionary();
var foreachDataDict = item.ToDictionary();
// 2. 渲染替换属性值{{}},插入循环元素,再替换……
// 2.1 替换属性值
if (i == 0)
Expand Down Expand Up @@ -709,34 +709,7 @@ private static void ReplaceForeachStatements(OpenXmlElement xmlElement,Wordproce


}

/// <summary>
/// 将实体对象转为字典格式
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
private static Dictionary<string, object> Obj2Dictionary(this object obj)
{
var result = new Dictionary<string, object>();
if(obj == null) return null;
if (obj is IDictionary d)
{
foreach (object key in d.Keys)
{
result.Add(key.ToString(), d[key]);
}
}
else
{
var props = obj.GetType().GetProperties();
foreach (var p in props)
{
result.Add(p.Name,p.GetValue(obj));
}
}
return result;
}


/// <summary>
/// 获取关键词之间的元素
/// </summary>
Expand Down

0 comments on commit 5b6be1c

Please sign in to comment.