public static Cmd parse_cmd(byte[] buffer, long start_index, long length) { if (start_index + length > buffer.Count()) { throw new Exception("命令长度不足."); } long pos = start_index; CmdType type = (CmdType)Cmd.to_int(buffer, ref pos); string type_name = type.ToString(); type_name = string.Join("", type_name.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries)); Type class_type = Type.GetType(type.GetType().Namespace + "." + type_name); Cmd cmd = Activator.CreateInstance(class_type) as Cmd; cmd.from_byte(buffer, ref start_index); return(cmd); }