小编jac*_*kie的帖子

BinaryFormatter和Deserialization Complex对象

无法反序列化以下对象图.在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)

//序列化成功 …

c# binaryformatter

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

NHibernate 3.1 NHibernate.Linq.NhRelinqQueryParser异常"序列包含多个匹配元素"

我正在使用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)

c# nhibernate

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

MongoDb聚合按日期分组

我正在尝试按时间戳分组名为"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)

mongodb aggregation-framework

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

转换Func <>类型

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)

有解决方案吗?

c# functional-programming

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

如何在C++中的类中实现main方法?

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问题

有什么解决方案吗?

c++

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

如何存储TypeInfo

  class A {}
  A a;
  type_info info = typeid (a); // error type_info is private
Run Code Online (Sandbox Code Playgroud)

我想要一个列表list<type_info>来存储类的类型.有解决方案吗?

c++

6
推荐指数
2
解决办法
3788
查看次数

如何在一个接口中两次使用具有不同模板参数的相同接口?

我想通过这个例子会更清楚。我们希望在处理器类中看到两个具有不同参数的方法。“ 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)

c# generics

5
推荐指数
2
解决办法
1966
查看次数

Topshelf多个主机

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)

topshelf

5
推荐指数
2
解决办法
4359
查看次数

Linq选择具有鲜明的内在价值

    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)

c# linq

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

stl :: list中的C++接口

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()',丢弃限定符

c++

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

如何在C++中创建没有无参数构造函数的接口?

如何隐藏消费者的默认构造函数?我试图私下写,但有编译问题.

解决方案是:

class MyInterface
{
public:
            MyInterface(SomeController *controller) {}
};

class Inherited : public MyInterface
{

private:
            Inherited () {}
public:
            Inherited(SomeController *controller)
            {
            }

};
Run Code Online (Sandbox Code Playgroud)

c++

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

如何使两个WORD变为DWORD

        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)

c#

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

C++抽象类的构造和破坏

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)"的引用

这适用于参数化构造函数的最佳实践吗?

c++

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