Exemple #1
0
        private static DateTime ReadDateTime(BinaryParser parser, FieldInfo field)
        {
            var attr = BinaryParser.GetAttribute <BinaryFieldAttribute>(field);

            if (attr != null)
            {
                if (attr.FieldType == BinaryFieldType.UnixTime)
                {
                    return(UnixTime.ToDateTime(parser.ReadUInt32()));
                }
            }

            PscxArgumentException.Throw("Don't know how to parse DateTime field " + field.ToString());
            return(DateTime.MinValue);
        }
Exemple #2
0
        private static Object ReadVersion(BinaryParser parser, FieldInfo field)
        {
            var attr = BinaryParser.GetAttribute <VersionFieldAttribute>(field);

            if (attr != null)
            {
                var args = new Object[attr.ComponentCount];

                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = ReadIntegral(parser, attr.ComponentType);
                }

                return(Activator.CreateInstance(typeof(Version), args));
            }

            PscxArgumentException.Throw(field.Name, "Don't know how to parse field " + field.ToString());
            return(null);
        }
Exemple #3
0
        private static String ReadString(BinaryParser parser, FieldInfo field)
        {
            var attr = BinaryParser.GetAttribute <BinaryFieldAttribute>(field);

            if (attr != null)
            {
                if (attr.FieldType == BinaryFieldType.StringAsciiZ)
                {
                    if (attr.FixedLength > 0)
                    {
                        return(parser.ReadStringAsciiZ());
                    }

                    return(parser.ReadStringAsciiZ());
                }
            }

            PscxArgumentException.Throw(field.Name, "Don't know how to parse field " + field.ToString());
            return(null);
        }
Exemple #4
0
        private string GetGenericTypeScriptDefinition(string typeName, int typeArgsCount, ref Type closedType)
        {
            // TODO: account for generic type arrays, e.g. collection<string>[]
            string openTypeName = String.Format("{0}`{1}", typeName, typeArgsCount);

            Type genericType = null;

            if (!LanguagePrimitives.TryConvertTo <Type>(openTypeName, out genericType))
            {
                PscxArgumentException.Throw("Generic Type {0} not found.", openTypeName);
            }

            string closedTypeName = CreateClosedTypeName(openTypeName);

            if (!LanguagePrimitives.TryConvertTo <Type>(closedTypeName, out closedType))
            {
                PscxArgumentException.Throw("Could not construct Closed Type using the provided arguments.");
            }

            WriteDebug("AssemblyQualifiedName: " + closedType.AssemblyQualifiedName);
            WriteVerbose("TypeName: " + closedTypeName);

            return(closedTypeName);
        }