コード例 #1
0
    public override XElement GenerateForXSD(
        ObjectGeneration objGen,
        XElement rootElement,
        XElement choiceElement,
        TypeGeneration typeGen,
        string nameOverride = null)
    {
        var elem = new XElement(XmlTranslationModule.XSDNamespace + "element",
                                new XAttribute("name", nameOverride ?? typeGen.Name),
                                new XAttribute("type", $"{typeGen.Name}Type"));

        choiceElement.Add(elem);

        var subChoice = new XElement(XmlTranslationModule.XSDNamespace + "choice",
                                     new XAttribute("minOccurs", 0),
                                     new XAttribute("maxOccurs", "unbounded"));

        rootElement.Add(
            new XElement(XmlTranslationModule.XSDNamespace + "complexType",
                         new XAttribute("name", $"{typeGen.Name}Type"),
                         subChoice));

        var list    = typeGen as ListType;
        var xmlGen  = XmlMod.GetTypeGeneration(list.SubTypeGeneration.GetType());
        var subElem = xmlGen.GenerateForXSD(
            objGen,
            rootElement,
            subChoice,
            list.SubTypeGeneration,
            nameOverride: "Item");

        return(elem);
    }
コード例 #2
0
    public override XElement GenerateForXSD(
        ObjectGeneration obj,
        XElement rootElement,
        XElement choiceElement,
        TypeGeneration typeGen,
        string nameOverride = null)
    {
        var common       = XmlMod.CommonXSDLocation(obj.ProtoGen);
        var relativePath = common.GetRelativePathTo(XmlMod.ObjectXSDLocation(obj));
        var includeElem  = new XElement(
            XmlTranslationModule.XSDNamespace + "include",
            new XAttribute("schemaLocation", relativePath));

        if (!rootElement.Elements().Any((e) => e.ContentEqual(includeElem)))
        {
            rootElement.AddFirst(includeElem);
        }

        var elem = new XElement(XmlTranslationModule.XSDNamespace + "element");

        elem.Add(new XAttribute("name", nameOverride ?? typeGen.Name));
        elem.Add(new XAttribute("type", Nullable ? "NullableValueType" : "ValueType"));
        choiceElement.Add(elem);
        return(elem);
    }
コード例 #3
0
    public void GenerateCopyInRet_Internal(
        StructuredStringBuilder sb,
        ObjectGeneration objGen,
        TypeGeneration typeGen,
        Accessor nodeAccessor,
        Accessor itemAccessor,
        bool ret,
        Accessor errorMaskAccessor,
        Accessor translationMaskAccessor)
    {
        var list = typeGen as ListType;

        if (!XmlMod.TryGetTypeGeneration(list.SubTypeGeneration.GetType(), out var subTransl))
        {
            throw new ArgumentException("Unsupported type generator: " + list.SubTypeGeneration);
        }

        if (ret)
        {
            throw new NotImplementedException();
        }

        MaskGenerationUtility.WrapErrorFieldIndexPush(
            sb: sb,
            toDo: () =>
        {
            using (var args = new Function(
                       sb,
                       $"if ({TranslatorName}<{list.SubTypeGeneration.TypeName(getter: false, needsCovariance: true)}>.Instance.Parse"))
            {
                args.AddPassArg($"{XmlTranslationModule.XElementLine.GetParameterName(objGen, Context.Backend)}");
                args.Add($"enumer: out var {typeGen.Name}Item");
                args.Add($"transl: {subTransl.GetTranslatorInstance(list.SubTypeGeneration, getter: false)}.Parse");
                args.Add("errorMask: errorMask");
                args.Add($"translationMask: {translationMaskAccessor})");
            }
            using (sb.CurlyBrace())
            {
                if (typeGen.Nullable)
                {
                    sb.AppendLine($"{itemAccessor.Access} = {typeGen.Name}Item.ToExtendedList();");
                }
                else
                {
                    sb.AppendLine($"{itemAccessor.Access}.SetTo({typeGen.Name}Item);");
                }
            }
            sb.AppendLine("else");
            using (sb.CurlyBrace())
            {
                list.GenerateClear(sb, itemAccessor);
            }
        },
            errorMaskAccessor: errorMaskAccessor,
            indexAccessor: typeGen.IndexEnumInt);
    }
