Beispiel #1
0
        public static object InstantiateArray(PfArray pfary, Type context_type = null)
        {
            var el_type = pfary.ArrayType.Resolve(context_type);
            var ary     = Array.CreateInstance(el_type, pfary.Entries.Length);

            for (int i = 0; i < pfary.Entries.Length; i++)
            {
                var ent = pfary.Entries[i];
                ary.SetValue(ConvertType(ent, el_type, context_type: el_type), i);
            }
            return(ary);
        }
Beispiel #2
0
        public object TryMakeObject()
        {
            var a = ArrayType != null;
            var b = CollectionType != null;
            var c = ObjectType != null;
            var d = InsertID != null;

            if (a && b || a && c || a && d || b && c || b && d || c && d)
            {
                throw new InvalidOperationException("Inconsistent object type");
            }

            object obj = null;

            if (ArrayType != null)
            {
                obj = new PfArray(ArrayType, ArrayEntries);
            }
            else if (CollectionType != null)
            {
                obj = new PfCollection(CollectionType, CollectionElements);
            }
            else if (ObjectType != null)
            {
                obj = new PfObject(ObjectType, Data);
            }
            else if (InsertID != null)
            {
                obj = new PfInsert(InsertID, Data);
            }

            if (obj == null)
            {
                throw new InvalidOperationException("Unknown object type");
            }

            return(obj);
        }