Example #1
0
        public void encode(AbstractSocketData sockeData)
        {
            if (sockeData == null)
            {
                return;
            }
            System.Type type = sockeData.GetType();
            if (!AttributeHelper.needEncoded(type))
            {
                return;
            }
            string assamble = sockeData.getAssamble();

            if (string.IsNullOrEmpty(assamble))
            {
                throw new System.Exception(type.ToString() + ".getAssamble() is not implemented.");
            }
            sockeData.Type = type.ToString() + "," + assamble;
            System.Reflection.FieldInfo[] fieldInfos    = ReflactUtil.getFieldInfos(type);
            System.Text.StringBuilder     stringBuilder = new System.Text.StringBuilder();
            System.Reflection.FieldInfo[] array         = fieldInfos;
            for (int i = 0; i < array.Length; i++)
            {
                System.Reflection.FieldInfo fieldInfo = array[i];
                if (AttributeHelper.needEncoded(fieldInfo))
                {
                    string name  = fieldInfo.Name;
                    object value = fieldInfo.GetValue(sockeData);
                    stringBuilder.Append(name + "{&}" + value).Append("{|}");
                }
            }
            this.dataBytes = System.Text.Encoding.UTF8.GetBytes(stringBuilder.ToString());
            if (this.dataBytes == null)
            {
                this.dataBytes = new byte[0];
            }
            this.dataLenth = this.dataBytes.Length;
        }
Example #2
0
 public static bool needEncoded(System.Type type)
 {
     object[] customAttributes = type.GetCustomAttributes(false);
     return(AttributeHelper.needEncoded(customAttributes));
 }
Example #3
0
 public static bool needEncoded(System.Reflection.FieldInfo fieldInfo)
 {
     object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(Encode), false);
     return(AttributeHelper.needEncoded(customAttributes));
 }