RusticiSoftware.TinCanAPILibrary.Model.StatementQueryObject.ToNameValueCollection C# (CSharp) Method

ToNameValueCollection() public method

Transforms the Query object into a NameValueCollection, which will be transformed into a query string.
public ToNameValueCollection ( TCAPIVersion version ) : NameValueCollection
version TCAPIVersion The TCAPI Version to serialize the statement as.
return System.Collections.Specialized.NameValueCollection
        public NameValueCollection ToNameValueCollection(TCAPIVersion version)
        {
            NameValueCollection nvc = new NameValueCollection();
            TinCanJsonConverter converter = new TinCanJsonConverter();

            if (!string.IsNullOrEmpty(verb))
                nvc["verb"] = verb.ToLower();
            if (targetObject != null)
                nvc["object"] = converter.SerializeToJSON(targetObject);
            if (!string.IsNullOrEmpty(registration))
                nvc["registration"] = registration;
            nvc["context"] = context.ToString();
            if (actor != null)
                switch( version)
                {
                    case TCAPIVersion.TinCan090:
                        nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)actor);
                        break;
                    default:
                        nvc["actor"] = converter.SerializeToJSON(actor);
                        break;
                }
            if (since != null)
                nvc["since"] = since.Value.ToString();
            if (until != null)
                nvc["until"] = until.Value.ToString();
            nvc["limit"] = limit.ToString();
            nvc["authoritative"] = authoritative.ToString();
            nvc["sparse"] = sparse.ToString();
            if (instructor != null)
                nvc["instructor"] = converter.SerializeToJSON(instructor);
            nvc["ascending"] = ascending.ToString();
            if (!string.IsNullOrEmpty(continueToken))
                nvc["continueToken"] = continueToken;
            nvc["historical"] = historical.ToString();

            return nvc;
        }

Usage Example

 private WebHeaderCollection GetWebHeaders()
 {
     WebHeaderCollection whc;
     StatementQueryObject qo = new StatementQueryObject();
     qo.Limit = 1;
     NameValueCollection nvc = qo.ToNameValueCollection(version);
     HttpMethods.GetRequest(nvc, endpoint + STATEMENTS, authentification, out whc, "0.95");
     return whc;
 }
All Usage Examples Of RusticiSoftware.TinCanAPILibrary.Model.StatementQueryObject::ToNameValueCollection