Free Support Forum - aspose.com

Linq Report call methods

Hello,

is it possible to call instance method inside a linq report template with parameters. it would be very powerfull and lead to very customizable templates.

@miniseb31

Thanks for your inquiry. Could you please share some more detail about your query along with sample template document and expected output document? We will then provide you with more information about your query.

In my datasource i have an object of ClassA. in the classA i have a method with parameters and i want to call it in the template.
the method looks like : double d = myObject.CalculateSomething(10, 20);
In my context, i have algorythms with some parameters that returns a double value, and i want to decide in my template which algorythm with right parameters.

@miniseb31

Thanks for sharing the detail. Yes, you can achieve your requirement using LINQ Reporting engine. Please refer to the following article.
Setting up Known External Types

Following code example shows how to use the external know types.
input.zip (8.8 KB)

public static class Util
{
    public static string[] GetArray(params string[] items)
    {
        // Simply return the input array. This is needed, because array type identifiers 
        // are not supported in template syntax.
        return items;
    }
}

Document doc = new Document(@"input.docx");

ReportingEngine engine = new ReportingEngine();
engine.KnownTypes.Add(typeof(Util));

engine.BuildReport(doc, new object());
doc.Save(@"Out.docx");

hello, i can not download the zip file,
“Sorry, this file is private. Only visible to topic owner and staff members.”

@miniseb31

Thanks for your inquiry. Please make sure that you have logged in to Aspose site. The template syntax of input.docx is shown below.

<<var [array = Util.GetArray(“a”, “b”, “c”)]>>
<<foreach [s in array]>>Type: <<[s.GetType()]>>, value: <<[s]>>
<</foreach>>