public IEnumerable <DiscoveredResource> GetDiscoveredResources( Type target, object instance, MemberInfo mi, string translation, string resourceKey, string resourceKeyPrefix, bool typeKeyPrefixSpecified, bool isHidden, string typeOldName, string typeOldNamespace, Type declaringType, Type returnType, bool isSimpleType) { // scan custom registered attributes (if any) foreach (var descriptor in _configurationContext.CustomAttributes.ToList()) { var customAttributes = mi.GetCustomAttributes(descriptor.CustomAttribute); foreach (var customAttribute in customAttributes) { var customAttributeKey = _keyBuilder.BuildResourceKey(resourceKey, customAttribute); var propertyName = customAttributeKey.Split('.').Last(); var oldResourceKeys = _oldKeyBuilder.GenerateOldResourceKey(target, propertyName, mi, resourceKeyPrefix, typeOldName, typeOldNamespace); var foreignTranslation = string.Empty; if (descriptor.GenerateTranslation) { var z1 = customAttribute.GetType().ToString(); var z2 = customAttribute.ToString(); foreignTranslation = !z1.Equals(z2) ? z2 : propertyName; } yield return(new DiscoveredResource(mi, customAttributeKey, _translationBuilder.FromSingle(foreignTranslation), propertyName, declaringType, returnType, isSimpleType) { TypeName = target.Name, TypeNamespace = target.Namespace, TypeOldName = oldResourceKeys.Item2, TypeOldNamespace = typeOldNamespace, OldResourceKey = oldResourceKeys.Item1 }); } } }
public IEnumerable <DiscoveredResource> GetDiscoveredResources( Type target, object instance, MemberInfo mi, string translation, string resourceKey, string resourceKeyPrefix, bool typeKeyPrefixSpecified, bool isHidden, string typeOldName, string typeOldNamespace, Type declaringType, Type returnType, bool isSimpleType) { // try to fetch also [Display()] attribute to generate new "...-Description" resource => usually used for help text labels var displayAttribute = mi.GetCustomAttribute <DisplayAttribute>(); if (displayAttribute?.Description != null) { var propertyName = $"{mi.Name}-Description"; var oldResourceKeys = _oldKeyBuilder.GenerateOldResourceKey(target, propertyName, mi, resourceKeyPrefix, typeOldName, typeOldNamespace); yield return(new DiscoveredResource(mi, $"{resourceKey}-Description", _translationBuilder.FromSingle(displayAttribute.Description), propertyName, declaringType, returnType, isSimpleType) { TypeName = target.Name, TypeNamespace = target.Namespace, TypeOldName = oldResourceKeys.Item2, TypeOldNamespace = typeOldNamespace, OldResourceKey = oldResourceKeys.Item1 }); } }
public IEnumerable <DiscoveredResource> GetDiscoveredResources( Type target, object instance, MemberInfo mi, string translation, string resourceKey, string resourceKeyPrefix, bool typeKeyPrefixSpecified, bool isHidden, string typeOldName, string typeOldNamespace, Type declaringType, Type returnType, bool isSimpleType) { var keyAttributes = mi.GetCustomAttributes <ResourceKeyAttribute>().ToList(); var validationAttributes = mi.GetCustomAttributes <ValidationAttribute>().ToList(); foreach (var validationAttribute in validationAttributes) { if (validationAttribute.GetType() == typeof(DataTypeAttribute)) { continue; } if (keyAttributes.Count > 1) { continue; } if (keyAttributes.Count == 1) { resourceKey = keyAttributes[0].Key; } var validationResourceKey = _keyBuilder.BuildResourceKey(resourceKey, validationAttribute); var propertyName = validationResourceKey.Split('.').Last(); var oldResourceKeys = _oldKeyBuilder.GenerateOldResourceKey( target, propertyName, mi, resourceKeyPrefix, typeOldName, typeOldNamespace); yield return(new DiscoveredResource( mi, validationResourceKey, _translationBuilder.FromSingle(string.IsNullOrEmpty(validationAttribute.ErrorMessage) ? propertyName : validationAttribute.ErrorMessage), propertyName, declaringType, returnType, isSimpleType) { TypeName = target.Name, TypeNamespace = target.Namespace, TypeOldName = oldResourceKeys.Item2, TypeOldNamespace = typeOldNamespace, OldResourceKey = oldResourceKeys.Item1 }); } }