コード例 #4
0
    public override string GetTranslatorInstance(TypeGeneration typeGen, bool getter)
    {
        var list = typeGen as ListType;

        if (!XmlMod.TryGetTypeGeneration(list.SubTypeGeneration.GetType(), out var subTransl))
        {
            throw new ArgumentException("Unsupported type generator: " + list.SubTypeGeneration);
        }

        var subMaskStr = subTransl.MaskModule.GetMaskModule(list.SubTypeGeneration.GetType()).GetErrorMaskTypeStr(list.SubTypeGeneration);

        return($"{TranslatorName}<{list.SubTypeGeneration.TypeName(getter)}, {subMaskStr}>.Instance");
    }
コード例 #5
0
    public override XElement GenerateForXSD(
        ObjectGeneration objGen,
        XElement rootElement,
        XElement choiceElement,
        TypeGeneration typeGen,
        string nameOverride = null)
    {
        LoquiType loqui           = typeGen as LoquiType;
        var       targetObject    = loqui.TargetObjectGeneration;
        var       targetNamespace = XmlMod.ObjectNamespace(targetObject);
        var       diffNamespace   = !targetNamespace.Equals(XmlMod.ObjectNamespace(objGen));

        if (diffNamespace)
        {
            rootElement.Add(
                new XAttribute(XNamespace.Xmlns + $"{targetObject.Name.ToLower()}", XmlMod.ObjectNamespace(targetObject)));
        }
        FilePath xsdPath      = XmlMod.ObjectXSDLocation(targetObject);
        var      relativePath = xsdPath.GetRelativePathTo(objGen.TargetDir);
        var      importElem   = new XElement(
            XmlTranslationModule.XSDNamespace + "include",
            new XAttribute("schemaLocation", relativePath));

        if (diffNamespace &&
            !rootElement.Elements().Any((e) => e.ContentEqual(importElem)))
        {
            importElem.Add(new XAttribute("namespace", XmlMod.ObjectNamespace(targetObject)));
        }
        if (!rootElement.Elements().Any((e) => e.ContentEqual(importElem)))
        {
            rootElement.AddFirst(importElem);
        }
        var elem = new XElement(
            XmlTranslationModule.XSDNamespace + "element",
            new XAttribute("name", nameOverride ?? loqui.Name));

        if (diffNamespace)
        {
            elem.Add(
                new XAttribute("type", $"{targetObject.Name.ToLower()}:{loqui.TargetObjectGeneration.Name}Type"));
        }
        else
        {
            elem.Add(
                new XAttribute("type", $"{loqui.TargetObjectGeneration.Name}Type"));
        }
        choiceElement.Add(elem);
        return(elem);
    }
コード例 #6
0
    public override XElement GenerateForXSD(
        ObjectGeneration obj,
        XElement rootElement,
        XElement choiceElement,
        TypeGeneration typeGen,
        string nameOverride = null)
    {
        if (!(typeGen is DictType dict))
        {
            throw new ArgumentException();
        }
        if (dict.Mode == DictMode.KeyValue)
        {
            throw new NotImplementedException();
        }
        var elem = new XElement(XmlTranslationModule.XSDNamespace + "element",
                                new XAttribute("name", nameOverride ?? typeGen.Name),
                                new XAttribute("type", $"{typeGen.Name}Type"));

        choiceElement.Add(elem);

        var subChoice = new XElement(XmlTranslationModule.XSDNamespace + "choice",
                                     new XAttribute("minOccurs", 0),
                                     new XAttribute("maxOccurs", "unbounded"));

        rootElement.Add(
            new XElement(XmlTranslationModule.XSDNamespace + "complexType",
                         new XAttribute("name", $"{typeGen.Name}Type"),
                         subChoice));

        var xmlGen  = XmlMod.GetTypeGeneration(dict.ValueTypeGen.GetType());
        var subElem = xmlGen.GenerateForXSD(
            obj,
            rootElement,
            subChoice,
            dict.ValueTypeGen,
            nameOverride: "Item");

        return(elem);
    }
