[英]How can I refactor c# code stage using classes?
所以我在BP的代碼階段內有一些代碼,它可以工作。
問題在於它笨拙,長而脆弱。 我想知道如何在BP中使用一個類來將代碼重構為更簡潔和可擴展的方法,而不必編寫外部類庫然后引用它(在Windows中做起來並不那么容易我的環境)。
我知道可以使用“全局代碼”選項卡編寫方法,但是我可以在其中編寫抽象類嗎? 子類將去哪里? 接口怎么樣? 抱歉,如果這太基礎了,我以前找不到任何東西可以指導我。 感謝您的幫助或指點,謝謝。
該代碼是一個基本的決策階段,它使用數據項“ Main_Segment”的輸入,並使用局部(私有)變量“ parcel_label”和“ found”將一些靜態值輸出到BP數據項“ Parcel_Label”和“ Found”中。
找到(BP數據項)=找到(本地變量)
(BP數據項)Parcel_Label =(局部變量)parcel_label
(BP數據項)Main_Segment =(局部變量)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
好的,我明白了:因此可以編寫抽象類以及任意數量的子類和接口,但是它們都必須在初始化頁面的“全局代碼”選項卡中彼此重疊地編寫。 然后,可以從整個項目的各個代碼階段實例化這些子類中的任何一個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.