Esempio n. 1
0
        private static string[] GenerateTypeNamesToDecode(TypeNameConfig[] typeNameConfigs, out MetadataHelpers.AssemblyQualifiedTypeName[] expectedDecodeNames)
        {
            var pooledStrBuilder = PooledStringBuilder.GetInstance();
            StringBuilder typeNamebuilder = pooledStrBuilder.Builder;
            
            var typeNamesToDecode = new string[typeNameConfigs.Length];
            expectedDecodeNames = new MetadataHelpers.AssemblyQualifiedTypeName[typeNameConfigs.Length];
            
            for (int index = 0; index < typeNameConfigs.Length; index++)
            {
                TypeNameConfig typeNameConfig = typeNameConfigs[index];

                string expectedTopLevelTypeName = "X";
                typeNamebuilder.Append("X");
                
                string[] expectedNestedTypes = null;
                if (typeNameConfig.nestingLevel > 0)
                {
                    expectedNestedTypes = new string[typeNameConfig.nestingLevel];
                    for (int i = 0; i < typeNameConfig.nestingLevel; i++)
                    {
                        expectedNestedTypes[i] = "Y" + i;
                        typeNamebuilder.Append("+" + expectedNestedTypes[i]);
                    }
                }

                MetadataHelpers.AssemblyQualifiedTypeName[] expectedTypeArguments;
                if (typeNameConfig.genericParamsConfig == null)
                {
                    expectedTypeArguments = null;
                }
                else
                {
                    string[] genericParamsToDecode = GenerateTypeNamesToDecode(typeNameConfig.genericParamsConfig, out expectedTypeArguments);
                    
                    var genericArityStr = "`" + genericParamsToDecode.Length.ToString();
                    typeNamebuilder.Append(genericArityStr);
                    if (typeNameConfig.nestingLevel == 0)
                    {
                        expectedTopLevelTypeName += genericArityStr;
                    }
                    else
                    {
                        expectedNestedTypes[typeNameConfig.nestingLevel - 1] += genericArityStr;
                    }

                    typeNamebuilder.Append("[");
                    
                    for (int i = 0; i < genericParamsToDecode.Length; i++)
                    {
                        if (i > 0)
                        {
                            typeNamebuilder.Append(", ");
                        }
                        
                        if (typeNameConfig.genericParamsConfig[i].assemblyQualified)
                        {
                            typeNamebuilder.Append("[");
                            typeNamebuilder.Append(genericParamsToDecode[i]);
                            typeNamebuilder.Append("]");
                        }
                        else
                        {
                            typeNamebuilder.Append(genericParamsToDecode[i]);
                        }
                    }

                    typeNamebuilder.Append("]");
                }

                int[] expectedArrayRanks = null;
                switch (typeNameConfig.arrayKind)
                {
                    case ArrayKind.SingleDimensional:
                        typeNamebuilder.Append("[]");
                        expectedArrayRanks = new [] { 1 };
                        break;

                    case ArrayKind.MultiDimensional:
                        typeNamebuilder.Append("[,]");
                        expectedArrayRanks = new[] { 2 };
                        break;

                    case ArrayKind.Jagged:
                        typeNamebuilder.Append("[,][]");
                        expectedArrayRanks = new[] { 1, 2 };
                        break;
                }

                string expectedAssemblyName;
                if (typeNameConfig.assemblyQualified)
                {
                    expectedAssemblyName = "Assembly, Version=0.0.0.0, Culture=neutral, null";
                    typeNamebuilder.Append(", " + expectedAssemblyName);
                }
                else
                {
                    expectedAssemblyName = null;
                }

                typeNamesToDecode[index] = typeNamebuilder.ToString();
                expectedDecodeNames[index] = new MetadataHelpers.AssemblyQualifiedTypeName(expectedTopLevelTypeName, expectedNestedTypes, expectedTypeArguments, expectedArrayRanks, expectedAssemblyName);

                typeNamebuilder.Clear();
            }

            pooledStrBuilder.Free();
            return typeNamesToDecode;
        }
Esempio n. 2
0
 private static void DecodeTypeNameAndVerify(
     MetadataHelpers.SerializedTypeDecoder decoder,
     string nameToDecode,
     string expectedTopLevelType,
     string expectedAssemblyName = null,
     string[] expectedNestedTypes = null,
     MetadataHelpers.AssemblyQualifiedTypeName[] expectedTypeArguments = null,
     int[] expectedArrayRanks = null)
 {
     MetadataHelpers.AssemblyQualifiedTypeName decodedName = decoder.DecodeTypeName(nameToDecode);
     VerifyDecodedTypeName(decodedName, expectedTopLevelType, expectedAssemblyName, expectedNestedTypes, expectedTypeArguments, expectedArrayRanks);
 }
Esempio n. 3
0
        private static void DecodeTypeNamesAndVerify(MetadataHelpers.SerializedTypeDecoder decoder, string[] namesToDecode, MetadataHelpers.AssemblyQualifiedTypeName[] expectedDecodedNames)
        {
            Assert.Equal(namesToDecode.Length, expectedDecodedNames.Length);

            for (int i = 0; i < namesToDecode.Length; i++)
            {
                var expectedDecodedName = expectedDecodedNames[i];
                DecodeTypeNameAndVerify(decoder, namesToDecode[i], expectedDecodedName.TopLevelType, expectedDecodedName.AssemblyName,
                    expectedDecodedName.NestedTypes, expectedDecodedName.TypeArguments, expectedDecodedName.ArrayRanks);
            }
        }
Esempio n. 4
0
 private static void VerifyDecodedTypeName(
     MetadataHelpers.AssemblyQualifiedTypeName decodedName,
     string expectedTopLevelType,
     string expectedAssemblyName,
     string[] expectedNestedTypes,
     MetadataHelpers.AssemblyQualifiedTypeName[] expectedTypeArguments,
     int[] expectedArrayRanks)
 {
     Assert.Equal(expectedTopLevelType, decodedName.TopLevelType);
     Assert.Equal(expectedAssemblyName, decodedName.AssemblyName);
     Assert.Equal(expectedNestedTypes, decodedName.NestedTypes);
     
     if (decodedName.TypeArguments == null)
     {
         Assert.Null(expectedTypeArguments);
     }
     else
     {
         var decodedTypeArguments = decodedName.TypeArguments;
         for (int i = 0; i < decodedTypeArguments.Length; i++)
         {
             var expectedTypeArgument = expectedTypeArguments[i];
             VerifyDecodedTypeName(decodedTypeArguments[i], expectedTypeArgument.TopLevelType, expectedTypeArgument.AssemblyName,
                 expectedTypeArgument.NestedTypes, expectedTypeArgument.TypeArguments, expectedTypeArgument.ArrayRanks);
         }
     }
 }