コード例 #7
0
    public override void GenerateWrite(
        StructuredStringBuilder sb,
        ObjectGeneration objGen,
        TypeGeneration typeGen,
        Accessor writerAccessor,
        Accessor itemAccessor,
        Accessor errorMaskAccessor,
        Accessor nameAccessor,
        Accessor translationMaskAccessor)
    {
        var dictType = typeGen as DictType;

        if (!XmlMod.TryGetTypeGeneration(dictType.ValueTypeGen.GetType(), out var valTransl))
        {
            throw new ArgumentException("Unsupported type generator: " + dictType.ValueTypeGen);
        }

        switch (dictType.Mode)
        {
        case DictMode.KeyValue:
            if (!XmlMod.TryGetTypeGeneration(dictType.KeyTypeGen.GetType(), out var keyTransl))
            {
                throw new ArgumentException("Unsupported type generator: " + dictType.KeyTypeGen);
            }

            using (var args = sb.Call(
                       $"DictXmlTranslation<{dictType.KeyTypeGen.TypeName(getter: true)}, {dictType.ValueTypeGen.TypeName(getter: true)}>.Instance.Write"))
            {
                args.Add($"node: {writerAccessor}");
                args.Add($"name: {nameAccessor}");
                args.Add($"items: {itemAccessor.Access}");
                if (typeGen.HasIndex)
                {
                    args.Add($"fieldIndex: (int){typeGen.IndexEnumName}");
                    args.Add($"errorMask: {errorMaskAccessor}");
                }
                else
                {
                    throw new NotImplementedException();
                }
                args.Add($"translationMask: {translationMaskAccessor}");
                args.Add((gen) =>
                {
                    gen.AppendLine($"keyTransl: (XElement subNode, {dictType.KeyTypeGen.TypeName(getter: true)} subItem, ErrorMaskBuilder? dictSubMask, {nameof(TranslationCrystal)}? dictSubTranslMask) =>");
                    using (new CurlyBrace(gen))
                    {
                        keyTransl.GenerateWrite(
                            sb: gen,
                            objGen: objGen,
                            typeGen: dictType.KeyTypeGen,
                            writerAccessor: "subNode",
                            itemAccessor: $"subItem",
                            errorMaskAccessor: $"dictSubMask",
                            translationMaskAccessor: "dictSubTranslMask",
                            nameAccessor: "\"Key\"");
                    }
                });
                args.Add((gen) =>
                {
                    gen.AppendLine($"valTransl: (XElement subNode, {dictType.ValueTypeGen.TypeName(getter: true)} subItem, ErrorMaskBuilder? dictSubMask, {nameof(TranslationCrystal)}? dictSubTranslMask) =>");
                    using (new CurlyBrace(gen))
                    {
                        valTransl.GenerateWrite(
                            sb: gen,
                            objGen: objGen,
                            typeGen: dictType.ValueTypeGen,
                            writerAccessor: "subNode",
                            itemAccessor: $"subItem",
                            errorMaskAccessor: $"dictSubMask",
                            translationMaskAccessor: "dictSubTranslMask",
                            nameAccessor: "\"Value\"");
                    }
                });
            }
            break;

        case DictMode.KeyedValue:
            MaskGenerationUtility.WrapErrorFieldIndexPush(
                sb: sb,
                toDo: () =>
            {
                using (var args = sb.Call(
                           $"KeyedDictXmlTranslation<{dictType.KeyTypeGen.TypeName(getter: true)}, {dictType.ValueTypeGen.TypeName(getter: true)}>.Instance.Write"))
                {
                    args.Add($"{XmlTranslationModule.XElementLine.GetParameterName(objGen, Context.Backend)}: {writerAccessor}");
                    args.Add($"name: {nameAccessor}");
                    args.Add($"items: {itemAccessor.Access}.Items");
                    args.Add($"translationMask: {translationMaskAccessor}");
                    args.Add("errorMask: errorMask");
                    args.Add((gen) =>
                    {
                        gen.AppendLine($"valTransl: (XElement subNode, {dictType.ValueTypeGen.TypeName(getter: true)} subItem, ErrorMaskBuilder? dictSubMask, {nameof(TranslationCrystal)}? dictTranslMask) =>");
                        using (new CurlyBrace(gen))
                        {
                            valTransl.GenerateWrite(
                                sb: gen,
                                objGen: objGen,
                                typeGen: dictType.ValueTypeGen,
                                writerAccessor: "subNode",
                                itemAccessor: new Accessor($"subItem"),
                                errorMaskAccessor: $"dictSubMask",
                                translationMaskAccessor: "dictTranslMask",
                                nameAccessor: "null");
                        }
                    });
                }
            },
                errorMaskAccessor: errorMaskAccessor,
                indexAccessor: typeGen.IndexEnumInt);
            break;

        default:
            throw new NotImplementedException();
        }
    }
