无法反序列化以下对象图.在BinaryFormmater上调用deserialize方法时发生异常:System.Runtime.Serialization.SerializationException:
The constructor to deserialize an object of type 'C' was not found.
Run Code Online (Sandbox Code Playgroud)
C上有两个构造函数,我认为问题可能是:序列化Binaryformatter使用参数化和反序列化过程,它需要一个无参数化的.有黑客/解决方案吗?对象:
[Serializable]
public class A
{
B b;
C c;
public int ID { get; set; }
public A()
{
}
public A(B b)
{
this.b = b;
}
public A(C c)
{
this.c = c;
}
}
[Serializable]
public class B
{
}
[Serializable]
public class C : Dictionary<int, A>
{
public C()
{
}
public C(List<A> list)
{
list.ForEach(p => this.Add(p.ID, p));
}
}
Run Code Online (Sandbox Code Playgroud)
//序列化成功 …
我正在使用Nhibernate 3.1/FluentNhibernate 1.2
当我使用CTRL + F5在发布模式下工作时,我没有任何异常.但在调试模式下,F5发生以下异常:
控制台应用程序,用于此代码:
_Session.Query<Foo> ().Where (x=>x.Bar == "bar").FirstOrDefault()
Run Code Online (Sandbox Code Playgroud)
例外:
System.TypeInitializationException was unhandled
Message=The type initializer for 'NHibernate.Linq.NhRelinqQueryParser' threw an exception.
Source=NHibernate
TypeName=NHibernate.Linq.NhRelinqQueryParser
StackTrace:
at NHibernate.Linq.NhRelinqQueryParser.Parse(Expression expression)
at NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor sessionFactory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhLinqExpression.cs:line 65
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs:line 27
at NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line 34
at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor …Run Code Online (Sandbox Code Playgroud) 我正在尝试按时间戳分组名为"foo"的集合{_id,TimeStamp}
db.foos.aggregate(
[
{$group : { _id : new Date (Date.UTC({ $year : '$TimeStamp' },{ $month : '$TimeStamp' },{$dayOfMonth : '$TimeStamp'})) }}
])
Run Code Online (Sandbox Code Playgroud)
期待许多日期,但结果只是一个日期.我正在使用的数据是正确的(除了1970年以外有很多foo和不同的日期).解析日期有一些问题,但我还无法解决.
{
"result" : [
{
"_id" : ISODate("1970-01-01T00:00:00.000Z")
}
],
"ok" : 1
}
Run Code Online (Sandbox Code Playgroud)
试过这一个:
db.foos.aggregate(
[
{$group : { _id : { year : { $year : '$TimeStamp' }, month : { $month : '$TimeStamp' }, day : {$dayOfMonth : '$TimeStamp'} }, count : { $sum : 1 } }},
{$project : { parsedDate : …Run Code Online (Sandbox Code Playgroud) Cannot convert type 'System.Func<int,bool>' to 'System.Func<object,bool>'
Run Code Online (Sandbox Code Playgroud)
试图将f2强制转换为f1:
Func<object, bool> f1 = x => true;
Func<int, bool> f2 = x => true;
f1 = (Func<object, bool>)f2;
Run Code Online (Sandbox Code Playgroud)
尝试解决地图功能但是,这次我得到了
Argument 1: cannot convert from 'C' to 'A'
Run Code Online (Sandbox Code Playgroud)
例外.关于转型(a)的功能
Func<int, bool> f3 = Map(f2, x => x);
Func<C, B> Map<A, B, C>(Func<A, B> input, Func<A, C> transform)
{
return x => input(transform(x));
// return x => input(transform((A)x)); not working
}
Run Code Online (Sandbox Code Playgroud)
有解决方案吗?
static class EntranceClass {
public:
static void RegisterSomething()
{
}
static int main()
{
RegisterSomething();
return 0;
}
} // <-expected unqualified-id at end
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:输入main.cpp结束时预期的nonqualified-id问题
有什么解决方案吗?
class A {}
A a;
type_info info = typeid (a); // error type_info is private
Run Code Online (Sandbox Code Playgroud)
我想要一个列表list<type_info>来存储类的类型.有解决方案吗?
我想通过这个例子会更清楚。我们希望在处理器类中看到两个具有不同参数的方法。“ int处理(int值);” “双重处理(双重价值);”
但是编译器对IRoot说:'Generics.IRoot'不能同时实现'Generics.IProcess'和'Generics.IProcess',因为它们可能会为某些类型参数替换统一。
public class Processor : IRoot<int, double, int, double>
{
// Here we want 2 methods
public int Process(int item) { }
public double Process(double item) { }
}
public interface IProcess<TResult, TItem>
{
TResult Process(TItem item);
}
public interface IRoot<TR1, TR2, TItem1, TItem2> :
IProcess<TR1, TItem1>,
IProcess<TR2, TItem2>
{
}
Run Code Online (Sandbox Code Playgroud) topshelf中有没有办法在一个可执行文件中运行多个主机?
// Create hosts
var h1 = HostFactory.New (...); var h2 = HostFactory.New (...)
// Start hosts
in one application Runner.Run (h1, h2);
Run Code Online (Sandbox Code Playgroud)
解决了线程.但不确定它是否安全......
new Thread (()=>Runner.Run (h1));
new Thread (()=>Runner.Run (h2));
Run Code Online (Sandbox Code Playgroud) class Foo
{
public List<Baz> bazs = new List<Baz> ();
}
class Baz
{
public List<int> ints = new List<int> ();
}
[Test] public void play ()
{
var foo = new Foo ();
foo.bazs = new List<Baz> ()
{
new Baz ()
{
ints = new List<int> () {1, 2, 3, 4, 5}
},
new Baz ()
{
ints = new List<int> () {4, 5, 6, 7, 8}
}
};
IEnumerable<int> result = foo.bazs
.Select (x => x.ints)
.Distinct …Run Code Online (Sandbox Code Playgroud) LessonInterface
class ILesson
{
public:
virtual void PrintLessonName() = 0;
virtual ~ILesson() {}
};
Run Code Online (Sandbox Code Playgroud)
stl容器
typedef list<ILesson> TLessonList;
Run Code Online (Sandbox Code Playgroud)
调用代码
for (TLessonList::const_iterator i = lessons.begin(); i != lessons.end(); i++)
{
i->PrintLessonName();
}
Run Code Online (Sandbox Code Playgroud)
错误:
描述资源路径位置类型将'const ILesson'作为'this'参数传递给'virtual void ILesson :: PrintLessonName()',丢弃限定符
如何隐藏消费者的默认构造函数?我试图私下写,但有编译问题.
解决方案是:
class MyInterface
{
public:
MyInterface(SomeController *controller) {}
};
class Inherited : public MyInterface
{
private:
Inherited () {}
public:
Inherited(SomeController *controller)
{
}
};
Run Code Online (Sandbox Code Playgroud) short val1 = short.MaxValue;
short val2 = short.MaxValue;
int result = val1;
result |= val2 << 16;
Console.WriteLine( "Result =\t" + result ); //2147450879
Console.WriteLine( "Expected =\t" + int.MaxValue ); //2147483647
Run Code Online (Sandbox Code Playgroud) class base
{
base () { }
virtual ~base () { }
}
class middleBase
{
middleBase () { }
middleBase (int param) { }
~middleBase () { }
}
class concrete : public middleBase
{
concrete () { }
concrete (int param) { // process }
~concrete () { // delete something }
}
Run Code Online (Sandbox Code Playgroud)
错误是:未完成对"middleBase :: middleBase(int param)"的引用
这适用于参数化构造函数的最佳实践吗?