小编Car*_*ras的帖子

动态添加属性到现有对象

我像这样创建person对象.

 Person person=new Person("Sam","Lewis") 
Run Code Online (Sandbox Code Playgroud)

它有这样的属性.

person.Dob
person.Address
Run Code Online (Sandbox Code Playgroud)

但现在我想添加这样的属性,并在创建对象后在运行时设置值.人.年老的人

如何在创建对象后添加这些额外的属性.那些属性名称可以不时更改.因此不能硬编码"年龄"和"性别".

c#

36
推荐指数
4
解决办法
9万
查看次数

WebResponse.GetResponseStream()可以返回null吗?

我知道它是一个菜鸟问题,但只是想知道GetResponseStream()在任何情况下是否都能返回null?

.net c#

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

使用JSch从SFTP服务器下载文件

我正在使用jsch从服务器下载文件,我的代码如下.

public static void downloadFile(TpcCredentialsDTO dto) {
        logger.trace("Entering downloadFile() method");

    Session session = null;
    Channel channel = null;
    ChannelSftp channelSftp = null;
    boolean success = false;

    try {
        JSch jsch = new JSch();
        session = jsch.getSession(dto.getUsername(), dto.getHost(),
                dto.getPort());
        session.setPassword(dto.getPassword());

        session.setConfig("StrictHostKeyChecking", "no");
        session.connect();
        logger.info("Connected to " + dto.getHost() + ".");

        channel = session.openChannel("sftp");
        channel.connect();
        channelSftp = (ChannelSftp) channel;

        List<String> filesToDownload = getFilesToDownload(dto,channelSftp);

        if (!filesToDownload.isEmpty()) {
            for (String fileDownloadName : filesToDownload) {
                success = false;
                OutputStream output = new FileOutputStream(
                    "C:\Download\BLT_03112012");

                channelSftp.get("BLT_03112012",output); …
Run Code Online (Sandbox Code Playgroud)

java sftp jsch

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

原因:(noSuchName)此MIB中没有此类变量名称

我正在使用centos操作系统.
我试图通过snmpget命令获取localhost的内存统计信息,我收到此错误.

snmpget -v 1 -c public localhost .1.3.6.1.4.1.2021.4.6
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: UCD-SNMP-MIB::memAvailReal
Run Code Online (Sandbox Code Playgroud)

但是,如果我解雇这个..我得到输出..

snmpget -v 1 -c public localhost .1.3.6.1.2.1.1.3.0
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (58756) 0:09:47.56
Run Code Online (Sandbox Code Playgroud)

我没有得到我做错的事.我出口的路径/usr/share/snmp/mibs/$PATH变量.
谁能帮我吗.

centos snmp

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

C++错误C2653"类"不是类或命名空间名称

下午好.我已经开始学习c ++而且我正在编写我的项目.如果你发现一些错误的代码我会很高兴,如果你告诉我.

我有以下定义:

Utils.h

#include "stdafx.h"
#include <string>
using namespace std;

class Utils
{
public:
static string GetStringFromInt (int number);
};
Run Code Online (Sandbox Code Playgroud)

Utils.cpp

#include "Utils.h"
#include <sstream>
#include <string>
using namespace std;

 string Utils::GetStringFromInt (int number)
{

    stringstream ss;
    ss << number;
    return ss.str();
}
Run Code Online (Sandbox Code Playgroud)

Ping.h

#include "stdafx.h"
#include <string>

using namespace std;

class Ping
{
public:
    static int PingIt(int argc, char* argv[],string &mstime,string &ttl);   
};
Run Code Online (Sandbox Code Playgroud)

Ping.cpp

#include "Ping.h"
#include <string>
#include "icmpdefs.h"
#include <string>
#include <iostream>
#include <sstream>
#include …
Run Code Online (Sandbox Code Playgroud)

c++ class

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

通过反射从某些给定字符串创建强类型LINQ查询的最佳方法是什么

我正在使用EF5,工作单元和存储库模式.我想为访问指定用户的数据定义一些限制.在数据库中,我设计了一个表来保存我的实体名称及其属性(称为EntityProperties),另一个表来保存这些属性的值,这些属性称为PropertyValues,每个EntityProperty都有一个或多个PropertyValues.在用户请求数据的业务层中,如果为他定义了任何限制,则应在linq语句中添加一些条件.我所做的是通过'userId'获取实体名称及其属性和值的列表,然后我在linq查询中添加一些'Where'子句.但是,实体名称及其属性的类型为"String",因此我应该使用Reflection来管理它们.但我不知道这一部分,我不知道 知道如何从给定的条件字符串集创建LINQ where子句.例如,假设用户请求列表顺序,用户ID为5.我首先查询这些访问限制表,结果是:

"订单","Id","74"

"秩序","Id","77"

"订单","Id","115"

这意味着该用户只能看到这三个订单,而在Orders表中,我们有更多的订单.所以,如果我想使用LINQ查询来获取订单,例如:

var orders = from order in Context.Orders
Run Code Online (Sandbox Code Playgroud)

我需要把它变成这样的东西:

var orders = from order in Context.Orders
Run Code Online (Sandbox Code Playgroud)

//其中订单ID应为74,77,115

但是,从"Order"和"Id"字符串到Order实体和Id属性需要反射.因此有两个问题:

从字符串中获取强类型的最佳方法是什么?我有更好的方法来做到这一点,表现更好吗?

c# linq reflection design-patterns entity-framework-5

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

C++错误LNK2001:未解析的外部符号函数_main

可能重复:
什么是未定义的引用/未解析的外部符号错误,如何解决?

我正在学习C++,我的项目中有编译问题.我已经阅读了大量的帖子,标题上有这个错误,但我无法找到问题所在.

我在我的Main函数中有一个方法调用负责该错误.每当我评论该项目时,项目编译完美.

代码如下:

Main.cpp的

#pragma once 
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <WinSock.h>
#include <Windows.h>
#include <string.h>
#include "NetUtils.h"
#include "Utils.h"
#include "FileUtils.h"
#include "SendMail.h"
using namespace std;



int _tmain(int argc, _TCHAR* argv[])
{   

    SendMail *mail = new SendMail("somemail@mail.com","Envio de C++","Cuerpo del mail");    
    char* msg="";   
    mail->SendNow();
    ...
Run Code Online (Sandbox Code Playgroud)

这个方法mail-> SendNow是我评论解决问题的方法,所以我想我在SendMail.cpp或SendMail.h中有一些头声明问题

现在剩下的类和标题:

SendMail.h

#pragma once
#ifndef SENDMAIL_H
#define SENDMAIL_H


class SendMail

{
public:
    SendMail(char* c_to, char* c_subject, char* c_body);
    void Check(int iStatus, char *szFunction);
    void SendNow();
    char * to; …
Run Code Online (Sandbox Code Playgroud)

c++ program-entry-point

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

MVC 4表单身份验证无法与[授权]一起使用

我正在学习MVC4,我正在关注Pro ASP NET MVC4第4版的书,以创建一个体育商店项目.

我一直在webforms中开发,我试图弄清楚表单身份验证在MVC4中是如何工作的.

这是我取得的成就:

Web.Config中

<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880"/>  </authentication>
Run Code Online (Sandbox Code Playgroud)

AccountController登录动作:

[HttpPost]
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (authProvider.Authenticate(model.UserName, model.Password))
                {
                    return Redirect(returnUrl ?? Url.Action("Index", "Admin"));
                }
                else
                {
                    ModelState.AddModelError("", "Incorrect username or password");
                    return View();
                }
            }
            else
            {
                return View();
            }
        }
Run Code Online (Sandbox Code Playgroud)

认证提供者:

public bool Authenticate(string username, string password) {
            bool result = FormsAuthentication.Authenticate(username, password);
            if (result)
            {
                FormsAuthentication.SetAuthCookie(username, false);
            }

            return result;

        }
Run Code Online (Sandbox Code Playgroud)

我正在设置AuthCookie,现在我想知道,如何保护AccountController之外的其他控制器和操作

该应用程序有一个名为AdminController的控制器,您可以在其中编辑
以下{controller/action}下的产品和产品列表

管理员/指标

所以,如果我不理解理论,如果用户没有登录AccountController,他们就不应该在声明中使用[Authorize]标签调用操作:

 public …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc forms-authentication authorize asp.net-mvc-4

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

如何使用asp.net隐藏和取消隐藏Excel工作表的列

我有一个需要实现的功能.

我们将网格数据绑定到excel导出,它工作正常.但我得到了新的要求,我必须隐藏excel导出中的列.之后,当用户打开excel表时,他应该可以选择再次隐藏我们通过代码隐藏的列.

编辑:

我在.aspx页面上有一个gridview控件,我使用以下代码导出到excel:

 public static void Export(string filename, GridView grid)
    {

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("content-disposition",
            string.Format("attachment; filename={0}", filename.Replace(" ", "") + ".xls"));
            HttpContext.Current.Response.Charset = "";
            HttpContext.Current.Response.ContentType = "application/vnd.xls";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            grid.HeaderStyle.BackColor = System.Drawing.Color.Cyan;
            GridViewRow row = new GridViewRow(0, 1, DataControlRowType.DataRow, DataControlRowState.Normal);
            TableCell cell = new TableCell();
            cell.Text = String.Format("{0}", Heading[count]);
            cell.ColumnSpan = grid.Rows[1].Cells.Count;
            cell.Attributes.Add("style", "background-color: white; color: black;text-align:left;");
            cell.Attributes.Add("class", "yellow");
            row.Cells.Add(cell);
            grid.Controls[0].Controls.AddAt(0, row);
            grid.RenderControl(htw);
            DataTable dt = new DataTable();
            DataRow …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net

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

如何使用ACRA发送Android崩溃报告

我试图将崩溃报告从我的应用程序发送到我的域或邮件但仍然失败.

为了通过邮件获取崩溃报告,我做到了

@ReportsCrashes(

      formKey = "",
      mailTo = "abc@gmail.com"
  )
Run Code Online (Sandbox Code Playgroud)

响应是,发送文件1372758321000-approved.stacktrace

checkAndSendReports - 完成

要在我的域中获取崩溃报告,我做到了

@ReportsCrashes(

      formKey = "",
      formUri = "http://www.abc.com/test1"
)
Run Code Online (Sandbox Code Playgroud)

响应是,发送文件1372856882000-approved.stacktrace无法发送崩溃报告1372856882000-approved.stacktrace org.acra.sender.ReportSenderException:通过Http POST发送FORM报告时出错

任何帮助对我都很方便,并表示赞赏.

crash android exception crash-reports acra

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