コード例 #1
0
        public override CodeGeneratedMethod CreateGetMaxSizeMethodBody(GetMaxSizeCodeGenContext context)
        {
            string lengthProperty = $"{context.ValueVariableName}.{this.LengthPropertyName}";

            string body;

            if (this.ItemTypeModel.IsFixedSize)
            {
                // Constant size items. We can reduce these reasonably well.
                body = $"return {VectorMinSize} + {SerializationHelpers.GetMaxPadding(this.ItemTypeModel.PhysicalLayout[0].Alignment)} + ({this.PaddedMemberInlineSize} * {lengthProperty});";
            }
            else
            {
                var itemContext = context.With(valueVariableName: "itemTemp");

                body =
                    $@"
                    int length = {lengthProperty};
                    int runningSum = {VectorMinSize} + {this.MaxInlineSize};
                    for (int i = 0; i < length; ++i)
                    {{
                        var itemTemp = {context.ValueVariableName}[i];
                        {this.ItemTypeModel.GetThrowIfNullInvocation("itemTemp")};
                        runningSum += {itemContext.GetMaxSizeInvocation(this.ItemTypeModel.ClrType)};
                    }}
                    return runningSum;";
            }

            return(new CodeGeneratedMethod
            {
                MethodBody = body,
            });
        }
コード例 #2
0
            public CodeGeneratedMethod CreateGetMaxSizeMethodBody(GetMaxSizeCodeGenContext context)
            {
                var body = context
                           .With(GetConvertToUnderlyingInvocation(context.ValueVariableName))
                           .GetMaxSizeInvocation(this.underlyingModel.ClrType);

                return(new CodeGeneratedMethod($"return {body};")
                {
                    IsMethodInline = true
                });
            }
コード例 #3
0
        public override CodeGeneratedMethod CreateGetMaxSizeMethodBody(GetMaxSizeCodeGenContext context)
        {
            Type   underlyingType     = this.underlyingTypeModel.ClrType;
            string underlyingTypeName = CSharpHelpers.GetCompilableTypeName(underlyingType);
            string body = context.With(valueVariableName: $"({underlyingTypeName}){context.ValueVariableName}")
                          .GetMaxSizeInvocation(underlyingType);

            return(new CodeGeneratedMethod($"return {body};")
            {
                IsMethodInline = true,
            });
        }
コード例 #4
0
        public override CodeGeneratedMethod CreateGetMaxSizeMethodBody(GetMaxSizeCodeGenContext context)
        {
            var ctx = context.With(valueVariableName: $"{context.ValueVariableName}.Value");

            string body = $@"
                if ({context.ValueVariableName}.HasValue)
                {{
                    return {ctx.GetMaxSizeInvocation(this.underlyingType)};
                }}

                return 0;
            ";

            return(new CodeGeneratedMethod(body)
            {
                IsMethodInline = true
            });
        }