public static string PrettyPrint <TKey, TValue>(
     this IReadOnlyDictionary <TKey, TValue> dictionary,
     char separator     = EnumerableExtensions.PrettyPrintDefaultSeparator,
     uint minSeparation = EnumerableExtensions.PrettyPrintMinSeparation)
 {
     dictionary.ThrowIfNull(nameof(dictionary));
     return(dictionary.AsEnumerable().PrettyPrint(separator, minSeparation));
 }
Exemplo n.º 2
0
            public object GetValue(object target)
            {
                var embed     = _embed.AsEnumerable();
                var haveEmbed = target as IHaveHalJsonEmbedded;

                if (haveEmbed != null)
                {
                    embed = embed.Concat(haveEmbed.GetEmbedded());
                }
                return(embed.ToDictionary(x => x.Key, x => x.Value.Getter(target)));
            }
Exemplo n.º 3
0
            public object GetValue(object target)
            {
                var links     = _links.AsEnumerable();
                var haveLinks = target as IHaveHalJsonLinks;

                if (haveLinks != null)
                {
                    links = links.Concat(haveLinks.GetLinks());
                }

                return(links.ToDictionary(x => x.Key, x => (object)new JObject
                {
                    { "href", GetHRef(x.Value.GetHref(target)) },
                    { "templated", x.Value.Templated }
                }));
            }
        public void Register(IReadOnlyDictionary <GamePayloadOperationCode, Type> clientPayloadByOpCode, IReadOnlyDictionary <GamePayloadOperationCode, Type> serverPayloadByOpCode)
        {
            RuntimeTypeModel.Default.AutoCompile = false;

            RuntimeTypeModel.Default.Add(typeof(GameClientPacketPayload), true);
            RuntimeTypeModel.Default.Add(typeof(GameServerPacketPayload), true);

            clientPayloadByOpCode
            .AsEnumerable()
            .Concat(serverPayloadByOpCode)
            .ToList()
            .ForEach(pair =>
            {
                Console.Write($"Registering Type: {pair.Value} Key: {(int)pair.Key}");

                //TODO: Will this ever prevent a subtype registeration?
                RuntimeTypeModel.Default.Add(pair.Value, true);

                //TODO: Sometimes for unit testing this fails before the Protobuf model isn't reset. Figure a way to handle it. IfDefined breaks the Unity3D.
                RuntimeTypeModel.Default[pair.Value.BaseType]
                .AddSubType((int)pair.Key, pair.Value);
            });
        }
Exemplo n.º 5
0
 /// <summary>
 /// Get a form for a request (form-encoded, like a query string)
 /// </summary>
 /// <param name="payload">Payload</param>
 /// <param name="includeNonce">Whether to add the nonce</param>
 /// <param name="orderByKey">Whether to order by the key</param>
 /// <param name="formEncode">True to use form encoding, false to use url encoding</param>
 /// <returns>Form string</returns>
 public static string GetFormForPayload(this IReadOnlyDictionary <string, object> payload, bool includeNonce = true, bool orderByKey = true, bool formEncode = true)
 {
     if (payload != null && payload.Count != 0)
     {
         StringBuilder form = new StringBuilder();
         IEnumerable <KeyValuePair <string, object> > e = (orderByKey ? payload.OrderBy(kv => kv.Key) : payload.AsEnumerable <KeyValuePair <string, object> >());
         foreach (KeyValuePair <string, object> keyValue in e)
         {
             if (!string.IsNullOrWhiteSpace(keyValue.Key) && keyValue.Value != null && (includeNonce || keyValue.Key != "nonce"))
             {
                 string key   = (formEncode ? keyValue.Key.FormEncode() : keyValue.Key.UrlEncode());
                 string value = (formEncode ? keyValue.Value.ToStringInvariant().FormEncode() : keyValue.Value.ToStringInvariant().UrlEncode());
                 form.Append($"{key}={value}&");
             }
         }
         if (form.Length != 0)
         {
             form.Length--; // trim ampersand
         }
         return(form.ToString());
     }
     return(string.Empty);
 }