コード例 #8
0
    private void GenerateCopyIn_Internal(
        StructuredStringBuilder sb,
        ObjectGeneration objGen,
        TypeGeneration typeGen,
        Accessor nodeAccessor,
        Accessor itemAccessor,
        bool ret,
        Accessor errorMaskAccessor,
        Accessor translationMaskAccessor)
    {
        var            dictType   = typeGen as IDictType;
        TypeGeneration keyTypeGen = dictType.KeyTypeGen;

        if (keyTypeGen == null)
        {
            if (!XmlMod.Gen.TryGetTypeGeneration(dictType.KeyTypeGen.TypeName(getter: false), out keyTypeGen))
            {
                throw new ArgumentException($"Could not find dictionary key type for {dictType.KeyTypeGen.TypeName(getter: false)}");
            }
        }

        if (!XmlMod.TryGetTypeGeneration(dictType.ValueTypeGen.GetType(), out var valSubTransl))
        {
            throw new ArgumentException("Unsupported type generator: " + dictType.ValueTypeGen);
        }
        var valSubMaskStr = valSubTransl.MaskModule.GetMaskModule(dictType.ValueTypeGen.GetType()).GetTranslationMaskTypeStr(dictType.ValueTypeGen);

        string prefix;

        if (!ret)
        {
            prefix = null;
        }
        else
        {
            prefix = itemAccessor.Access;
        }

        string funcStr;

        switch (dictType.Mode)
        {
        case DictMode.KeyValue:
            funcStr = $"{prefix}DictXmlTranslation<{dictType.KeyTypeGen.TypeName(getter: false)}, {dictType.ValueTypeGen.TypeName(getter: false)}>.Instance.Parse{(ret ? null : "Into")}";
            break;

        case DictMode.KeyedValue:
            funcStr = $"{prefix}KeyedDictXmlTranslation<{dictType.KeyTypeGen.TypeName(getter: false)}, {dictType.ValueTypeGen.TypeName(getter: false)}>.Instance.Parse{(ret ? null : "Into")}";
            break;

        default:
            throw new NotImplementedException();
        }

        using (var args = sb.Call(funcStr))
        {
            args.AddPassArg($"{XmlTranslationModule.XElementLine.GetParameterName(objGen, Context.Backend)}");
            if (!ret)
            {
                args.Add($"item: {itemAccessor.Access}");
            }
            if (typeGen.HasIndex)
            {
                args.Add($"fieldIndex: (int){typeGen.IndexEnumName}");
                args.Add($"errorMask: {errorMaskAccessor}");
            }
            else
            {
                throw new NotImplementedException();
            }
            args.Add($"translationMask: {translationMaskAccessor}");
            switch (dictType.Mode)
            {
            case DictMode.KeyValue:
                if (!XmlMod.TryGetTypeGeneration(dictType.KeyTypeGen.GetType(), out var keySubTransl))
                {
                    throw new ArgumentException("Unsupported type generator: " + dictType.KeyTypeGen);
                }
                args.Add($"keyTransl: {keySubTransl.GetTranslatorInstance(dictType.KeyTypeGen, getter: false)}.Parse");
                args.Add($"valTransl: {valSubTransl.GetTranslatorInstance(dictType.ValueTypeGen, getter: false)}.Parse");
                break;

            case DictMode.KeyedValue:
                args.Add($"valTransl: {valSubTransl.GetTranslatorInstance(dictType.ValueTypeGen, getter: false)}.Parse");
                break;

            default:
                throw new ArgumentException();
            }
        }
    }
