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)
        {
            // check if there are [ResourceKey] attributes
            var keyAttributes = mi.GetCustomAttributes <ResourceKeyAttribute>().ToList();

            return(keyAttributes.Select(attr =>
            {
                var translations = TranslationsHelper.GetAllTranslations(mi, resourceKey, string.IsNullOrEmpty(attr.Value) ? translation : attr.Value);

                return new DiscoveredResource(mi,
                                              ResourceKeyBuilder.BuildResourceKey(typeKeyPrefixSpecified ? resourceKeyPrefix : null, attr.Key, string.Empty),
                                              translations,
                                              null,
                                              declaringType,
                                              returnType,
                                              true)
                {
                    FromResourceKeyAttribute = true
                };
            }));
        }
Пример #2
0
        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)
        {
            // check if there are [ResourceKey] attributes
            var keyAttributes = mi.GetCustomAttributes <ResourceKeyAttribute>().ToList();

            if (keyAttributes.Any())
            {
                yield break;
            }

            // check if there are [UseResource] attributes
            var useAttribute = mi.GetCustomAttribute <UseResourceAttribute>();

            if (useAttribute != null)
            {
                yield break;
            }

            var isResourceHidden = isHidden || mi.GetCustomAttribute <HiddenAttribute>() != null;
            var translations     = TranslationsHelper.GetAllTranslations(mi, resourceKey, translation);
            var oldResourceKeys  = OldResourceKeyBuilder.GenerateOldResourceKey(target, mi.Name, mi, resourceKeyPrefix, typeOldName, typeOldNamespace);

            yield return(new DiscoveredResource(mi,
                                                resourceKey,
                                                translations,
                                                mi.Name,
                                                declaringType,
                                                returnType,
                                                isSimpleType,
                                                isResourceHidden)
            {
                TypeName = target.Name,
                TypeNamespace = target.Namespace,
                TypeOldName = oldResourceKeys.Item2,
                TypeOldNamespace = typeOldNamespace,
                OldResourceKey = oldResourceKeys.Item1
            });
        }