public DAIGuid GetDaiGuidFieldValue(DAIField field)
        {
            Debug.Assert(field.ValueType == DAIFieldType.DAI_Guid, "this method can only be applied to GUID fields");

            var  guid      = new DAIGuid();
            uint UIntValue = field.GetUIntValue();

            if ((UIntValue >> 31) == 1)
            {
                /* External Guid */
                DAIExternalGuid Guid = this.ExternalGuids.ElementAt((int)(UIntValue & 0x7fffffff));
                guid.external     = true;
                guid.fileGuid     = GuidToString(Guid.FileGuid);
                guid.instanceGuid = GuidToString(Guid.InstanceGuid);
            }
            else if (UIntValue == 0)
            {
                /* NULL Guid */
                guid.instanceGuid = "null";
            }
            else
            {
                /* Internal Guid */
                byte[] Guid = this.InternalGuids[(int)(UIntValue - 1)];
                guid.instanceGuid = GuidToString(Guid);
            }

            return(guid);
        }
Esempio n. 2
0
        private static AValue convert(DAIField field, ConverterContext ctx)
        {
            AValue result;

            if (field.ValueType == DAIFieldType.DAI_Complex)
            {
                var value = field.GetComplexValue();

                if (value == null)
                {
                    result = new ASimpleValue("{null}");
                }
                else
                {
                    var astruct = new AStruct();
                    astruct.name = value.GetName();

                    foreach (var childField in value.Fields)
                    {
                        AValue convertedChild = convert(childField, ctx);
                        var    childFieldName = childField.Descriptor.FieldName;
                        astruct.fields.Add(childFieldName, convertedChild);
                        astruct.correspondingDaiFields.Add(childFieldName, childField);
                    }

                    result = astruct;
                }
            }
            else if (field.ValueType == DAIFieldType.DAI_Array)
            {
                var value  = field.GetArrayValue();
                var aarray = new AArray();

                foreach (var memberField in value.Fields)
                {
                    AValue convertedMember = convert(memberField, ctx);
                    aarray.elements.Add(convertedMember);
                    aarray.correspondingDaiFields.Add(memberField);
                }

                result = aarray;
            }
            else if (field.ValueType == DAIFieldType.DAI_Guid)
            {
                var guid = ctx.file.GetDaiGuidFieldValue(field);

                if (guid.instanceGuid.Equals("null"))
                {
                    result = new ANullRef();
                }
                else
                {
                    if (guid.external)
                    {
                        var aexref = new AExRef(guid.fileGuid, guid.instanceGuid);
                        ctx.extRefs.Add(new Tuple <AExRef, string>(aexref, ctx.instanceGuid));
                        result = aexref;
                    }
                    else
                    {
                        var ainref = new AIntRef(guid.instanceGuid);
                        ctx.intReferences.Add(new Tuple <AIntRef, string>(ainref, ctx.instanceGuid));
                        result = ainref;
                    }
                }
            }
            else
            {
                String strValue;

                switch (field.ValueType)
                {
                case DAIFieldType.DAI_String:
                    strValue = field.GetStringValue();
                    break;

                case DAIFieldType.DAI_Enum:
                    strValue = field.GetEnumValue();
                    break;

                case DAIFieldType.DAI_Int:
                    strValue = field.GetIntValue().ToString();
                    break;

                case DAIFieldType.DAI_UInt:
                    strValue = field.GetUIntValue().ToString();
                    break;

                case DAIFieldType.DAI_Double:
                case DAIFieldType.DAI_Float:
                    strValue = field.GetFloatValue().ToString();
                    break;

                case DAIFieldType.DAI_Short:
                    strValue = field.GetShortValue().ToString();
                    break;

                case DAIFieldType.DAI_UShort:
                    strValue = field.GetUShortValue().ToString();
                    break;

                case DAIFieldType.DAI_Byte:
                case DAIFieldType.DAI_UByte:
                    strValue = field.GetByteValue().ToString();
                    break;

                case DAIFieldType.DAI_Long:
                    strValue = field.GetLongValue().ToString();
                    break;

                case DAIFieldType.DAI_LongLong:
                    strValue = "LL " + DAIEbx.GuidToString(field.GetLongLongValue());
                    break;

                case DAIFieldType.DAI_Bool:
                    strValue = field.GetBoolValue().ToString();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                result = new ASimpleValue(strValue, tryUnhash(strValue));
            }

            return(result);
        }