コード例 #1
0
        public async Task GenerateForCustomFlagWrapperFields(
            FileGeneration fg,
            ObjectGeneration objGen,
            TypeGeneration typeGen,
            Accessor dataAccessor,
            int?currentPosition,
            string passedLenAccessor,
            DataType dataType = null)
        {
            var    fieldData = typeGen.GetFieldData();
            var    gen       = this.Module.GetTypeGeneration(typeGen.GetType());
            string loc;

            if (fieldData.HasTrigger)
            {
                using (var args = new ArgsWrapper(fg,
                                                  $"partial void {typeGen.Name}CustomParse"))
                {
                    args.Add($"{nameof(OverlayStream)} stream");
                    args.Add($"long finalPos");
                    args.Add($"int offset");
                }
                if (typeGen.Nullable && !typeGen.CanBeNullable(getter: true))
                {
                    fg.AppendLine($"public bool {typeGen.Name}_IsSet => Get{typeGen.Name}IsSetCustom();");
                }
                loc = $"_{typeGen.Name}Location.Value";
            }
            else if (dataType != null)
            {
                loc = $"_{typeGen.Name}Location";
                DataBinaryTranslationGeneration.GenerateWrapperExtraMembers(fg, dataType, objGen, typeGen, passedLenAccessor);
            }
            else
            {
                loc = passedLenAccessor;
            }
            using (var args = new ArgsWrapper(fg,
                                              $"public {typeGen.OverrideStr}{typeGen.TypeName(getter: true)}{(typeGen.IsNullable ? "?" : null)} {typeGen.Name} => Get{typeGen.Name}Custom"))
            {
                if (!fieldData.HasTrigger && dataType == null)
                {
                    args.Add($"location: {loc ?? "0x0"}");
                }
            }
            if (!fieldData.HasTrigger)
            {
                currentPosition += fieldData.Length ?? await gen.ExpectedLength(objGen, typeGen);
            }
        }