Beispiel #1
0
        Data ReadField(FieldSchema fieldSchema, Interpreter interpreter, ReadingContext parentContext)
        {
            var type         = parentContext.ReadType(fieldSchema.Type);
            var argument     = Expressions.GetArgument(fieldSchema, interpreter);
            var childContext = parentContext.Extend(fieldSchema, argument);

            if (!parentContext.Version.MatchesVersionConstraint(fieldSchema.MinVersion, fieldSchema.MaxVersion))
            {
                return(null);
            }
            if (!Expressions.CheckCondition(fieldSchema, interpreter))
            {
                return(null);
            }
            if (!Expressions.CheckVersionCondition(fieldSchema, parentContext.VersionInterpreter))
            {
                return(null);
            }
            if (!Inheritance.CheckIncludedInType(fieldSchema, parentContext.Parent))
            {
                return(null);
            }

            if (fieldSchema.IsMultiDimensional)
            {
                var count    = Expressions.GetCount(fieldSchema, interpreter);
                var elements = new List <Data>(count);
                for (int i = 0; i < count; i++)
                {
                    elements.Add(ReadData(type, childContext));
                }
                return(new ListData(elements));
            }
            return(ReadData(type, childContext));
        }
Beispiel #2
0
        NiObjectData ReadNiObject(NiObjectSchema niObject,
                                  ReadingContext parentContext)
        {
            var fields       = Inheritance.GetFields(niObject);
            var state        = Document.ParameterLookup.BuildNiObjectState(niObject);
            var interpreter  = new Interpreter(state);
            var childContext = parentContext.Extend(niObject);
            var niObjectData = new Dictionary <string, Data>();

            foreach (var fieldSchema in fields)
            {
                var fieldData = ReadField(fieldSchema, interpreter, childContext);
                if (fieldData == null)
                {
                    continue;
                }
                //state.Set(fieldSchema, Oldvalue.From(fieldData));
                niObjectData[fieldSchema.Name] = fieldData;
            }

            return(new NiObjectData()
            {
                Name = niObject.Name,
                Fields = niObjectData,
                Schema = niObject,
            });
        }