Exemple #1
0
        private void AssertStructure(ResourceEntryInfo expectedStructure, IResourceEntry directory)
        {
            var expectedStack = new Stack <ResourceEntryInfo>();
            var stack         = new Stack <IResourceEntry>();

            expectedStack.Push(expectedStructure);
            stack.Push(directory);

            while (stack.Count > 0)
            {
                var expected = expectedStack.Pop();
                var current  = stack.Pop();

                Assert.Equal(expected.Name, current.Name);
                Assert.Equal(expected.Id, current.Id);

                if (expected.IsData)
                {
                    Assert.IsAssignableFrom <IResourceData>(current);
                }
                else
                {
                    Assert.IsAssignableFrom <IResourceDirectory>(current);
                    var subEntries = ((IResourceDirectory)current).Entries;
                    Assert.Equal(expected.Entries.Count, subEntries.Count);

                    for (int i = 0; i < subEntries.Count; i++)
                    {
                        expectedStack.Push(expected.Entries[i]);
                        stack.Push(subEntries[i]);
                    }
                }
            }
        }
Exemple #2
0
        public void DotNetHelloWorld()
        {
            var peImage = PEImage.FromBytes(Properties.Resources.HelloWorld);

            var expected = new ResourceEntryInfo(0)
            {
                Entries =
                {
                    new ResourceEntryInfo(16)
                    {
                        Entries =
                        {
                            new ResourceEntryInfo(1)
                            {
                                Entries =
                                {
                                    new ResourceEntryInfo(0)
                                    {
                                        IsData = true
                                    }
                                }
                            }
                        }
                    },

                    new ResourceEntryInfo(24)
                    {
                        Entries =
                        {
                            new ResourceEntryInfo(1)
                            {
                                Entries =
                                {
                                    new ResourceEntryInfo(0)
                                    {
                                        IsData = true
                                    }
                                }
                            }
                        }
                    }
                }
            };

            AssertStructure(expected, peImage.Resources);
        }
Exemple #3
0
        public object ProvideValue(IServiceProvider serviceProvider)
        {
            if (Key.IsNullOrEmpty())
            {
                throw new MissingResourceException("You should provide Resource key.");
            }

            var resourceInfo = new ResourceEntryInfo(Key);
            var resource     = new ResourceManager(resourceInfo.Dictionary, resourceInfo.Assembly);
            var result       = resource.GetString(resourceInfo.ResourceKey, resourceInfo.CurrentCultureInfo);

            if (result == null)
            {
                throw new MissingResourceException($"{resourceInfo.ResourceKey} is not found in {resourceInfo.Dictionary} dictionary for {resourceInfo.CurrentCultureInfo.Name} culture.");
            }
            return(result);
        }