我有一个调用记录器,用于记录所有方法调用以及与使用XmlSerializer的方法相关的参数.它适用于大多数调用,但它会为具有IEnumerable
类型参数的所有方法抛出异常.
例如,void MethodWithPlace( Place value )
将序列化,但void MethodWithPlace( IEnumerable<Place> value )
不会.
例外是
System.NotSupportedException:无法序列化接口System.Collections.Generic.IEnumerable`1 [[Place,Test,Version = 0.0.0.0,Culture = neutral]].
我应该怎么做才能使用这些方法IEnumerable
作为其参数之一?
在我的App_code
,我有一个叫做辅助函数FormatTelephone(string number)
在Formatter.cshtml
.我尝试在局部视图中访问它@Formatter.FormatTelephone(number)
.当我测试它时,它说
编译器错误消息:CS0103:当前上下文中不存在名称"Formatter"
可能的原因是什么?谢谢!
这可能听起来愚蠢的,但我不能得到MethodInfo
的Queryable.Join(...)
.我想得到它,因为如何在泛型方法调用中使用Type变量(C#)
它有2个可用的方法签名和我想没有的IEqualityComparer的一个,所以我需要指定Type[]
在GetMethod
.
我写了类似的东西
MethodInfo joinMethod = typeof( Queryable ).GetMethod( "Join", new Type[] { typeof(IEnumerable<>), typeof(Expression<Func<>>), typeof(Expression<Func<>>), typeof(Expression<Func<>>)});
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我无法在上面指定泛型中的类型,因为它们是Type
从外部传递的(这就是我需要这种反射的原因).
谁能告诉我怎么样?谢谢!
我有一个t
传递给方法的Type变量,我想在调用时将其用作通用参数IQueryable.Join
,如下所示
queryResult.Join<Type1, Type2, t, Type3>( items, outerSelector, innerSelector, ( a, b) => a);
Run Code Online (Sandbox Code Playgroud)
它显然不起作用.t
为了达到我的目的,我该怎么做?谢谢!