This is a migrated thread and some comments may be shown as answers.

Use template document with fieldnames embedded.

2 Answers 28 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Guy
Top achievements
Rank 1
Guy asked on 15 May 2011, 05:13 AM
I'd like to embed fieldnames in a template document to be parsed in at runtime for said fieldnames.  The result would be a document with all the fieldnames replaced by the corresponding data for the currently selected records.

Ie., for HTML there would be something like 

...<td>$Customer.Name$</td>...

in the template document.

Using Regex, I'll pull out "Customer.Name".  I've looked at Customer.FieldValue<string>("Name"); but I think Customer.Select("c => c.Name") will let me use dynamic binding to avoid trying to find the type of the field and simply .ToString() on the var.

Is there any way to use the "Customer" portion of the string to select the correct object/table to use?  I'd rather not have to put if clauses into the post parser:

if (tname == "Customer")
var fvalue = Customer.Select("c => c."+fname);

perhaps something like

var fvalue = dbModel.GetTable(tname).Select("c => c."+fname);


2 Answers, 1 is accepted

Sort by
0
Guy
Top achievements
Rank 1
answered on 15 May 2011, 09:34 AM
Since ORM creates an object that I used as a private member of the form (with data from the current record of the table), reflection provides values:

string ReplaceValues(string inbuf)
{
    return _fieldPattern.Replace(inbuf, delegate(Match m)
    {
        FieldInfo fi = this.GetType().GetField(m.Groups[1].Value, BindingFlags.Instance | BindingFlags.NonPublic);
        object record = fi.GetValue(this);
        PropertyInfo pi = record.GetType().GetProperty(m.Groups[2].Value, BindingFlags.Instance | BindingFlags.Public);
        object val = pi.GetValue(record, null);
        return val==null?"":val.ToString();
    });
}
0
PetarP
Telerik team
answered on 19 May 2011, 04:19 PM
Hello Guy,

 I was not really able to understand your problem. Can you please share with us what are you trying to achieve exactly and at what point of time do you expect this embedding to happen?

Greetings,
Petar
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
Tags
General Discussions
Asked by
Guy
Top achievements
Rank 1
Answers by
Guy
Top achievements
Rank 1
PetarP
Telerik team
Share this question
or