小编Pac*_*ane的帖子

转换为List <T>以返回功能

所以我试图创建一个返回数据列表的函数,数据有很多"子"类,其中一个是注释但是,如果日期的类型是注释(我用IF语句测试)那么我想orderby编辑日期而不是id(ID在所有数据对象上都可用,而编辑日期仅在评论类中可用).所以,而不是做TypeOf我做TypeOf然后我能够在编辑日期订购它然而,它想要返回一个List然后我需要它作为一个List,但是我已经google了一个小时+没有运气找到关于如何转换它.这是方法:

private List<T> GetAllData<T>() where T : Data, new()
    {
        List<T> TmpList = new List<T>();
        if (typeof(T) == typeof(Comment))
        {
            TmpList = _newdb.Data.OfType<Comment>().OrderBy(x => x.EditDate).ToList();
            // THIS ABOVE doesn t work ofc since it wants to return a List<Comment> but TmpList is a List<T>

            //List<Comment> TmpComments = _newdb.Data.OfType<Comment>().OrderBy(x => x.EditDate).ToList();
            // List<T> tempzor = new List<T>(TmpComments.ToList());
            //TmpList = (List<T>(TmpComments));
            // TmpList = TmpComments.ConvertAll;
        }
        else
        {
            TmpList = _newdb.Data.OfType<T>().OrderBy(x => (x.Id)).ToList();
        }
        return TmpList;
    }
Run Code Online (Sandbox Code Playgroud)

提前致谢!

c# inheritance function list

1
推荐指数
1
解决办法
305
查看次数

form_for混合id和locale参数

我正在努力让Globalize3在我的应用上工作.我有博客文章的玩具项目,我想翻译.

我的网址看起来像这样: localhost/en/posts localhost/fr/posts

这就是我在我的工作中的表现 ApplicationController

before_action :set_locale

def set_locale
  I18n.locale = params[:locale] if params[:locale] || I18n.default_locale
end
Run Code Online (Sandbox Code Playgroud)

我用它form_for来创建和更新帖子.这是视图代码:

<%= form_for(@post) do |f| %>
...
<% end %>
Run Code Online (Sandbox Code Playgroud)

它在我进入/new页面时工作正常,这是控制器代码:

def new                                    
  @post = Post.new                         
end   

def create                                 
  @post = Post.new(post_params)            

  if @post.save                            
    redirect_to action: :show, id: @post.id
  else                                     
    render 'new'                           
  end                                      
end    
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用url编辑帖子时/en/posts/1/edit,它会混合传递给的文件form_for.这是错误信息:

没有路由匹配{:action =>"show",:controller =>"posts",:locale =>#,:id => nil,:format => nil}缺少必需的键:[:locale,:id]

我的问题是:它为什么这样做,我该如何修复thix?


我已经尝试过一些事情,例如将form_for声明更改为:

<%= form_for(@post, url: {action: 'show', id: @post, …

ruby ruby-on-rails form-for globalize3

1
推荐指数
1
解决办法
2193
查看次数

如何使用StreamChannel在Dart中进行双向通信?

有没有办法让Dart Streams await stream.first连续多次执行某些操作 ,使用有点像堆栈/队列的流?

据我所知,你可以通过在现有的Single-substription流上使用asBroadcastStream来做到这一点,但我觉得这并不理想.

也许有一种缓冲原语与一些Rx包或类似的东西?

我的用例如下:

我有一个StreamChannel(IOWebSocketChannel),我想按特定顺序发送/接收消息.

即:

Send Message0
Receive Message1
Send Message2
Receive Message3
Run Code Online (Sandbox Code Playgroud)

我肯定知道Message1服务器收到后才会到达Message0 (等的Message2Message3)

stream dart

0
推荐指数
1
解决办法
121
查看次数

TeamCity在幕后使用Jenkins吗?

我的同事告诉我,TeamCity只是Jenkins有一个不同的前端(就像Teamcity使用Jenkins一样......).

真的吗?我无法在网上找到这些信息.

teamcity jenkins

-5
推荐指数
1
解决办法
697
查看次数