Пример #1
0
        // --------------- public Interface -------------------

        public static T NLSend <T> (this T arg, string prefix = "")
        {
            // can't get runtime type of null
            if (arg == null)
            {
                send_string("$null$", prefix, default_dst_name, default_dst); return(arg);
            }                                                                                                           // TODO: check out how this interferes with unitys null check overloading stuff

            // control flow of non degenerate cases
            Type      typ     = arg.GetType();
            var       ser_att = (NLSendSerializationAttribute)Attribute.GetCustomAttribute(typ, typeof(NLSendSerializationAttribute));
            NLSerMode mode    = (ser_att == null) ?  NLSerMode.toString  : ser_att.mode;

            var dst_att = (NLSendDestinationAttribute)Attribute.GetCustomAttribute(typ, typeof(NLSendDestinationAttribute));

            string dst_name          = default_dst_name;
            DST    attr_fallback_dst = default_dst;

            if (dst_att != null)
            {
                attr_fallback_dst = new DST {
                    ip = dst_att.dst_ip, port = dst_att.dst_port
                };
                dst_name = dst_att.dst_name;
            }

            if (mode == NLSerMode.toString)
            {
                send_string(arg.ToString(), prefix, dst_name, attr_fallback_dst);
            }
            if (mode == NLSerMode.json)
            {
                send_json(arg, prefix, dst_name, attr_fallback_dst);
            }
            if (mode == NLSerMode.csv)
            {
                throw new Exception("not implemented");
            }


            return(arg);
        }
Пример #2
0
 public NLSendSerializationAttribute(NLSerMode mode)
 {
     this.mode = mode;
 }