static IDNameObjectManager() { ClassType = typeof(TEntity); // if (ClassType.IsGenericType && (ClassType.GetGenericTypeDefinition() == typeof(IDNameObject<>))) if (ClassType.GetType() == typeof(SimpleIDNameObject)) { throw new ArgumentException("You cannot make an IDNameObject from IDNameObject"); } entityParameter = Expression.Parameter(ClassType, "entity"); IDNameObjectType <TEntity> .IDProperty = GetIDProperty(); IDNameObjectType <TEntity> .NameProperty = GetNameProperty(); if ((IDNameObjectType <TEntity> .IDProperty == null) || (IDNameObjectType <TEntity> .NameProperty == null)) { throw new ArgumentException($"Failed to determine ID and/or Name property of type {ClassType.Name}"); } IDNameObjectType <TEntity> .NameDBProperty = GetNameDBProperty(IDNameObjectType <TEntity> .NameProperty); idMemberExpression = Expression.Property(entityParameter, IDNameObjectType <TEntity> .IDProperty.Name); nameMemberExpression = Expression.Property(entityParameter, IDNameObjectType <TEntity> .NameProperty.Name); nameDBMemberExpression = Expression.Property(entityParameter, IDNameObjectType <TEntity> .NameDBProperty.Name); var entityAttribute = AttributeManager <IDNameObjectAttribute> .GetClassAttribute(ClassType); IDNameObjectType <TEntity> .NameSearchType = entityAttribute?.NameSearchType ?? "Contains"; IDNameObjectType <TEntity> .DefaultPageSize = entityAttribute?.PageSize ?? 10; IDNameObjectType <TEntity> .SimpleINOType = typeof(SimpleIDNameObject); IDNameObjectType <TEntity> .IsSimplifiable = (IDNameObjectType <TEntity> .NameProperty == IDNameObjectType <TEntity> .NameDBProperty); miDefaultIDEqualsExpression = ClassManager.FindStaticGenericMethod(typeof(IDNameObjectManager <TEntity>), "DefaultIDEqualsExpression", 1, 1); miDefaultIDsInListExpression = ClassManager.FindStaticGenericMethod(typeof(IDNameObjectManager <TEntity>), "DefaultIDsInListExpression", 1, 1); /* * miOrderBy = * ClassManager.FindStaticGenericMethod(typeof(IDNameObjectManager<TEntity>), "_orderby", 1, 2); */ try { IDNameObjectType <TEntity> .NameContainsPredicateMethod = GetNameContainsPredicateMethod(); IDNameObjectType <TEntity> .NameStartsWithPredicateMethod = GetNameStartsWithPredicateMethod(); IDNameObjectType <TEntity> .IDEqualsPredicateMethod = GetIDEqualsPredicateMethod(); IDNameObjectType <TEntity> .IDsInListPredicateMethod = GetIDsInListPredicateMethod(); IDNameObjectType <TEntity> .IDsNotInListPredicateMethod = GetIDsNotInListPredicateMethod(); IDNameObjectType <TEntity> .OrderBySelectorMethod = GetOrderBySelectorMethod(); IDNameObjectType <TEntity> .OrderMethod = GetOrderMethod(); IDNameObjectType <TEntity> .IDSelectorExpression = GetPropertySelectorExpression(IDNameObjectType <TEntity> .IDProperty); IDNameObjectType <TEntity> .NameSelectorExpression = GetPropertySelectorExpression(IDNameObjectType <TEntity> .NameProperty); IDNameObjectType <TEntity> .NameDBSelectorExpression = GetPropertySelectorExpression(IDNameObjectType <TEntity> .NameDBProperty); IDNameObjectType <TEntity> .OrderBySelectorExpression = GetOrderBySelector(); IDNameObjectType <TEntity> .IDSelectorFunc = GetPropertySelectorFunc(IDNameObjectType <TEntity> .IDSelectorExpression); IDNameObjectType <TEntity> .NameSelectorFunc = GetPropertySelectorFunc(IDNameObjectType <TEntity> .NameSelectorExpression); IDNameObjectType <TEntity> .NameDBSelectorFunc = GetPropertySelectorFunc(IDNameObjectType <TEntity> .NameDBSelectorExpression); IDNameObjectType <TEntity> .OrderBySelectorFunc = GetPropertySelectorFunc(IDNameObjectType <TEntity> .OrderBySelectorExpression); IDNameObjectType <TEntity> .SimpleINOSelectorExpression = GetSimpleINOSelectorExpression(); } catch { throw new ArgumentException($"{ClassType.Name} contains method(s) with IDNameObjectMethod attribute that is (are) of wrong type."); } }