Netty Camel样品(Netty Camel samples)
我是Netty的新手。
我正在寻找一些样品。 (优选但不是必须使用Camel Netty Component和Spring)
特别是一个使用TCP消息的示例Netty应用程序。
另外,我如何编写可以测试这个netty应用程序的JUnit测试?
谢谢,Dar
I'm a newbie to Netty.
I'm looking for some samples. (Preferably but not necessarity using Camel Netty Component and Spring)
Specifically a sample Netty app that consumes TCP messages.
Also how can I write a JUnit test that can test this netty app?
Thanks, Dar
原文:https://stackoverflow.com/questions/8419245
满意答案
这里有足够的例子来使用表达式来获取一个属性或字段的名称来启动它:
public static MemberInfo GetMemberInfo<T, U>(Expression<Func<T, U>> expression) { var member = expression.Body as MemberExpression; if (member != null) return member.Member; throw new ArgumentException("Expression is not a member access", "expression"); }
调用代码如下所示:
public class Program { public string Name { get { return "My Program"; } } static void Main() { MemberInfo member = ReflectionUtility.GetMemberInfo((Program p) => p.Name); Console.WriteLine(member.Name); } }
尽管如此:
(Program p) => p.Name
的简单(Program p) => p.Name
实际上涉及相当多的工作(并且可能花费大量时间)。 考虑缓存结果,而不是经常调用该方法。Here's enough of an example of using Expressions to get the name of a property or field to get you started:
public static MemberInfo GetMemberInfo<T, U>(Expression<Func<T, U>> expression) { var member = expression.Body as MemberExpression; if (member != null) return member.Member; throw new ArgumentException("Expression is not a member access", "expression"); }
Calling code would look like this:
public class Program { public string Name { get { return "My Program"; } } static void Main() { MemberInfo member = ReflectionUtility.GetMemberInfo((Program p) => p.Name); Console.WriteLine(member.Name); } }
A word of caution, though: the simple statment of
(Program p) => p.Name
actually involves quite a bit of work (and can take measurable amounts of time). Consider caching the result rather than calling the method frequently.
相关问答
更多使用lambda表达式获取属性名称和类型(Get property name and type using lambda expression)
动态lambda表达式(OrderBy)和可空属性类型(Dynamic lambda expression (OrderBy) and nullable property type)
lambda表达式作为属性(lambda Expression as a property)
从属性名称获取属性lambda(其中属性类型可以为空)(get property lambda from property Name (Where property type can be nullable))
使用lambda表达式获取属性或类型名称(Using lambda expression to get property OR type name)
从类型lambda表达式中获取所有属性表达式(Get all property expressions from a type lambda expressions)
使用该lambda中包含的匿名类型定义lambda表达式(Defining a lambda expression with an anonymous type contained within that lambda)
使用内部委托类型编译lambda表达式(Compile lambda expression with internal delegate type)
如何使用lambda表达式和匿名类型获取类型的属性名称?(How do I get property names of a type using a lambda expression and anonymous type?)
lambda表达式的扩展方法(Extension method on lambda expression)
相关文章
更多[Netty 1] 初识Netty
Netty环境配置
Netty开发环境配置
Netty源码分析
storm学习之Netty代替ZMQ
Netty基于流的传输处理
Netty入门实例-时间服务器
Netty入门实例-使用POJO代替ByteBuf
在Twitter,Netty 4 GC开销降为五分之一
Netty入门实例-编写服务器端程序
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!