简体   繁体   中英

How can I refactor c# code stage using classes?

So I have some code inside a code-stage in BP and it works.
The problem is that it is clunky, long and fragile. I would like to know how could I maybe use a class/es in BP to refactor this code into something more concise and scalable, without having to write an external class-library and then refer to it (this is not so easy to do in my environment).
I know it is possible to write methods using the Global Code tab, but could I write an abstract class there? and where would the sub-classes go? How about interfaces? Apologies if this is too basic, I could not find anything previous to guide me on this. Any help or pointers are appreciated, thank you.

The code is a basic decision stage that uses input from data item "Main_Segment" and uses local (private) variables "parcel_label" and "found" to output some static values into BP data items "Parcel_Label" and "Found".

(BP Data Item) Found = (Local variable) found

(BP Data Item) Parcel_Label = (Local variable) parcel_label

(BP Data Item) Main_Segment = (Local variable) segdescript

string segdescript = Main_Segment;
found = false;
parcel_label = "";


    if (segdescript.Contains("Segment 001") || segdescript.Contains("Segment 101"))
            {
                found = true;       //if first condition is met, assign value of true to "found".
                if (found = true)   //as "found" is now true, the assignment below is carried out.
                {
                    parcel_label = "Parcel0000";
                }
            }
//and again...

    if (segdescript.Contains("Segment 002") || segdescript.Contains("Segment 202"))
            {
                found = true;
                if (found = true)
                {
                    parcel_label = "Parcel1111";
                }
            }
//and again another 97 times...zzz

OK I got it: so it is possible to write abstract classes and any number of child classes and interfaces, but they all have to be written on top of each other inside the Global Code tab of the initialise page. Then any of these child classes can be instantiated from individual code stages throughout the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM