小编Ste*_*idi的帖子

c#读取xml文件

我试图<thumbnail_large>http://b.vimeocdn.com/ts/235/662/23566238_640.jpg</thumbnail_large>从创建的xml文件中的thumbnail_large元素中提取值.有没有办法在不循环who xml文件的情况下提取该值?谢谢你的帮助.

<videos>
    <video>
        <id>6271487</id>
        <title>Spheres</title>
        <description>text</description>
        <url>http://vimeo.com/6271487</url>
        <thumbnail_small>http://b.vimeocdn.com/ts/235/662/23566238_100.jpg</thumbnail_small>
        <thumbnail_medium>http://b.vimeocdn.com/ts/235/662/23566238_200.jpg</thumbnail_medium>
        <thumbnail_large>http://b.vimeocdn.com/ts/235/662/23566238_640.jpg</thumbnail_large>
        <embed_privacy>anywhere</embed_privacy>
    </video>
</videos>
Run Code Online (Sandbox Code Playgroud)

.net c# xml xpath

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

在调试时,如何在枚举中的任意位置启动foreach循环?

我正在调试我的程序.我可以foreach在调试模式下为循环设置起始对象吗?例如,我希望foreach循环从我的集合的第5个元素开始.

.net c# debugging foreach

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

c ++中数组的长度

我读到了用C++获取数组的长度,你这样做:

int arr[17];
int arrSize = sizeof(arr) / sizeof(int);
Run Code Online (Sandbox Code Playgroud)

我试着为字符串做同样的事情:我在哪里

string * arr;
arr = new (nothrow) string [213561];
Run Code Online (Sandbox Code Playgroud)

然后我做

arr[k] = "stuff";
Run Code Online (Sandbox Code Playgroud)

我循环遍历每个索引并在其中放入"stuff".

现在我想要数组的大小应该是213561,这是正确的方法,为什么它在C++中如此复杂?

c++ arrays

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

调用没有反射的方法声明

我有一个基类(顺序)与一组子类(生产者,特殊订单,零件订单等).

只有其中一些子类实现了一个特定的接口(ITrackingCustomer),该接口具有单个方法声明(object getcustdetails()).

作为我的解决方案的一部分,我的所有订单都在中心位置处理,即任何crud方法都通过中心层.在这个中心层,我想做以下事情:

如果订单类型为ITrackingCustomer

然后调用方法getcustdetails()

我使用以下代码工作:

if (typeof(ITrackingCustomer).IsAssignableFrom(Order.GetType())) 
{ 
     MethodInfo theMethod = Order.GetType().GetMethod("getcustdetails"); 
     object y = theMethod.Invoke(Order, null); 
} 
Run Code Online (Sandbox Code Playgroud)

我对第一部分使用isassignable来感到满意,但是想对第二部分使用性能较低的方法(即使用invoke进行反射).

我的问题是:

有没有更有效的方法来执行此操作,因为我已经读过使用invoke命令是昂贵的.

c# reflection methods polymorphism interface-implementation

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

如何在C#中动态创建DataGridView?

如何在C#中动态创建DataGridView?你能举个例子吗?

c# datagridview winforms

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

如何为不由ASP.NET管理的cookie设置滑动到期时间?

我的ASP.NET应用程序管理两个cookie:由FormsAuthentication发布和管理的标准auth cookie,以及另一个允许使用非Windows/ASP.NET系统进行单点登录的cookie.

ASP.NET应用程序配置为通过web.config启用auth cookie的滑动过期:

<authentication mode="Forms">
    <!-- forms attributes removed for brevity -->
    <forms name=".ASPXAUTH" slidingExpiration="true" /> 
</authentication>
Run Code Online (Sandbox Code Playgroud)

不幸的是,滑动过期只会更改auth cookie而不是SSO cookie.是否有我可以订阅的事件,以便在auth cookie的到期时间延长时通知我?

或者,我是否可以通过拦截对应用程序的每个有效请求并手动扩展cookie来模拟此行为?如果是这样,我必须实施哪种方法来拦截任何控制器的此类请求?

c# asp.net cookies asp.net-mvc forms-authentication

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

什么是c#Transacted?

我在别人的代码上工作,它在类成员实现期间使用"Transacted",例如:

void Smth.Add(type var)
{
    this.Smth.Transacted.Add(var);
}
Run Code Online (Sandbox Code Playgroud)

什么是交易?

c#

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

需要默认参数值的模板函数的首选设计是什么?

我正在努力清理一个充满功能模板的API,并且强烈希望编写以下代码.

template <typename T, typename U, typename V>
void doWork(const T& arg1, const U& arg2, V* optionalArg = 0);
Run Code Online (Sandbox Code Playgroud)

当我调用此模板时,我想按照以下方式执行此操作.

std::string text("hello");
doWork(100, 20.0, &text);
doWork('a', text);         // oops!
doWork<char, std::string, void>('a', text);  // to verbose!
Run Code Online (Sandbox Code Playgroud)

