Example #1
0
        public Statement(JToken statement, ApiVersion version) : base(statement, version)
        {
            GuardType(statement, JTokenType.Object);

            var id = statement["id"];

            if (id != null)
            {
                Id = ParseGuid(id);
            }

            var @object = statement["object"];

            if (@object != null)
            {
                GuardType(@object, JTokenType.Object);

                var jobjectType = @object["objectType"];
                if (jobjectType != null)
                {
                    ObjectType type = ParseObjectType(jobjectType, ObjectType.Activity, ObjectType.Agent, ObjectType.Group, ObjectType.Activity, ObjectType.StatementRef, ObjectType.SubStatement);
                    Object = type.CreateInstance(@object, version);
                }
                else if (@object["id"] != null)
                {
                    // Assume activity
                    Object = new Activity(@object, version);
                }
            }

            var stored = statement["stored"];

            if (stored != null)
            {
                Stored = ParseDateTimeOffset(stored);
            }

            var authority = statement["authority"];

            if (authority != null)
            {
                GuardType(authority, JTokenType.Object);

                var objectType = authority["objectType"];
                if (objectType != null)
                {
                    ObjectType type = ParseObjectType(objectType, ObjectType.Agent, ObjectType.Group);
                    Authority = (Agent)type.CreateInstance(authority, version);
                }
                else
                {
                    Authority = new Agent(authority, version);
                }
            }

            var ver = statement["version"];

            if (ver != null)
            {
                GuardType(ver, JTokenType.String);
                Version = new ApiVersion(ver.Value <string>());
            }

            GuardAdditionalProperties((JObject)statement, "id", "stored", "authority", "version", "object", "actor", "verb", "result", "context", "timestamp", "attachments");
        }