我已經爲抽象類型覆蓋了PromptDialog.PromptChoice。我有兩個不同的孩子,我想分享相同的邏輯,但我需要保證某些變量可用於部分TryParse邏輯。對於其中一個孩子,我在這裏沒有任何問題。但是,對於另一個孩子,我正在遇到非常奇怪的行爲。當我從我的對話框CustomPromptChoice.Choice(context,function,options)中調用時,我看到選項是我所期望的。用戶會看到正確的選項列表,但在選擇一個選項後,在TryParse邏輯中,我看到所有選項都已更改。顯然,我的TryParse總是會失敗。有沒有人見過這種行爲?PromptChoice在接收到用戶輸入後更改選項
這是基礎類:
[Serializable]
public abstract class ExtractionClass
{
public List<ExtractionClass> children;
public ExtractionClass parent;
public string name;
public string value;
public override string ToString()
{
return name;
}
public ExtractionClass() { }
public ExtractionClass(string name, string value, ExtractionClass parent)
{
this.name = name;
this.value = value;
this.parent = parent;
}
//upon initialization, guarantee that children is filled correctly
public abstract void SetChildren();
//use to check if child is a where match
public abstract bool IsWhereMatch(ExtractionClass child, string query="");
//use to check if child is a when match
public abstract bool IsWhenMatch(ExtractionClass child, string query="");
//use to check if child is a who match
public abstract bool IsWhoMatch(ExtractionClass child, string query="");
//use to check if child is a what match
public abstract bool IsWhatMatch(ExtractionClass child, string query="");
}
這裏是子類的精簡版本,不工作:
[Serializable]
public class ChildClass1:ExtractionClass
{
public Dictionary<ChildClass1, int> childrenLookup;
public Dictionary<string, ChildClass1> childrenNames;
private dynamic content;
public string spokenName;
static HashSet<string> childrenToKeep = new HashSet<string>()
static List<string> ignoreNames = new List<string>();
public static Dictionary<string, List<string>> nodeNameSynonyms = new Dictionary<string, List<string>>();
public static HashSet<string> WhoNodes = new HashSet<string>();
public ChildClass1(dynamic content)
{
this.children = new List<ExtractionClass>();
this.childrenLookup = new Dictionary<ChildClass1, int>();
this.childrenNames = new Dictionary<string, ChildClass1>();
this.parent = null;
this.name = String.Empty;
this.value = String.Empty;
this.spokenName = String.Empty;
this.content = content;
}
public ChildClass1(string name, string value, List<string> synonyms) : this(null)
{
this.name = name;
this.spokenName = name;
double doubleValue;
int integerValue;
bool isInt = Int32.TryParse(value, out integerValue);
if (isInt)
{
this.value = string.Format("{0}", integerValue);
}
else {
bool isDouble = Double.TryParse(value, out doubleValue);
if (isDouble)
{
this.value = string.Format("{0:N2}", doubleValue);
}
else
{
this.value = value;
}
}
}
public override string ToString()
{
return this.name;
}
public override void SetChildren()
{
//pretty long and complicated
}
public override bool IsWhereMatch(ExtractionClass child, string query = "")
{
return false;
}
public override bool IsWhenMatch(ExtractionClass child, string query = "")
{
return false;
}
public override bool IsWhoMatch(ExtractionClass child, string query = "")
{
return false;
}
public override bool IsWhatMatch(ExtractionClass child, string query = "")
{
return false;
}
}
最後,這裏是一個精簡版可以工作的班級:
public class ChildClass2: ExtractionClass
{
public Address address;
public Rating rating;
public string description, telephone, spokenName;
public ChildClass2(string name, string value, ExtractionClass parent) : base(name, value, parent) { children = new List<ExtractionClass>(); }
public override string ToString()
{
return name;
}
public override void SetChildren()
{
//a bit of a mess but works as expected
}
}
但是,對我來說沒有任何意義的是,我在Dialo中撥打了這個電話g:
ExtractionPromptChoice.Choice(context, this.CarouselEntityHandler, nodeOptions);
然後當我通過堆棧時,我看到它返回給用戶正確的選項。我的控件的最後一個實例中的nodeOptions設置正確,但是當我轉到ExtractionPromptChoice TryParse邏輯時,選項是不同的。 nodeOptions最終保存了ChildClass1類型的列表,但是爲ExtractionClass定義了提示選項。
編輯:事實證明,有關我的代碼的東西導致遠程服務器在我的MessagesController代碼中返回400錯誤的請求錯誤。
沒有兩個孩子是一樣的。當一個行爲問題出現時,最好擁有所有的事實,否則可能會引起偏袒,這當然會讓另一個兄弟姐妹感到不安,然後他們會打架,尖叫,阻止和約會對方,導致更多的高中情侶打架...你能粘貼一些代碼,這樣我們可以幫你嗎? –
哈哈好點。我沒有粘貼任何代碼,因爲我甚至無法開始弄清楚在哪裏尋找。我將添加子代碼 – jon