2017-08-31 63 views
0

我已经为抽象类型覆盖了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错误的请求错误。

+1

没有两个孩子是一样的。当一个行为问题出现时,最好拥有所有的事实,否则可能会引起偏袒,这当然会让另一个兄弟姐妹感到不安,然后他们会打架,尖叫,阻止和约会对方,导致更多的高中情侣打架...你能粘贴一些代码,这样我们可以帮你吗? –

+0

哈哈好点。我没有粘贴任何代码,因为我甚至无法开始弄清楚在哪里寻找。我将添加子代码 – jon

回答

0

原来我的代码中有其他地方的错误逻辑,它们捕获错误而不传播它们。我得到一个400错误的请求响应,因为在ChildClass1中我有一个动态的,这打破了序列化。这个错误不会引发任何地方,我不确定为什么我看到错误的PromptOption选项,但我不认为当我捕获并且不重新抛出错误时,行为是非常明确的。