This topic is locked

Write your own custom functions

6/15/2016 9:12:43 AM
IronSpeed to ASPRunner.NET transition
Pete K author

In Iron Speed, there was a special code file that contained built-in functions and formulas that could be used in your app. To add a custom function of your own, you merely added it to that file. Of course, ASPR.net comes with built-in functions as well, but the code is not designed to be extensible.
It's really handy to be able to call a custom function when you have some advanced processing you want to do on a field value, for instance. To accomplish this is ASPR.net, I created my own custom class file. It was really easy to do and now I do this for every app I develop. Here's how I did it.
It helps to have Visual Studio, but it's not necessary.Create a new class file in /source/include. Make sure to add all the includes you will need and declare the namespace. Here is my skeleton file I use as a starting point:

using System;

using System.IO;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Web;

using System.Web.Mvc;

using System.Reflection;

using runnerDotNet;
namespace runnerDotNet
{

public class PkFunctions

{

public static string TestFunction()

{

return "Hello world!";

}

}

}


Name your class whatever you like -- I call mine PKFunctions. So to call my test function, I merely insert something like:

value = PkFunctions.TestFunction();


Easy peasy!

A
AlanT 6/16/2016

Aah. Thanks.

I haven't had time to experiment yet, but this is EXACTLY the sort of thing I want to know.

Cheers,

Alan

M
Mack88DevClub member 3/6/2017

Nice <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81527&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
Saved my bacon again, Pete!

Pete K author 3/7/2017



Nice <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81544&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
Saved my bacon again, Pete!


Nice! I'm glad you found it helpful.