Esempio n. 1
0
 public override InvocationExpressionSyntax Create()
 {
     //TODO: Support seperated collection sizes
     //Case where the array will be send with length-prefixed size
     if (Member.HasAttributeExact <SendSizeAttribute>())
     {
         var generator = new ArraySerializerGenerator(ActualType, Member, Mode, CreateSendSizeExpressionEmitter(Member.GetAttributeExact <SendSizeAttribute>()));
         return(generator.Create());
     }
     else if (Member.HasAttributeExact <KnownSizeAttribute>())
     {
         var generator = new ArraySerializerGenerator(ActualType, Member, Mode, CreateFixedSizeExpressionEmitter(Member.GetAttributeExact <KnownSizeAttribute>()));
         return(generator.Create());
     }
     else
     {
         //TODO: If this isn't the LAST member then there is issues!!
         //Assume it's write ALL and then other side will need to ReadToEnd (but the attribute isn't needed)
         var defaultGenerator = new ArraySerializerGenerator(ActualType, Member, Mode, CreateDefaultExpressionEmitter());
         return(defaultGenerator.Create());
     }
 }
        public override InvocationExpressionSyntax Create()
        {
            //Overriding default behavior.
            bool hasSaneDefaults = Member.ContainingType.HasAttributeExact <WireSaneDefaultsAttribute>(true);

            //TODO: Support seperated collection sizes
            //Case where the array will be send with length-prefixed size

            //Prefer length-prefixing for performance, that is why it's the sane default.
            if (Member.HasAttributeExact <SendSizeAttribute>() || (hasSaneDefaults && !Member.HasAttributeExact <KnownSizeAttribute>()))           //SANE DEFAULT
            {
                IInvokationExpressionEmittable invokable;

                //Only other case is sane defaults are enabled.
                if (Member.HasAttributeExact <SendSizeAttribute>())
                {
                    invokable = CreateSendSizeExpressionEmitter(Member.GetAttributeExact <SendSizeAttribute>());
                }
                else
                {
                    invokable = CreateSendSizeExpressionEmitter(PrimitiveSizeType.Int32);                     //SANE DEFAULT size
                }
                var generator = new ArraySerializerGenerator(ActualType, Member, Mode, invokable);
                return(generator.Create());
            }
            else if (Member.HasAttributeExact <KnownSizeAttribute>())
            {
                var generator = new ArraySerializerGenerator(ActualType, Member, Mode, CreateFixedSizeExpressionEmitter(Member.GetAttributeExact <KnownSizeAttribute>()));
                return(generator.Create());
            }
            else
            {
                //TODO: If this isn't the LAST member then there is issues!!
                //Assume it's write ALL and then other side will need to ReadToEnd (but the attribute isn't needed)
                var defaultGenerator = new ArraySerializerGenerator(ActualType, Member, Mode, CreateDefaultExpressionEmitter());
                return(defaultGenerator.Create());
            }
        }