Forums: Write your own custom functions - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Write your own custom functions

#1 User is offline   Pete K 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 231
  • Joined: 05-February 16

Posted 15 June 2016 - 01:12 PM

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!


----------------------------------------------------------
Pete K.
Web Developer
Fayette County Public Schools | Lexington, Kentucky, USA
0

#2 User is offline   Alan Telford 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 08-March 16

Posted 16 June 2016 - 10:45 PM

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

#3 User is offline   ChrisN 

  • Member
  • PipPip
  • Group: Members
  • Posts: 26
  • Joined: 01-November 14

Posted 06 March 2017 - 09:49 PM

Nice :)

Saved my bacon again, Pete!
0

#4 User is offline   Pete K 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 231
  • Joined: 05-February 16

Posted 07 March 2017 - 06:48 PM

View PostChrisN, on 06 March 2017 - 04:49 PM, said:

Nice :)

Saved my bacon again, Pete!


Nice! I'm glad you found it helpful.





----------------------------------------------------------
Pete K.
Web Developer
Fayette County Public Schools | Lexington, Kentucky, USA
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users