C#异常是可序列化的,因此它们也不能同时是DataContracts,因此我不能使用JsonDataContractSerializer。
有什么方法可以将Exceptions序列化为JSON?
我无法通过好友访问来访问私人成员。这是我的代码。
#pragma once
#ifndef TEST_FRIENDS
#define TEST_FRIENDS
#endif
namespace LibToTestNamespace
{
class LibToTest
{
public:
double Add(double, double);
private:
TEST_FRIENDS;
int GetMyInt();
int mInt;
};
}
Run Code Online (Sandbox Code Playgroud)
和
#include "UnitTests.h"
#define TEST_FRIENDS \
friend class TestCustomUnitTest_hello_Test;
#include "LibToTest.h"
TEST(TestCustomUnitTest, hello)
{
LibToTestNamespace::LibToTest ltt;
ltt.mInt = 5;
ltt.GetMyInt();
}
Run Code Online (Sandbox Code Playgroud)
我收到错误“无法访问类中声明的私有成员”。我认为首先构建了库,所以 TEST_FRIENDS 没有被正确替换?但如果单元测试依赖于库,它总是会首先构建,对吧?
Type myType = Type.GetType(nameOfTypeString);
DoSomething(typeof(myType));
// signature of DoSomething
DoSomething(Type myType)
Run Code Online (Sandbox Code Playgroud)
抱怨它无法解析myType.