123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using FWindSoft.Tools;
- namespace Test.ReflectTest
- {
- /// <summary>
- /// WinReflectTest.xaml 的交互逻辑
- /// </summary>
- public partial class WinReflectTest : Window
- {
- public WinReflectTest()
- {
- InitializeComponent();
- Class2 c = new Class2();
- //var result = ObjectUtil.GetPropertyValue(c, "C1.Name");
- //var result2 = ObjectUtil.GetPropertyValue(c, "CList[2].Name[0]");
- var result3 = ObjectUtil.GetPropertyValue(c, "StrList[1][2]");
- //TestRegex();
- }
- public void TestRegex()
- {
- string str = "aaaaaaa.[bbbbbb][jlkoihj]";
- string pattern = @"(\[.*?\])";//匹配模式
- Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
- MatchCollection matches = regex.Matches(str);
- StringBuilder sb = new StringBuilder();//存放匹配结果
- foreach (Match match in matches)
- {
- string value = match.Value.Trim('[', ']');
- sb.AppendLine(value);
- }
- MessageBox.Show(sb.ToString());
- }
- }
- public class Class1
- {
- public string Name { get; set; }
- }
- public class Class2
- {
- public Class2()
- {
- C1=new Class1(){Name = "1"};
- CList=new List<Class1>();
- for (int i = 0; i < 10; i++)
- {
- CList.Add(new Class1(){Name = "Child"+(i).ToString()});
- }
- StrList=new List<string>();
- StrList.Add("abcdef");
- StrList.Add("123456");
- }
- public Class1 C1 { get; set; }
- public List<Class1> CList { get; set; }
- public List<string> StrList { get; set; }
- }
-
- }
|