private CultureInfo[] GetSupportedCultures(Type interfaceType)
 {
     if (DataLocalizationFacade.IsLocalized(interfaceType))
     {
         return(DataLocalizationFacade.ActiveLocalizationCultures.ToArray());
     }
     return(new[] { CultureInfo.InvariantCulture });
 }
        /// <exclude />
        public static CultureInfo MapByType(Type type)
        {
            if (DataLocalizationFacade.IsLocalized(type))
            {
                return(CurrentLocalizationScope);
            }

            return(CultureInfo.InvariantCulture);
        }
Пример #3
0
        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);
            }
        }