public static FixedSizeList <T> Create(Pointer pointer, IList <T> items)
        {
            var accessor = TypeAccessor <T> .Instance;

            if (accessor.IsStruct)
            {
                throw new InvalidOperationException("Lists of structs cannot be created retrospectively, since the list *is* the data");
            }

            if (items == null)
            {
                return(default(FixedSizeList <T>));
            }
            if (items.Count == 0)
            {
                return(FixedSizeList <T> .Create(pointer, 0));
            }

            FixedSizeList <T> list = accessor.CreateList(pointer, items.Count);

            for (int i = 0; i < items.Count; i++)
            {
                list[i] = items[i];
            }
            return(list);
        }
Beispiel #2
0
 public CodeWriter(TextWriter destination, FixedSizeList <Schema.Node> nodes, string @namespace, string serializer)
 {
     this.destination = destination;
     this.@namespace  = @namespace;
     this.serializer  = serializer;
     foreach (var node in nodes)
     {
         if (node.id != 0)
         {
             map[node.id] = node;
         }
     }
 }
Beispiel #3
0
        public CodeWriter(TextWriter destination, FixedSizeList <Schema.Node> nodes, string @namespace, string serializer)
        {
            this.destination = destination;
            this.@namespace  = @namespace;
            this.serializer  = serializer;
            ulong fileNodeId = 0;
            ulong nsNodeId   = 0;

            foreach (var node in nodes)
            {
                if (node.id != 0)
                {
                    map[node.id] = node;
                }
                if (fileNodeId == 0 && node.Union == Node.Unions.file)
                {
                    fileNodeId = node.id;
                }
                if (nsNodeId == 0 && node.Union == Node.Unions.annotation && node.annotation.targetsFile && node.annotation.type.Union == Schema.Type.Unions.text)
                {
                    string name = node.displayName.ToString();
                    string anno = name.Substring((int)node.displayNamePrefixLength);
                    if (name.Contains("csharp") && anno == "namespace")
                    {
                        nsNodeId = node.id;
                    }
                }
            }
            if (nsNodeId != 0 && fileNodeId != 0)
            {
                Node fileNode = map[fileNodeId];
                foreach (var anno in fileNode.annotations)
                {
                    if (anno.id == nsNodeId)
                    {
                        string ns = anno.value.text.ToString();
                        if (ns.Length > 0)
                        {
                            //this.@namespace = ns;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public static FixedSizeList <T> Create(Pointer pointer, IList <T> items)
        {
            if (items == null)
            {
                return(default(FixedSizeList <T>));
            }
            if (items.Count == 0)
            {
                return(FixedSizeList <T> .Create(pointer, 0));
            }

            var accessor           = StructAccessor <T> .Instance;
            FixedSizeList <T> list = accessor.IsPointer
                ? accessor.CreateList(pointer, items.Count, ElementSize.EightBytesPointer)
                : accessor.CreateList(pointer, items.Count);

            for (int i = 0; i < items.Count; i++)
            {
                list[i] = items[i];
            }
            return(list);
        }
Beispiel #5
0
 public CSharpStructWriter(TextWriter destination, FixedSizeList <Schema.Node> nodes,
                           string @namespace)
     : base(destination, nodes, @namespace, "not used")
 {
 }
 public override void SetElement(Pointer pointer, int index, FixedSizeList <TInner> value)
 {
     pointer.SetListPointer(index, value);
 }
Beispiel #7
0
 public FixedSizeList <T> AllocateList <T>(IList <T> items)
 {
     return(FixedSizeList <T> .Create(this.Root, items));
 }