小编uni*_*uni的帖子

XmlSerializer不会序列化IEnumerable

我有一个调用记录器,用于记录所有方法调用以及与使用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作为其参数之一?

c# xml-serialization xmlserializer

38
推荐指数
3
解决办法
3万
查看次数

无法访问App_Code中的Razor @helper

在我的App_code,我有一个叫做辅助函数FormatTelephone(string number)Formatter.cshtml.我尝试在局部视图中访问它@Formatter.FormatTelephone(number).当我测试它时,它说

编译器错误消息:CS0103:当前上下文中不存在名称"Formatter"

可能的原因是什么?谢谢!

c# partial-views view-helpers razor asp.net-mvc-3

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

如何获取Queryable.Join的MethodInfo

这可能听起来愚蠢的,但我不能得到MethodInfoQueryable.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从外部传递的(这就是我需要这种反射的原因).

谁能告诉我怎么样?谢谢!

c# generics reflection iqueryable

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

如何在泛型方法调用中使用Type变量(C#)

我有一个t传递给方法的Type变量,我想在调用时将其用作通用参数IQueryable.Join,如下所示

queryResult.Join<Type1, Type2, t, Type3>( items, outerSelector, innerSelector, ( a, b) => a);
Run Code Online (Sandbox Code Playgroud)

它显然不起作用.t为了达到我的目的,我该怎么做?谢谢!

c# generics

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