不幸的是,第二次调用没有编译,因为编译器无法推断出可选参数的类型.这很不幸,因为我真的不在乎参数类型是什么,而是它的值是NULL.此外,我想避免第三次调用的路由,因为它妨碍了可读性.

这导致我尝试使模板参数V具有默认类型,这也不起作用,因为您不能将默认类型应用于函数模板参数(至少使用VC++ 9.0).

template <typename T, typename U, typename V = void>  // oops!
void doWork(const T& arg1, const U& arg2, V* optionalArg = 0);
Run Code Online (Sandbox Code Playgroud)

我唯一剩下的选择是引入一个doWork对模板参数一无所知的重载V.

template <typename T, typename U>
void doWork(const T& arg1, const U& arg2) …
Run Code Online (Sandbox Code Playgroud)

c++ templates optional-parameters optional-arguments function-templates

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

如何将long转换为LPCWSTR?

如何在C++中将long转换为LPCWSTR?我需要类似于这个的功能:

LPCWSTR ToString(long num) {
    wchar_t snum;
    swprintf_s( &snum, 8, L"%l", num);
    std::wstring wnum = snum;
    return wnum.c_str();
}
Run Code Online (Sandbox Code Playgroud)

c++ string type-conversion

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

char*丢失数据

我正在写一个返回一些数据的C++代码,问题是:每当我从另一个文件调用它时,我的const char都会丢失它的值.我不知道发生了什么.

我在ProcClient.h上的代码

virtual void reportWorkflowError(unsigned int workflow,
        const dp::String& errorCode) {
    char message[1000];
    snprintf(message, 1000, "Workflow: %s ERROR: %s", workflowToString(
            workflow).utf8(), errorCode.utf8());
    printf("[%s]", message);

    errorInfo = message;
}
virtual const char * getErrorInfo() {
    return errorInfo;
}
Run Code Online (Sandbox Code Playgroud)

[工作流程:DW_FULFILL错误:E_ADEPT_NO_TOKEN]

[工作流程:错误:E_ADEPT_NOT_READY]

//抛出两个错误,errorInfo应该是最后一个

在Services.cpp上我启动一个"工作流程",如果它抛出一个错误,则调用上面的监听器,之后我应该得到lastError指针.

// g_drmClient是ProcClient

bool RMServices::startFullfilment(dp::String acsm) {
    //Do things 
g_drmClient->getProcessor()->startWorkflows(dpdrm::DW_FULFILL);
size_t count = g_drmClient->getProcessor()->getFulfillmentItems();
printf("Number of items fulfilled: %d\n", count);

bool returnValue = !g_drmClient->hasError();
if (!returnValue)
    lastError = g_drmClient->getErrorInfo());

printf("[%s]", lastError);

return returnValue;
}
Run Code Online (Sandbox Code Playgroud)

在这里它打印:[\æ¾°¯¯¯¯| |æ¾\æ¾er的项目更充分的迭代]

发生了什么?

c c++ string pointers

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

.NET JIT是否优化嵌套的try/catch语句?

我一直在考虑嵌套的try/catch语句,并开始考虑JIT可以在哪些条件下执行编译IL的优化或简化.

为了说明,请考虑以下功能等效的异常处理程序表示.

// Nested try/catch
try
{
  try
  {
    try
    {
      foo();
    }
    catch(ExceptionTypeA) { }
  }
  catch(ExceptionTypeB) { }
}
catch(ExceptionTypeC) { }

// Linear try/catch
try
{
  foo();
}
catch(ExceptionTypeA) { }
catch(ExceptionTypeB) { }
catch(ExceptionTypeC) { }
Run Code Online (Sandbox Code Playgroud)

假设在嵌套的try语句的堆栈帧中没有额外的变量引用或函数调用,JIT可以断定堆栈帧可能会折叠为线性示例吗?

现在下面的例子怎么样?

void Try<TException>(Action action)
{
  try
  {
    action();
  }
  catch (TException) { }
}

void Main()
{
  Try<ExceptionC>(Try<ExceptionB>(Try<ExceptionA>(foo)));
}
Run Code Online (Sandbox Code Playgroud)

我认为JIT没有任何方法可以内联委托调用,所以这个例子不能简化为前一个.然而,在foo()投掷的情况下ExceptionC,与线性示例相比,此解决方案的性能是否更差?我怀疑从委托调用中拆除堆栈帧需要额外的成本,即使帧中包含的额外数据很少.

.net optimization jit exception-handling try-catch

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

在这个C++代码中调用函数的方式是什么?

我从c ++入门书中得到了这段代码,这本书旨在解释删除操作符.但是,我不明白的是程序如何调用这两个函数以及它们如何交互.

// delete.cpp -- using the delete operator
#include <iostream>
#include <cstring> // or string.h
using namespace std;
char * getname(void); // function prototype

int main()
{
    char * name; // create pointer but no storage

    name = getname(); // assign address of string to name
    cout << name << " at " << (int *) name << "\n";
    delete [] name; // memory freed

    name = getname(); // reuse freed memory
    cout << name << " at " …
Run Code Online (Sandbox Code Playgroud)

c++ function

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