Example #1
0
 public override CodeNode VisitSkipType(SkipTypeNode node)
 {
     _Writer.WriteStartElement("SkipType");
     _Writer.WriteAttributeString("LengthIndex", node.LengthIndex.ToString());
     _Writer.WriteAttributeString("IsNibble", node.IsNibble.ToString());
     _Writer.WriteAttributeString("Type", node.Type.ToString());
     _Writer.WriteEndElement();
     return(node);
 }
        public override CodeNode VisitSkipType(SkipTypeNode node)
        {
            MethodInfo skipTypeMethod;
            var        argsArray = node.Type.IsArray ? new[] { typeof(int) } : new Type[0];

            if (node.IsNibble)
            {
                skipTypeMethod = typeof(BinaryReader).GetMethod("SkipNibbleArray", argsArray);
            }
            else if (!_SkipTypeMethods.TryGetValue(node.Type, out skipTypeMethod))
            {
                string skipTypeMethodName;
                if (node.Type == typeof(byte))
                {
                    skipTypeMethodName = "Skip1";
                }
                else if (node.Type == typeof(byte[]))
                {
                    skipTypeMethodName = "Skip1Array";
                }
                else if (node.Type == typeof(sbyte))
                {
                    skipTypeMethodName = "Skip1";
                }
                else if (node.Type == typeof(sbyte[]))
                {
                    skipTypeMethodName = "Skip1Array";
                }
                else if (node.Type == typeof(ushort))
                {
                    skipTypeMethodName = "Skip2";
                }
                else if (node.Type == typeof(ushort[]))
                {
                    skipTypeMethodName = "Skip2Array";
                }
                else if (node.Type == typeof(short))
                {
                    skipTypeMethodName = "Skip2";
                }
                else if (node.Type == typeof(short[]))
                {
                    skipTypeMethodName = "Skip2Array";
                }
                else if (node.Type == typeof(uint))
                {
                    skipTypeMethodName = "Skip4";
                }
                else if (node.Type == typeof(uint[]))
                {
                    skipTypeMethodName = "Skip4Array";
                }
                else if (node.Type == typeof(int))
                {
                    skipTypeMethodName = "Skip4";
                }
                else if (node.Type == typeof(int[]))
                {
                    skipTypeMethodName = "Skip4Array";
                }
                else if (node.Type == typeof(ulong))
                {
                    skipTypeMethodName = "Skip8";
                }
                else if (node.Type == typeof(ulong[]))
                {
                    skipTypeMethodName = "Skip8Array";
                }
                else if (node.Type == typeof(long))
                {
                    skipTypeMethodName = "Skip8";
                }
                else if (node.Type == typeof(long[]))
                {
                    skipTypeMethodName = "Skip8Array";
                }
                else if (node.Type == typeof(float))
                {
                    skipTypeMethodName = "Skip4";
                }
                else if (node.Type == typeof(float[]))
                {
                    skipTypeMethodName = "Skip4Array";
                }
                else if (node.Type == typeof(double))
                {
                    skipTypeMethodName = "Skip8";
                }
                else if (node.Type == typeof(double[]))
                {
                    skipTypeMethodName = "Skip8Array";
                }
                else if (node.Type == typeof(string))
                {
                    skipTypeMethodName = "SkipString";
                }
                else if (node.Type == typeof(string[]))
                {
                    skipTypeMethodName = "SkipStringArray";
                }
                else if (node.Type == typeof(DateTime))
                {
                    skipTypeMethodName = "Skip4";
                }
                else if (node.Type == typeof(BitArray))
                {
                    skipTypeMethodName = "SkipBitArray";
                }
                else
                {
                    throw new NotSupportedException(string.Format(Resources.UnsupportedReaderType, node.Type));
                }
                skipTypeMethod = typeof(BinaryReader).GetMethod(skipTypeMethodName, argsArray);
                _SkipTypeMethods[node.Type] = skipTypeMethod;
            }
            Log($"Skipping with {skipTypeMethod}.");

            ILGen.Ldloc(_Reader);
            //if we have a length index, load its local (we enforce its presence for arrays in the node)
            if (node.LengthIndex.HasValue)
            {
                ILGen.Ldloc(_FieldLocals[node.LengthIndex.Value]);
            }
            ILGen.Callvirt(skipTypeMethod);
            return(node);
        }
Example #3
0
 public virtual CodeNode VisitSkipType(SkipTypeNode node)
 {
     return(node);
 }