-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes.txt
92 lines (76 loc) · 2.29 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#Discovery Notes during coding process.
var lines = fields.Select(kvp => kvp.Key); //Grab PDF Fields from document
foreach (var l in lines) //Iterate through the fields to build the set value map
{
Console.WriteLine($"fields[\"{l}\"].SetValue();");
}
Console.WriteLine(string.Join(Environment.NewLine, lines)); //Print them out */
//Prints out just the heads on CSV file using the ETL
using (var p = new ChoCSVReader(@"C:\DEV\pdffillerdncore\data.csv").WithFirstLineHeader())
{
p.Read();
Console.WriteLine(String.Join(", ", p.Context.Headers));
}
/* New Stuff */
public void FillForm<T>(T rec, string templatePdfFile)
{
// var fields =
var fields = GetFormFieldsForTempalte(templatePdfFile);
var properties = typeof(T).GetProperties().Where(x => x.GetCustomAttributes(typeof(PdfFieldAttribute)).Any());
foreach (var prop in properties)
{
var attr = prop.GetCustomAttribute<PdfFieldAttribute>();
if (!fields.TryGetValue(attr.FieldName, out var pdfField))
continue;
pdfField.SetValue(prop.GetValue(rec)?.ToString());
}
}
public Dictionary<string, FieldStub> GetFormFieldsForTempalte(string templatePdfFile)
{
return new Dictionary<string, FieldStub>
{
{"some_field_name", new FieldStub{Name="the field i want to set"}}
};
}
//Other Code
var fields = new Dictionary<string, FieldStub>
{
{"some_field_name", new FieldStub{Name="the field i want to set"}}
};
var rec = new RecordStub { Foo = "some value i want to set"};
FillForm(rec);
}
public void FillForm(RecordStub rec)
{
var fields = new Dictionary<string, FieldStub>
{
{"some_field_name", new FieldStub{Name="the field i want to set"}}
};
var properties = typeof(RecordStub).GetProperties().Where(x => x.GetCustomAttributes(typeof(PdfFieldAttribute)).Any());
foreach (var prop in properties)
{
var attr = prop.GetCustomAttribute<PdfFieldAttribute>();
if (!fields.TryGetValue(attr.FieldName, out var pdfField))
continue;
pdfField.SetValue(prop.GetValue(rec)?.ToString());
}
}
public class FieldStub
{
public string Name{get;set;}
public void SetValue(string value){
$"setting [{Name}] with value [{value}]".Dump();
}
}
public class RecordStub
{
[PdfFieldAttribute("some_field_name")]
public string Foo{get;set;}
}
public class PdfFieldAttribute : Attribute
{
public string FieldName{ get; }
public PdfFieldAttribute(string fieldName){
FieldName = fieldName;
}
}