forked from mini-software/MiniWord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 4585bcb Author: Wei <shps951002@gmail.com> Date: Thu Sep 22 10:27:30 2022 +0800 doc tranlate picture tag commit f90ba4a Author: WeiLin <shps951002@gmail.com> Date: Wed Sep 21 18:46:25 2022 +0800 [New] support object & dynamic parameter (mini-software#19 via @isdaniel ) commit e7c8492 Merge: 0ddfe00 c5a7d2f Author: Wei Lin <shps951002@gmail.com> Date: Wed Sep 21 10:07:55 2022 +0800 Merge pull request mini-software#24 from isdaniel/feature/support-object-dynamic support object & dynamic parameter commit c5a7d2f Author: danielshih <dog830228@gmail.com> Date: Tue Sep 20 19:37:14 2022 +0800 add sample code. commit 0580c65 Author: danielshih <dog830228@gmail.com> Date: Tue Sep 20 18:26:47 2022 +0800 支援 object & dynamic 參數
- Loading branch information
Showing
13 changed files
with
414 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,9 @@ | |
|
||
|
||
|
||
### 0.5.0 | ||
|
||
- [New] 支持 object & dynamic parameter (#19 via @isdaniel ) | ||
|
||
### 0.4.0 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,57 @@ | ||
namespace MiniSoftware | ||
{ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using DocumentFormat.OpenXml.Office2013.Excel; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Dynamic; | ||
using System.IO; | ||
using System.Linq.Expressions; | ||
|
||
public static partial class MiniWord | ||
public static partial class MiniWord | ||
{ | ||
public static void SaveAsByTemplate(string path, string templatePath, Dictionary<string, object> value) | ||
{ | ||
using (var stream = File.Create(path)) | ||
SaveAsByTemplate(stream, templatePath, value); | ||
} | ||
|
||
public static void SaveAsByTemplate(string path, string templatePath, object value) | ||
{ | ||
using (var stream = File.Create(path)) | ||
SaveAsByTemplate(stream, templatePath, value.ToDictionary()); | ||
} | ||
|
||
public static void SaveAsByTemplate(string path, byte[] templateBytes, Dictionary<string, object> value) | ||
{ | ||
using (var stream = File.Create(path)) | ||
SaveAsByTemplate(stream, templateBytes, value); | ||
} | ||
|
||
public static void SaveAsByTemplate(string path, byte[] templateBytes, object value) | ||
{ | ||
using (var stream = File.Create(path)) | ||
SaveAsByTemplate(stream, templateBytes, value.ToDictionary()); | ||
} | ||
|
||
public static void SaveAsByTemplate(this Stream stream, string templatePath, Dictionary<string, object> value) | ||
{ | ||
SaveAsByTemplateImpl(stream, GetBytes(templatePath), value); | ||
} | ||
|
||
public static void SaveAsByTemplate(this Stream stream, byte[] templateBytes, Dictionary<string, object> value) | ||
public static void SaveAsByTemplate(this Stream stream, string templatePath, object value) | ||
{ | ||
SaveAsByTemplateImpl(stream, GetBytes(templatePath), value.ToDictionary()); | ||
} | ||
|
||
public static void SaveAsByTemplate(this Stream stream, byte[] templateBytes, Dictionary<string, object> value) | ||
{ | ||
SaveAsByTemplateImpl(stream, templateBytes, value); | ||
} | ||
} | ||
|
||
public static void SaveAsByTemplate(this Stream stream, byte[] templateBytes, object value) | ||
{ | ||
|
||
SaveAsByTemplateImpl(stream, templateBytes, value.ToDictionary()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace MiniSoftware | ||
{ | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Dynamic; | ||
|
||
internal static class ObjectExtension | ||
{ | ||
internal static Dictionary<string, object> ToDictionary(this object value) | ||
{ | ||
if (value is ExpandoObject) | ||
{ | ||
return new Dictionary<string, object>(value as ExpandoObject); | ||
} | ||
|
||
Dictionary<string, object> reuslt = new Dictionary<string, object>(); | ||
|
||
if (value != null) | ||
{ | ||
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(value); | ||
foreach (PropertyDescriptor prop in props) | ||
{ | ||
object val = prop.GetValue(value); | ||
reuslt.Add(prop.Name, val); | ||
} | ||
} | ||
|
||
return reuslt; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.