How to reuse user code

Ranorex Studio, Spy, Recorder, and Driver.
HansSchl
Posts: 141
Joined: Wed Sep 19, 2018 10:05 am

How to reuse user code

Post by HansSchl » Mon Sep 24, 2018 2:42 pm

Hi,
I created a user code collection the other day, and now I want to reuse this collection in a new Ranorex project. How do I achieve this? I added the *.cs file to the new solution where it appears under "Solution items" but I cannot select the function from the collection when I want to add a "user code" action.

Thanks
Hans

User avatar
Andymann
Posts: 50
Joined: Wed Jul 27, 2016 12:22 pm
Location: Hamburg
Contact:

Re: How to reuse user code

Post by Andymann » Mon Sep 24, 2018 3:42 pm

did you add "[UserCodeMethod]" (yeah ... without the quotation marks) to every method?
Like this:

Code: Select all

 /// <summary>
        /// 
        /// <para/>Beendet alle Prozesse, die mit 'pProcessName' beginnen
        /// <para/>
        /// <para/>03.08.2018	A.Fischer	
        /// </summary>
        /// 
        /// <param name="processname">Name of the process to kill</param>
        [UserCodeMethod]
        public static void KillProcessStartingWith(string pProcessName){
        	String sExeName;
        	Process[] tmpProc;
        	
        	Process[] processes = Process.GetProcesses();
        	if((processes!=null) && (processes.Length>0)){
        		for(int i=0; i<processes.Length; i++){
        			if(processes[i].ProcessName.StartsWith(pProcessName)){
        				sExeName = processes[i].ProcessName;
        				tmpProc = Process.GetProcessesByName( sExeName );
        				for(int j=0; j<tmpProc.Length; j++){
        					tmpProc[j].Kill();
        				}
        			}
        			 
        		}
        	}            

        }
Vorsprung durch Wahnsinn
www.Doktor-Andy.de

HansSchl
Posts: 141
Joined: Wed Sep 19, 2018 10:05 am

Re: How to reuse user code

Post by HansSchl » Mon Sep 24, 2018 3:45 pm

Yes I did... In the meantime, I somehow managed to pull the cs file into the test case (not into the solution... that may have been my error) and use it :D