/// <summary> /// 构造方法 /// </summary> /// <param name="property">属性的信息</param> /// <param name="propertyDefine">属性的定义</param> public Column(PropertyInfo property, PropertyDefine propertyDefine) { Property = property; PropertyDefine = propertyDefine; if (DataType.FullName != DataTypeNames.String && propertyDefine.Length > 0) { throw new SpiderException("Only string property can set length."); } DefaultValue = Property.PropertyType.IsValueType ? Activator.CreateInstance(Property.PropertyType) : null; Option = propertyDefine.Option; SelectorAttribute = new SelectorAttribute { Expression = propertyDefine.Expression, Type = propertyDefine.Type, Arguments = propertyDefine.Arguments }; NotNull = propertyDefine.NotNull; IgnoreStore = propertyDefine.IgnoreStore; Length = propertyDefine.Length; foreach (var formatter in property.GetCustomAttributes <Formatter.Formatter>(true)) { Formatters.Add(formatter); } }
/// <summary> /// 构造方法 /// </summary> public EntityDefine() { Type = typeof(T); var typeName = Type.FullName; Name = typeName; TableInfo = Type.GetCustomAttribute <EntityTable>(); if (TableInfo != null) { if (TableInfo.Indexs != null) { TableInfo.Indexs = new HashSet <string>(TableInfo.Indexs.Select(i => i.Replace(" ", ""))).ToArray(); } if (TableInfo.Uniques != null) { TableInfo.Uniques = new HashSet <string>(TableInfo.Uniques.Select(i => i.Replace(" ", ""))).ToArray(); } } EntitySelector entitySelector = Type.GetCustomAttribute <EntitySelector>(); if (entitySelector != null) { Multi = true; Take = entitySelector.Take; TakeFromHead = entitySelector.TakeFromHead; SelectorAttribute = new SelectorAttribute { Expression = entitySelector.Expression, Type = entitySelector.Type }; } else { Multi = false; } var targetUrlsSelectors = Type.GetCustomAttributes <TargetUrlsSelector>(); TargetUrlsSelectors = targetUrlsSelectors.ToList(); var sharedValueSelectorAttributes = Type.GetCustomAttributes <SharedValueSelector>(); SharedValues = sharedValueSelectorAttributes.Select(e => new SharedValueSelector { Name = e.Name, Expression = e.Expression, Type = e.Type }).ToList(); GenerateEntityColumns(); ValidateEntityDefine(); }