コード例 #9
0
    public override void GenerateWrite(
        StructuredStringBuilder sb,
        ObjectGeneration objGen,
        TypeGeneration typeGen,
        Accessor writerAccessor,
        Accessor itemAccessor,
        Accessor errorMaskAccessor,
        Accessor nameAccessor,
        Accessor translationMaskAccessor)
    {
        using (sb.CurlyBrace(doIt: !XmlMod.TranslationMaskParameter))
        {
            if (typeGen.Nullable)
            {
                sb.AppendLine($"if ({itemAccessor.Access} is {{}} {typeGen.Name}Item)");
                itemAccessor = $"{typeGen.Name}Item";
            }
            else
            {
                // We want to cache retrievals, in case it's a wrapper being written
                sb.AppendLine($"var {typeGen.Name}Item = {itemAccessor.Access};");
                itemAccessor = $"{typeGen.Name}Item";
            }

            using (sb.CurlyBrace(doIt: typeGen.Nullable))
            {
                var    loquiGen = typeGen as LoquiType;
                string line;
                if (loquiGen.TargetObjectGeneration != null)
                {
                    line = $"(({XmlMod.TranslationWriteClassName(loquiGen.TargetObjectGeneration)})(({nameof(IXmlItem)}){typeGen.Name}Item).{XmlMod.TranslationWriteItemMember})";
                }
                else
                {
                    line = $"(({XmlMod.TranslationWriteInterface})(({nameof(IXmlItem)}){typeGen.Name}Item).{XmlMod.TranslationWriteItemMember})";
                }
                using (var args = sb.Call($"{line}.Write{loquiGen.GetGenericTypes(getter: true, additionalMasks: new MaskType[] { MaskType.Normal })}"))
                {
                    args.Add($"item: {typeGen.Name}Item");
                    args.Add($"{XmlTranslationModule.XElementLine.GetParameterName(objGen, Context.Backend)}: {writerAccessor}");
                    args.Add($"name: {nameAccessor}");
                    if (typeGen.HasIndex)
                    {
                        args.Add($"fieldIndex: (int){typeGen.IndexEnumName}");
                    }
                    args.Add($"errorMask: {errorMaskAccessor}");
                    if (XmlMod.TranslationMaskParameter)
                    {
                        if (typeGen.HasIndex)
                        {
                            args.Add($"translationMask: {translationMaskAccessor}?.GetSubCrystal({typeGen.IndexEnumInt})");
                        }
                        else
                        {
                            args.Add($"translationMask: {translationMaskAccessor}");
                        }
                    }
                }
            }
        }
    }
コード例 #10
0
    public override void GenerateWrite(
        StructuredStringBuilder sb,
        ObjectGeneration objGen,
        TypeGeneration typeGen,
        Accessor writerAccessor,
        Accessor itemAccessor,
        Accessor errorMaskAccessor,
        Accessor nameAccessor,
        Accessor translationMaskAccessor)
    {
        var list = typeGen as ListType;

        if (!XmlMod.TryGetTypeGeneration(list.SubTypeGeneration.GetType(), out var subTransl))
        {
            throw new ArgumentException("Unsupported type generator: " + list.SubTypeGeneration);
        }

        var typeName = list.SubTypeGeneration.TypeName(getter: true, needsCovariance: true);

        if (list.SubTypeGeneration is LoquiType loqui)
        {
            typeName = loqui.TypeNameInternal(getter: true, internalInterface: true);
        }

        using (var args = sb.Call(
                   $"{TranslatorName}<{typeName}>.Instance.Write"))
        {
            args.Add($"{XmlTranslationModule.XElementLine.GetParameterName(objGen, Context.Backend)}: {writerAccessor}");
            args.Add($"name: {nameAccessor}");
            args.Add($"item: {GetWriteAccessor(itemAccessor)}");
            if (typeGen.HasIndex)
            {
                args.Add($"fieldIndex: (int){typeGen.IndexEnumName}");
            }
            else
            {
                throw new NotImplementedException();
            }
            args.Add($"errorMask: {errorMaskAccessor}");
            args.Add($"translationMask: {translationMaskAccessor}?.GetSubCrystal({typeGen.IndexEnumInt})");
            args.Add((gen) =>
            {
                var subTypeName = list.SubTypeGeneration.TypeName(getter: true, needsCovariance: true);
                if (list.SubTypeGeneration is LoquiType subLoqui)
                {
                    subTypeName = subLoqui.TypeNameInternal(getter: true, internalInterface: true);
                }
                gen.AppendLine($"transl: (XElement subNode, {subTypeName} subItem, ErrorMaskBuilder? listSubMask, {nameof(TranslationCrystal)}? listTranslMask) =>");
                using (new CurlyBrace(gen))
                {
                    subTransl.GenerateWrite(
                        sb: gen,
                        objGen: objGen,
                        typeGen: list.SubTypeGeneration,
                        writerAccessor: "subNode",
                        itemAccessor: new Accessor($"subItem"),
                        errorMaskAccessor: $"listSubMask",
                        translationMaskAccessor: "listTranslMask",
                        nameAccessor: "null");
                }
            });
            ExtraWriteArgs(itemAccessor, typeGen, args);
        }
    }