Ejemplo n.º 1
0
 private void WriteUnionHeader(IndentedTextWriter writer, ClassDefinition c, string name)
 {
     writer.WriteLine($"public sealed class {name} : Workstation.ServiceModel.Ua.Union");
 }
Ejemplo n.º 2
0
        public bool ParentHasOptionalProperties(ClassDefinition c)
        {
            var p = Definitions.OfType <ClassDefinition>().FirstOrDefault(d => d.DataTypeId == c.ParentDataTypeId);

            return(p != null && (p.OptionalPropertyCount != 0 || ParentHasOptionalProperties(p)));
        }
Ejemplo n.º 3
0
        private void WriteDecodeMethod(IndentedTextWriter writer, ClassDefinition c, bool isDerived, bool parentIsStructure, bool parentHasOptionalFields)
        {
            var hasOptionalFields = c.OptionalPropertyCount != 0;
            var modifier          = isDerived ? "override" : "virtual";

            WriteInheritDoc(writer);
            writer.WriteLine($"public {modifier} void Decode(Workstation.ServiceModel.Ua.IDecoder decoder)");
            writer.Begin("{");
            if (hasOptionalFields && parentHasOptionalFields)
            {
                writer.WriteLine("int offset = base.OptionalFieldCount;");
                writer.WriteLine();
            }
            if (isDerived && !parentIsStructure)
            {
                writer.WriteLine("base.Decode(decoder);");
            }

            writer.WriteLine($"decoder.PushNamespace({ToStringLiteral(c.Namespace)});");
            writer.WriteLine();
            if (hasOptionalFields)
            {
                if (!parentHasOptionalFields)
                {
                    writer.WriteLine("var encodingMask = decoder.ReadUInt32(null);");
                    writer.WriteLine("EncodingMask = encodingMask;");
                }
                else
                {
                    writer.WriteLine("var encodingMask = EncodingMask;");
                }
                writer.WriteLine();
            }

            var index = 0;

            foreach (var p in c.Properties)
            {
                var netType = _typeSet.GetNetType(p.DataTypeId);
                var suffix  = RenderMethodSuffix(netType, p.Rank);
                var type    = RenderType(p, isOptional: true);

                if (p.IsOptional)
                {
                    if (parentHasOptionalFields)
                    {
                        writer.WriteLine($"{p.SymbolicName} = (encodingMask & (1u << ({index} + offset))) != 0");
                    }
                    else
                    {
                        writer.WriteLine($"{p.SymbolicName} = (encodingMask & (1u << {index})) != 0");
                    }
                    writer.Indent++;
                    writer.WriteLine($"? decoder.Read{suffix}({ToStringLiteral(p.OpcUaName)})");
                    writer.WriteLine($": default({type});");
                    writer.Indent--;
                    index++;
                }
                else
                {
                    writer.WriteLine($"{p.SymbolicName} = decoder.Read{suffix}({ToStringLiteral(p.OpcUaName)});");
                }
            }
            writer.WriteLine();
            writer.WriteLine("decoder.PopNamespace();");
            writer.End("}");
        }