/// <summary> /// 判断给定 property 是否存在 AbstractPropertyComponentAttribute标注且标注中 componentSchema为 给定schema 的 标注, /// 如果存在此标注,还判断权限是否包含给定标注的权限,如果包含,则返回此标注; /// 如果存在多个符合的标注,则返回匹配 componentSchema为 给定schema 的所有标注; /// 否则,返回 null; /// </summary> static IEnumerable <PropertyAndVuecompontAttribute> getPropertyWithAttributeFunc(PropertyInfo prop, EnumComponentSchema schema, Func <ILimitAttribute, bool> filterPropertyAndComponentFunc) { if (filterPropertyAndComponentFunc == null) { filterPropertyAndComponentFunc = (c) => true; } Func <AbstractPropertyComponentAttribute, bool> filterFunc = (c) => (c.componentSchema == EnumComponentSchema.FilterAndEditAndList || c.componentSchema == schema || ((c.componentSchema & schema) > 0)) && filterPropertyAndComponentFunc(c); var propAttributes = prop.GetCustomAttributes <AbstractPropertyComponentAttribute>(true).ToList(); // // 获取到的标注中,如果子类和父类对同一个属性同时定义有标注,子类定义的标注在前,父类定义的标注在后; //麻烦的是 如果获取 父类中定义的 标注,则可能获取到多个标注; (例如, Name 同时在 OA_Role 和 父类: IdAndNameAndCreateDatetimeEntity 中定义了标注) //如果不获取父类中定义的标注,则某一个属性在子类中未定义标注时,标注就无法获取到;( OA_User 无法获取到 父类父类: IdAndNameAndCreateDatetimeEntity 中定义的标注) //另外,可能对于同一个属性会定有多个标注; var result = propAttributes.Where(filterFunc) .OrderBy(c => c.componentSchema == schema ? 0 : 1) .Select(attr => new PropertyAndVuecompontAttribute(prop, attr)).ToList(); IListExtension.ReverseForEach(result, (item, index) => { //移走相同属性的, var sameItemIndex = result.FindIndex((xitem) => item.VueComponentAttribute.propertyPath == xitem.VueComponentAttribute.propertyPath); if (sameItemIndex < index) { propAttributes.RemoveAt(index); } }); return(result); }
/// <summary> ///A test for Shuffle ///</summary> public void ShuffleTest1Helper <T>() { IList <T> list = null; // TODO: Initialize to an appropriate value Random rnd = null; // TODO: Initialize to an appropriate value IListExtension.Shuffle <T>(list, rnd); }
/// <summary> ///A test for RemoveAllNulls ///</summary> public void RemoveAllNullsTestHelper <T>() where T : class { IList <T> list = null; // TODO: Initialize to an appropriate value IListExtension.RemoveAllNulls <T>(list); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> ///A test for GenerateBindingSourced ///</summary> public void GenerateBindingSourcedTestHelper <T>() { IList <T> list = null; // TODO: Initialize to an appropriate value bool readOnly = false; // TODO: Initialize to an appropriate value BindingSource expected = null; // TODO: Initialize to an appropriate value BindingSource actual; actual = IListExtension.GenerateBindingSourced <T>(list, readOnly); Assert.AreEqual(expected, actual); }
/// <summary> /// 根据整数数字获取枚举类型的值; /// </summary> /// <param name="enumType"></param> /// <param name="val"></param> /// <returns></returns> public static object GetValue(Type enumType, string val) { int ot; if (Int32.TryParse(val, out ot)) { return(GetValue(enumType, ot)); } var values = Enum.GetValues(enumType); return(IListExtension.Find(values, value => value.ToString() == val)); }
/// <summary> ///A test for IndexOf ///</summary> public void IndexOfTestHelper <TYPE>(TYPE[] data, TYPE what, int pos) { int p = IListExtension.IndexOf <TYPE>(data, T => T.Equals(what)); Assert.AreEqual(p, pos); }