示例#1
0
        private SyntaxNodeOrToken YieldSerializerTypeName()
        {
            //We need special case handling for string arrays.
            if (ElementType.IsTypeExact <string>())
            {
                StringTypeSerializationStatementsBlockEmitter stringSerializerEmitter = new StringTypeSerializationStatementsBlockEmitter(ActualType, Member, Mode);
                InvocationExpressionSyntax expressionSyntax = stringSerializerEmitter.Create();

                TypeNameTypeCollector genericNameCollector = new TypeNameTypeCollector();
                genericNameCollector.Visit(expressionSyntax);

                //Now we analyze the expression to determine the string type information
                return(genericNameCollector.Types.First());
            }
            else if (ElementType.IsEnumType())
            {
                //TODO: Enum string arrays aren't supported. This will break if they send EnumString
                //Send element type instead of array type, it's SO much easier that way! But kinda hacky
                EnumTypeSerializerStatementsBlockEmitter emitter = new EnumTypeSerializerStatementsBlockEmitter(ActualType.ElementType, Member, Mode);
                InvocationExpressionSyntax invokeSyntax          = emitter.Create();

                TypeNameTypeCollector genericNameCollector = new TypeNameTypeCollector();
                genericNameCollector.Visit(invokeSyntax);

                //Now we analyze the expression to determine the Enum serializer type.
                return(genericNameCollector.Types.First());
            }
            else
            {
                return(IdentifierName(GeneratedSerializerNameStringBuilder.Create(ElementType).BuildName(Member)));
            }
        }
        private void EmitRequestedGenericTypeSerializers(ITypeSymbol[] genericTypeSymbols)
        {
            foreach (ITypeSymbol genericTypeSymbol in genericTypeSymbols)
            {
                GeneratedSerializerNameStringBuilder builder = new GeneratedSerializerNameStringBuilder(genericTypeSymbol);
                string genericSerializerName = builder.BuildName();

                //If an emitted serializer name matches the expected generic serializer name
                //then one is going to be emitted so we should not do anything.
                if (this.GeneratedTypeNames.Any(t => genericSerializerName == t))
                {
                    continue;
                }

                //TODO: Don't hardcore default namespace!!
                //Now we check if one exists in the compilation unit or references
                INamedTypeSymbol symbol = CompilationUnit.GetTypeByMetadataName($"FreecraftCore.Serializer.{genericSerializerName}");
                if (symbol != null)
                {
                    continue;
                }

                //TODO: Calling this may end up having us require MORE generic serializers but this case isn't handled yet.
                //At this point we don't have a generic serializer defined for the closed generic type
                //and we should just emit one otherwise compilation will fail.
                WriteSerializerStrategyClass((INamedTypeSymbol)genericTypeSymbol);
            }
        }
        public override InvocationExpressionSyntax Create()
        {
            string serializerTypeName = GeneratedSerializerNameStringBuilder
                                        .Create(ActualType)
                                        .BuildName();

            RawComplexTypeSerializationGenerator generator = new RawComplexTypeSerializationGenerator(ActualType, Member, Mode, serializerTypeName);

            return(generator.Create());
        }
 protected BaseSerializerImplementationCompilationUnitEmitter([NotNull] INamedTypeSymbol typeSymbol)
 {
     TypeSymbol           = typeSymbol ?? throw new ArgumentNullException(nameof(typeSymbol));
     SerializableTypeName = new SerializableTypeNameStringBuilder(TypeSymbol).ToString();
     SerializerTypeName   = new GeneratedSerializerNameStringBuilder(TypeSymbol).ToString();
 }