public IEnumerable <ReferenceFailingPropertyInfo> GetReferencingLocalizeFailingProperties(ILocalizedControlled data) { DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(data.DataSourceId.InterfaceType); IEnumerable <DataFieldDescriptor> requiredDataFieldDescriptors = dataTypeDescriptor.Fields.Where(f => f.ForeignKeyReferenceTypeName != null); foreach (DataFieldDescriptor dataFieldDescriptor in requiredDataFieldDescriptors) { Type referencedType = TypeManager.GetType(dataFieldDescriptor.ForeignKeyReferenceTypeName); if (!DataLocalizationFacade.IsLocalized(referencedType)) { continue; // No special handling for not localized data. } IData referencedData = data.GetReferenced(dataFieldDescriptor.Name); if (referencedData != null) { continue; // Data has already been localized } bool optionalReferenceWithValue = false; if (dataFieldDescriptor.IsNullable) { PropertyInfo propertyInfo = data.DataSourceId.InterfaceType.GetPropertiesRecursively().Single(f => f.Name == dataFieldDescriptor.Name); object value = propertyInfo.GetValue(data, null); if (value == null || object.Equals(value, dataFieldDescriptor.DefaultValue)) { continue; // Optional reference is null; } optionalReferenceWithValue = true; } CultureInfo locale = data.DataSourceId.LocaleScope; using (new DataScope(locale)) { referencedData = data.GetReferenced(dataFieldDescriptor.Name); } ReferenceFailingPropertyInfo referenceFailingPropertyInfo = new ReferenceFailingPropertyInfo ( dataFieldDescriptor, referencedType, referencedData, optionalReferenceWithValue ); yield return(referenceFailingPropertyInfo); } }
public IEnumerable<ReferenceFailingPropertyInfo> GetReferencingLocalizeFailingProperties(ILocalizedControlled data) { DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(data.DataSourceId.InterfaceType); IEnumerable<DataFieldDescriptor> requiredDataFieldDescriptors = dataTypeDescriptor.Fields.Where(f => f.ForeignKeyReferenceTypeName != null); foreach (DataFieldDescriptor dataFieldDescriptor in requiredDataFieldDescriptors) { Type referencedType = TypeManager.GetType(dataFieldDescriptor.ForeignKeyReferenceTypeName); if (!DataLocalizationFacade.IsLocalized(referencedType)) continue; // No special handling for not localized data. IData referencedData = data.GetReferenced(dataFieldDescriptor.Name); if (referencedData != null) continue; // Data has already been localized bool optionalReferenceWithValue = false; if (dataFieldDescriptor.IsNullable) { PropertyInfo propertyInfo = data.DataSourceId.InterfaceType.GetPropertiesRecursively().Single(f => f.Name == dataFieldDescriptor.Name); object value = propertyInfo.GetValue(data, null); if (value == null || object.Equals(value, dataFieldDescriptor.DefaultValue)) { continue; // Optional reference is null; } optionalReferenceWithValue = true; } CultureInfo locale = data.DataSourceId.LocaleScope; using (new DataScope(locale)) { referencedData = data.GetReferenced(dataFieldDescriptor.Name); } ReferenceFailingPropertyInfo referenceFailingPropertyInfo = new ReferenceFailingPropertyInfo ( dataFieldDescriptor, referencedType, referencedData, optionalReferenceWithValue ); yield return referenceFailingPropertyInfo; } }