public QueryModelDescription(System.Type aModel, QueryModelAttribute aDescription) { if (aModel == null) { throw new NullReferenceException("QueryModelDescription: Model type can't be null"); } if (aDescription == null) { throw new NullReferenceException("QueryModelDescription: Attribute must be specified"); } foreach (ConstructorInfo info in aModel.GetConstructors()) { if (info.GetParameters().Length == 1) { if (TypeValidator.IsCompatible(info.GetParameters()[0].ParameterType, typeof(MappingsImplementor)) == true) { constructor = info; break; } } } if (constructor == null) { throw new NotImplementedException("QueryModelDescription: QueryImplementor needs public .ctor (MappingsImplementor)"); } model = aModel; definition = aDescription; }
/// <summary> /// Checks if specified type is query model, then checks if model is already registered. /// Next checks for duplicate type handler and if everything is successful registers it /// </summary> /// <param name="aType"> /// Type which is checked <see cref="System.Type"/> /// </param> /// <returns> /// true if it is model handler, false if not <see cref="System.Boolean"/> /// </returns> /// <remarks> /// If registered model for specified type already exists, then it throws /// ExceptionDuplicateQueryModelTypeHandler exception /// </remarks> public static bool IsQueryModel(System.Type aType) { if (aType == null) { return(false); } QueryModelAttribute[] attrs = (QueryModelAttribute[])aType.GetCustomAttributes(typeof(QueryModelAttribute), false); if ((attrs == null) || (attrs.Length == 0)) { return(false); } QueryModelAttribute attr = attrs[0]; // Check if model is already registered if (models != null) { foreach (QueryModelDescription desc in models) { if (desc != null) { if (desc.Model == aType) { return(true); } } } // Check if duplicate handler exists foreach (QueryModelDescription desc in models) { if (desc != null) { if (desc.Definition.ListType == attr.ListType) { throw new ExceptionDuplicateQueryModelTypeHandler(aType, attr.ListType); } } } } models.Add(new QueryModelDescription(aType, attr)); return(true); }