public PropertyTreeNode(PropertyInfo propertyInfo, ExpressionTreeNode parent) : base(parent) { this.PropertyInfo = propertyInfo; m_resultType = propertyInfo.PropertyType; this.DbColumnMappings = new List <DBColumnMapping>((DBColumnMapping[])propertyInfo.GetCustomAttributes(typeof(DBColumnMapping), true)); foreach (var dbColumnMapping in DbColumnMappings) { dbColumnMapping.Host = this; } }
public NonLeafPropertyNode(PropertyInfo propertyInfo, ExpressionTreeNode parent) : base(propertyInfo, parent) { this.m_exprIniter = new Lazy <Expression>(this.CreatePropertyAccessorExpression); m_noNullCheck = propertyInfo.GetCustomAttributes(typeof(NoNullCheckAttribute), true).Any() | propertyInfo.GetCustomAttributes(typeof(DBColumnPath), true).Cast <DBColumnPath>() .Any(p => p.HasOption(DBColumnPathOptions.DoNotGenerateNullCheck)); if (m_noNullCheck && s_logger.IsTraceEnabled) { s_logger.TraceFormat("No null check is enabled on {0}", this); } }
public ExpressionTreeNode(ExpressionTreeNode parent) { this.Parent = parent; if (parent == null) { Depth = 0; } else { Depth = parent.Depth + 1; } }
public LeafPropertyNode(PropertyInfo propertyInfo, ExpressionTreeNode parent, string destLabel) : base(propertyInfo, parent) { var externalMappings = TypeAccessorConfig.s_externalMappings.Where(pair => pair.Item2.DestLabel == destLabel) .Where(pair => TypeAccessorConfig.ExpressionPathEquals(pair.Item1, this.RawExpression)) .Select(pair => pair.Item2) .ToList(); foreach (var externalMapping in externalMappings) { externalMapping.Host = this; } DbColumnMappings = DbColumnMappings.Where(m => m.DestLabel == destLabel).Union(externalMappings).ToList(); //type safety check for db column mappings in order to fail early rather than insertion time foreach (var dbColumnMapping in DbColumnMappings) { if (dbColumnMapping.DefaultValue != null) { if (this.ResultType.IsValueType) { Type innerType; if (this.ResultType.IsNullableType(out innerType)) { if (innerType.IsInstanceOfType(dbColumnMapping.DefaultValue)) { //conversion here //dbColumnMapping.DefaultValue = Convert.ChangeType(dbColumnMapping.DefaultValue,this.ResultType); } else { throw new InvalidDBColumnMappingException("The default value has wrong type", dbColumnMapping, this); } } else { throw new InvalidDBColumnMappingException( "A value type should not have non-null default value. If you want one consider declare the property type as Nullable<T>." , dbColumnMapping, this); } } else if (this.ResultType == typeof(string)) { if (!(dbColumnMapping.DefaultValue is string)) { throw new InvalidDBColumnMappingException("The default value has wrong type", dbColumnMapping, this); } } else if (this.ResultType == typeof(byte[])) { if (!(dbColumnMapping.DefaultValue is byte[])) { throw new InvalidDBColumnMappingException("The default value has wrong type", dbColumnMapping, this); } } else { Debug.Fail("Should not reach here. A leaf node should not have ResultType as class type"); } } } }