Aspose.Words.Examples.CSharp.Mail_Merge.LINQtoXMLMailMerge.MyMailMergeDataSource.GetValue C# (CSharp) Method

GetValue() public method

Aspose.Words calls this method to get a value for every data field. This is a simple "generic" implementation of a data source that can work over Any IEnumerable collection. This implementation assumes that the merge field Name in the document matches the name of a public property on the object In the collection and uses reflection to get the value of the property.
public GetValue ( string fieldName, object &fieldValue ) : bool
fieldName string
fieldValue object
return bool
            public bool GetValue(string fieldName, out object fieldValue)
            {
                // Use reflection to get the property by name from the current object.
                object obj = mEnumerator.Current;

                Type curentRecordType = obj.GetType();
                PropertyInfo property = curentRecordType.GetProperty(fieldName);
                if (property != null)
                {
                    fieldValue = property.GetValue(obj, null);
                    return true;
                }

                // Return False to the Aspose.Words mail merge engine to indicate the field was not found.
                fieldValue = null;
                return false;
            }
            // ExEnd:MyMailMergeDataSourceGetValue