예제 #1
0
 public ParametredAction GetAction()
 {
     try
     {
         ParameterInfo[] info        = typeControl.GetMethod(cbMethods.Text).GetParameters();
         ArrayList       ReadyParams = new ArrayList();
         List <Control>  temp        = DopControlsInForm.Where <Control>(x => x.Name.StartsWith("tb") || x.Name.StartsWith("cb")).ToList();
         for (int i = 0; i < temp.Count; i++)
         {
             if (!info[i].ParameterType.IsEnum)
             {
                 ReadyParams.Add(Convert.ChangeType(temp[i].Text, info[i].ParameterType));
             }
             else
             {
                 ReadyParams.Add(Enum.Parse(info[i].ParameterType, temp[i].Text));
             }
         }
         ParametredAction pa = new ParametredAction(typeControl.GetMethod(cbMethods.Text), ReadyParams.ToArray(), typeControl);
         pa.Name = tbName.Text;
         return(pa);
     }
     catch
     {
         return(null);
     }
 }
예제 #2
0
        private void AddToList_Click(object sender, EventArgs e)
        {
            ParametredAction pa = ucCM.GetAction();

            if (pa == null)
            {
                return;
            }
            if (lbAddedEffect.SelectedIndex != -1 && ((ParametredAction)lbAddedEffect.SelectedItem).Name == pa.Name)
            {
                lbAddedEffect.Items[lbAddedEffect.Items.IndexOf(lbAddedEffect.SelectedItem)] = pa;
            }
            else
            {
                lbAddedEffect.Items.Add(pa);
            }
        }
예제 #3
0
 public void LoadEffect(ParametredAction pa)
 {
     cbMethods.SelectedIndex = cbMethods.Items.IndexOf(pa.link.Name);
     CbMethods_SelectedIndexChanged(null, null);
     tbName.Text = pa.Name;
     ParameterInfo[] info = pa.link.GetParameters();
     for (int i = 0; i < info.Length; i++)
     {
         MethodInfo ToString = info[i].ParameterType.GetMethod("ToString", new Type[] { });
         Control    ctrl;
         if (info[i].ParameterType.IsEnum)
         {
             ctrl = DopControlsInForm.Find(x => x.Name == "cb" + info[i].Name);
         }
         else
         {
             ctrl = DopControlsInForm.Find(x => x.Name == "tb" + info[i].Name);
         }
         if (ctrl != null)
         {
             ctrl.Text = (string)ToString.Invoke(pa.Params[i], null);
         }
     }
 }
예제 #4
0
파일: BaseCard.cs 프로젝트: Elmion/EVDTest
        private CardBase()
        {
            ImageBase = new ImageFile();
            Cards     = new List <Card>();

            if (!File.Exists(ConfigurationManager.AppSettings["XMLCardBasePath"]))
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(ConfigurationManager.AppSettings["XMLCardBasePath"]);
            foreach (XmlNode XMLCardDescription in doc.GetElementsByTagName("Card"))
            {
                Card card = new Card();

                card.Header      = XMLCardDescription.SelectSingleNode("Header").InnerText;
                card.Description = XMLCardDescription.SelectSingleNode("Description").InnerText;
                card.uid         = Guid.Parse(XMLCardDescription.SelectSingleNode("uid").InnerText);

                card.ImageRef = Guid.Parse(XMLCardDescription.SelectSingleNode("Image").InnerText);

                //Заполняем эффекты
                card.effects = new List <ParametredAction>();
                foreach (XmlNode EffectXML in XMLCardDescription.SelectSingleNode("Effects").ChildNodes)
                {
                    XmlNode       EffectParamsNode = EffectXML.SelectSingleNode("Parameters");
                    List <object> Params           = new List <object>();
                    for (int i = 0; i < EffectParamsNode.ChildNodes.Count; i++)
                    {
                        Params.Add(EffectParamsNode.ChildNodes[i].InnerText);
                    }
                    string EffectName = EffectXML.SelectSingleNode("Name").InnerText;
                    string MethodName = EffectXML.SelectSingleNode("MethodName").InnerText;

                    ParameterInfo[] info        = typeof(Effect).GetMethod(MethodName).GetParameters();
                    ArrayList       ReadyParams = new ArrayList();
                    for (int j = 0; j < info.Length; j++)
                    {
                        if (!info[j].ParameterType.IsEnum)
                        {
                            ReadyParams.Add(Convert.ChangeType(Params[j], info[j].ParameterType));
                        }
                        else
                        {
                            ReadyParams.Add(Enum.Parse(info[j].ParameterType, (string)Params[j]));
                        }
                    }

                    ParametredAction pa = new ParametredAction(typeof(Effect).GetMethod(MethodName), ReadyParams.ToArray(), typeof(Effect));
                    pa.Name = EffectName;
                    card.effects.Add(pa);
                }

                //Заполняем доступы
                card.accesses = new List <ParametredAction>();
                foreach (XmlNode AccessXML in XMLCardDescription.SelectSingleNode("Accesses").ChildNodes)
                {
                    XmlNode       AccessParamsNode = AccessXML.SelectSingleNode("Parameters");
                    List <object> Params           = new List <object>();
                    for (int i = 0; i < AccessParamsNode.ChildNodes.Count; i++)
                    {
                        Params.Add(AccessParamsNode.ChildNodes[i].InnerText);
                    }
                    string AccessName = AccessXML.SelectSingleNode("Name").InnerText;
                    string MethodName = AccessXML.SelectSingleNode("MethodName").InnerText;

                    ParameterInfo[] info        = typeof(Access).GetMethod(MethodName).GetParameters();
                    ArrayList       ReadyParams = new ArrayList();
                    for (int j = 0; j < info.Length; j++)
                    {
                        if (!info[j].ParameterType.IsEnum)
                        {
                            ReadyParams.Add(Convert.ChangeType(Params[j], info[j].ParameterType));
                        }
                        else
                        {
                            ReadyParams.Add(Enum.Parse(info[j].ParameterType, (string)Params[j]));
                        }
                    }
                    ParametredAction pa = new ParametredAction(typeof(Access).GetMethod(MethodName), ReadyParams.ToArray(), typeof(Access));
                    pa.Name = AccessName;
                    card.accesses.Add(pa);
                }
                Cards.Add(card);
            }
        }