コード例 #1
0
ファイル: TypeCollector.cs プロジェクト: FlorianGrimm/Latrans
        void CollectArray(IArrayTypeSymbol array)
        {
            var elemType = array.ElementType;

            CollectCore(elemType);

            var info = new GenericSerializationInfo {
                FullName = array.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
            };

            if (array.IsSZArray)
            {
                info.FormatterName = $"global::Brimborium.Latrans.JSON.Formatters.ArrayFormatter<{elemType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>";
            }
            else if (array.Rank == 2)
            {
                info.FormatterName = $"global::Brimborium.Latrans.JSON.Formatters.TwoDimentionalArrayFormatter<{elemType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>";
            }
            else if (array.Rank == 3)
            {
                info.FormatterName = $"global::Brimborium.Latrans.JSON.Formatters.ThreeDimentionalArrayFormatter<{elemType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>";
            }
            else if (array.Rank == 4)
            {
                info.FormatterName = $"global::Brimborium.Latrans.JSON.Formatters.FourDimentionalArrayFormatter<{elemType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>";
            }
            else
            {
                throw new InvalidOperationException("does not supports array dimention, " + info.FullName);
            }

            collectedGenericInfo.Add(info);

            return;
        }
コード例 #2
0
        static void MakeArray(IArrayTypeSymbol array, List <GenericSerializationInfo> list)
        {
            var arrayInfo = new GenericSerializationInfo
            {
                FormatterName = $"global::MessagePack.Formatters.ArrayFormatter<{array.ElementType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>()",
                FullName      = array.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
            };

            list.Add(arrayInfo);
        }
コード例 #3
0
        void CollectArray(IArrayTypeSymbol array)
        {
            var elemType = array.ElementType;

            CollectCore(elemType);

            var info = new GenericSerializationInfo
            {
                FormatterName = $"global::MessagePack.Formatters.ArrayFormatter<{elemType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>",
                FullName      = array.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
            };

            collectedGenericInfo.Add(info);

            return;
        }
コード例 #4
0
        private IEnumerable <Instruction> CreateNewArray(ArrayCreationExpressionSyntax syntaxNode,
                                                         IArrayTypeSymbol arrayTypeSymbol, UcfgExpression callTarget)
        {
            expressionService.Associate(syntaxNode, callTarget);

            var instruction = new Instruction
            {
                NewObject = new NewObject
                {
                    Location = syntaxNode.GetUcfgLocation(),
                    Type     = arrayTypeSymbol.ToDisplayString()
                }
            };

            callTarget.ApplyAsTarget(instruction);

            return(new[] { instruction });
        }
コード例 #5
0
        private bool CollectArray(IArrayTypeSymbol arraySymbol)
        {
            var elementType = arraySymbol.ElementType;

            Collect(elementType);

            if (!_formatters.TryGetValue(arraySymbol, out INamedTypeSymbol formatter) &&
                _genericArrayFormatters.TryGetValue(arraySymbol.Rank, out formatter))
            {
                formatter = formatter.Construct(elementType);
                _formatters.Add(arraySymbol, formatter);
            }

            if (formatter == null)
            {
                throw new InvalidOperationException($"Not supported array type {arraySymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}");
            }

            _collected.Add(arraySymbol);
            return(true);
        }