Esempio n. 1
0
        private object TargetFrameworkName_Parser(
            string name,
            PatternTable table)
        {
            object obj = null;

            // Check for replacements
            if (table != null)
            {
                if (table.TryLookup(PropertyNames.TargetFrameworkMoniker, name, out obj))
                {
                    return(obj);
                }
            }

            // Check the cache for an exact match
            if (!string.IsNullOrEmpty(name))
            {
                NuGetFramework cachedResult;
                if (!_frameworkCache.TryGetValue(name, out cachedResult))
                {
                    // Parse and add the framework to the cache
                    cachedResult = TargetFrameworkName_ParserCore(name);
                    _frameworkCache.Add(name, cachedResult);
                }

                return(cachedResult);
            }

            // Let the framework parser handle null/empty and create the error message.
            return(TargetFrameworkName_ParserCore(name));
        }
Esempio n. 2
0
        public void PatternTable_LookupWhenEmpty()
        {
            // Arrange
            var table = new PatternTable();

            // Act
            object obj;
            var    b = table.TryLookup("tfm", "any", out obj);

            // Assert
            Assert.False(b);
            Assert.Null(obj);
        }
Esempio n. 3
0
        private static object CodeLanguage_Parser(string name, PatternTable table)
        {
            if (table != null)
            {
                object val;
                if (table.TryLookup(PropertyNames.CodeLanguage, name, out val))
                {
                    return(val);
                }
            }

            // Code language values must be alpha numeric.
            return(name.All(c => char.IsLetterOrDigit(c)) ? name : null);
        }
Esempio n. 4
0
        public void PatternTable_LookupWithMiss()
        {
            // Arrange
            var data = new List <PatternTableEntry>()
            {
                new PatternTableEntry("tfm", "dotnet", NuGetFramework.Parse("dotnet"))
            };

            var table = new PatternTable(data);

            // Act
            object obj;
            var    b = table.TryLookup("tfm", "any", out obj);

            // Assert
            Assert.False(b);
            Assert.Null(obj);
        }
Esempio n. 5
0
        public void PatternTable_LookupWithValue()
        {
            // Arrange
            var dotnet = NuGetFramework.Parse("dotnet");
            var data   = new List <PatternTableEntry>()
            {
                new PatternTableEntry("tfm", "any", dotnet)
            };

            var table = new PatternTable(data);

            // Act
            object obj;
            var    b = table.TryLookup("tfm", "any", out obj);

            // Assert
            Assert.True(b);
            Assert.Equal(dotnet, obj);
        }
Esempio n. 6
0
        private static object Locale_Parser(string name, PatternTable table)
        {
            if (table != null)
            {
                object val;
                if (table.TryLookup(PropertyNames.Locale, name, out val))
                {
                    return(val);
                }
            }

            if (name.Length == 2)
            {
                return(name);
            }
            else if (name.Length >= 4 && name[2] == '-')
            {
                return(name);
            }

            return(null);
        }