/// <summary> /// Carrega as configurações do tipo. /// </summary> /// <param name="culture"></param> private void LoadTypeSettings(System.Globalization.CultureInfo culture) { var entityTypeName = Colosoft.Reflection.TypeName.Get(_entity.GetType()); if (_entitySettings == null) { _entitySettings = _validationManager.LoadSettings(entityTypeName); } string startString = EntityTypeStartString; var allIdentifiers = GetIdentifierSpecialize(entityTypeName, startString, startString, String.Empty); foreach (string identifier in allIdentifiers.Keys) { IPropertySettingsInfo currentPropertSettings = _entitySettings.Where(f => f.Identifier == identifier).FirstOrDefault(); if (currentPropertSettings != null) { IStatebleItem stateble = CreatePropertyStateByIdentifier(allIdentifiers[identifier], identifier, culture); if (stateble != null) { stateble.IsConfigured = true; _propertyAttributes.Add(identifier, stateble); } } else { string[] propertyPath = allIdentifiers[identifier].Split('.'); var currentObjectTypeName = Colosoft.Reflection.TypeName.Get(this.GetType()); bool findPath = true; IEntityPropertyInfo info = null; for (int index = 0; index < propertyPath.Length - 1; index++) { string currentProperty = propertyPath[index]; info = _validationManager.LoadTypeProperty(currentObjectTypeName, currentProperty); if (info == null) { findPath = false; break; } else { currentObjectTypeName = info.PropertyType; } } if ((findPath) && (info != null) && (info.IsInstance)) { IPropertySettingsInfo propertyInfo = _validationManager.LoadSettings(currentObjectTypeName).Where(f => f.Identifier.EndsWith(propertyPath[propertyPath.Length - 1])).FirstOrDefault(); if (propertyInfo != null) { var propertyStateble = CreatePropertyState(allIdentifiers[identifier], propertyInfo, identifier, culture); propertyStateble.IsConfigured = true; _propertyAttributes.Add(identifier, propertyStateble); } else { var propertyState = CreatePropertyState(allIdentifiers[identifier], identifier, culture); _propertyAttributes.Add(identifier, propertyState); } } else { var propertyState = CreatePropertyState(allIdentifiers[identifier], identifier, culture); _propertyAttributes.Add(identifier, propertyState); } } } }
public static bool PopulateEntity <T>(T entity, IEntityInfo info, IDataReader dataReader, bool stripLeadUnderscore) where T : class, IEntityIdentity { if (dataReader == null || !dataReader.Read()) { return(false); } var extra = entity._extra ?? new Dictionary <string, object>(); //EntityInfoManager.Map<T>(info); var propertyNames = info.Properties; for (int i = 0, l = dataReader.FieldCount; i < l; i++) { if (dataReader.IsDBNull(i)) { continue; } try { var name = dataReader.GetName(i); string type; IEntityPropertyInfo property = null; if (propertyNames.ContainsKey(name)) { property = propertyNames[name]; name = property.Name; type = property.Type.ToLower(); } else { type = dataReader.GetDataTypeName(i).ToLower(); } if (stripLeadUnderscore) { name = name.TrimStart(new[] { '_' }); } object value; switch (type) { case "double": value = dataReader.GetDouble(i); break; case "float": value = dataReader.GetFloat(i); break; case "guid": case "uniqueidentifier": value = Guid.Parse(dataReader.GetString(i)); break; case "money": case "decimal": value = dataReader.GetDecimal(i); break; case "time": case "date": case "smalldatetime": case "datetime": case "datetime2": value = dataReader.GetDateTime(i); break; case "smallint": value = dataReader.GetInt16(i); break; case "short": case "int16": value = dataReader.GetInt16(i); break; case "int": case "int32": value = dataReader.GetInt32(i); break; case "bigint": case "int64": value = dataReader.GetInt64(i); break; case "bit": value = dataReader.GetBoolean(i); break; default: value = dataReader.GetValue(i).ToString(); break; } if (property != null) { if (property.Set != null) { property.Set.DynamicInvoke(entity, value); } else { extra[name] = value; } } else { extra[name] = value; } } catch (Exception ex) { // intentionally bury exceptions Logger.HandleException(LoggingBoundaries.DataLayer, ex); } } return(true); }