Page 1 of 1

How to reuse user code

Posted: Mon Sep 24, 2018 2:42 pm
by HansSchl
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

Re: How to reuse user code

Posted: Mon Sep 24, 2018 3:42 pm
by Andymann
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();
        				}
        			}
        			 
        		}
        	}            

        }

Re: How to reuse user code

Posted: Mon Sep 24, 2018 3:45 pm
by HansSchl
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