我在代码隐藏的ASP.NET中有一个布尔属性,现在我想在标记文件的Javascript中使用它,但Javascript不理解True或False.那么现在,我正在使用这个:
if ( '<%=IsTabVisible%>' == 'True'){
///
}
Run Code Online (Sandbox Code Playgroud)
它有效,但非常难看.有一个更好的方法吗?
谢谢
我在这里发现问题如果检索方法返回'null'或者当它无法产生返回值时抛出异常?和是否应函数返回null或一个空对象?,但我认为我的情况完全不同.
我正在编写一个由Web服务和客户端组成的应用程序.Web服务负责访问数据并将数据返回给客户端.我设计我的应用程序是这样的:
//网络服务
try
{
DataTable data = GetSomeData(parameter);
return data
}
catch (OopsException ex)
{
//write some log here
return null;
}
Run Code Online (Sandbox Code Playgroud)
//客户:
DataTable data = CallGetSomeData(parameter);
if(data == null)
{
MessageBox.Show("Oops Exception!");
return;
}
Run Code Online (Sandbox Code Playgroud)
好吧,有一个不返回null的规则.我不认为我应该重新抛出异常并让客户端捕获SoapException.你有什么评论?有没有更好的方法来解决这个问题?
谢谢.
我刚刚问我的经理为什么我们公司不使用Resharper,而且他很友好地告诉我,我们的项目使用Resharper非常庞大,因为它会减慢我们的计算机的速度.
我仍然从TFS获得源代码,似乎需要2个多小时(啊),每个解决方案应该包含大约30个项目,每个项目包含50-100个.cs文件.我们的机器运行在Q6700/4GB RAM和Windows 7 x64 Enterprise,VS/TFS 2010上.
我会亲自尝试一下,但我想问一下Resharper(最新版本)是否适合大型项目.在我的情况下,配置/调整VS/Resharper以获得可接受的性能是否有变化?你有同样的事吗?
非常感谢你
我有一个有两种方法的课程如下:
public class WorkManagement
{
public string DoYourWork(Manager manager)
{
//
}
public string DoYourWork(Employee employee)
{
//
}
}
Run Code Online (Sandbox Code Playgroud)
Manager和Employee是从数据库(在Entity Framework中)生成的类.我认为这很难看,例如,当我需要扩展更多类时,所以我想将它重构为:
public interface IDoWork
{
string DoSomeWork();
}
public class Manager:IDoWork
{
public string DoSomeWork()
{
//
}
}
public class Employee:IDoWork
{
public string DoSomeWork()
{
//
}
}
Run Code Online (Sandbox Code Playgroud)
但是我如何处理自动生成的类?我如何添加这些东西?
谢谢.
我设置了一个数据库镜像,然后使用它connectionstring
连接到它:
Data Source={0};Failover Partner={1};Initial Catalog=AdventureWorks;
Integrated Security=True;
Run Code Online (Sandbox Code Playgroud)
将一些数据添加到数据库后,我关闭了主服务器,因此镜像服务器成为主服务器.我再次打开连接,得到这个错误:
System.Data.SqlClient.SqlException: A transport-level error has
occurred when sending the request to the server. (provider: Shared Memory
Provider, error: 0 - No process is on the other end of the pipe.)
Run Code Online (Sandbox Code Playgroud)
我认为通过连接字符串中指定的故障转移伙伴,ADO.NET将为我完成工作.那我现在该怎么办?
这个问题很紧迫.非常感谢你的帮助.
sql-server ado.net failover connection-string high-availability
根据这个:http://code.google.com/appengine/docs/whatisgoogleappengine.html 似乎GAE仅使用数据存储来存储数据,这与Windows Azure平台上的表服务等效.
有谁知道它使用哪个RDBMS?或者这样的事情存在与否?
编辑:Windows Azure平台是微软的一个云计算平台,它提供了两种存储数据的选项:
这就是为什么我认为很难相信Google App Engine不提供RDBMS.我搜索过,但没有找到确认.这就是我在这里问的原因
这个问题看起来很熟悉:https://stackoverflow.com/questions/2187/essential-programming-tools,但我想专注于.NET编程.除了Windows和Visual Studio之外,您每天都需要哪些工具来完成工作?免费的开源代码工具是首选:)
我一直在使用这些工具:
我应该知道和使用哪些其他工具?
我有两个类定义如下:
public class RoleButton: Button
{
protected bool PrimaryRole;
protected bool SecondaryRole;
private string _role;
private AuthenticatedPage CurrentPage
{
get { return (AuthenticatedPage)Page; }
}
protected UserInfo CurrentUser
{
get { return CurrentPage.CurrentUser; }
}
protected void SetRole(string role)
{
_role = role;
}
protected override void OnPreRender(EventArgs e)
{
base.OnInit(e);
if (CurrentUser.IsSuperAdmin) return;
DataTable dt = CommandController.GetButtonRoleForUserByPortalID(CurrentUser.UserID,
ConvertUtility.ToInt32(AppEnv.PortalId()));
if (dt.Rows.Count > 0)
{
if (dt.Rows.Count > 1)
{
PrimaryRole = ConvertUtility.ToBoolean(dt.Rows[0][_role]);
SecondaryRole = ConvertUtility.ToBoolean(dt.Rows[1][_role]);
if (!PrimaryRole && !SecondaryRole)
{ …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个Web服务,对于每个方法调用,必须将日志条目写入数据库.在特定时间,对此方法的调用可能非常密集(高达1-2k请求/分钟),并且我们的服务器不是那么强大.
我想用a List<Log>
来缓存日志条目,然后:
第一个条件是OK,但我不知道如何实现第二个条件.
我怎么能这样做,而不会给我的Web服务增加太多开销?
编辑:我根据小麦的建议解决了这个问题.
在这种情况下,MSMQ非常有帮助!
来自我的导师:首选本地方法(直接在集合上实现)而不是IEnumerable的扩展方法,因为:
LINQ-to-Objects扩展方法在IEnumerable上实现,这意味着在最坏的情况下(当您搜索的项目不存在于集合中时),您将必须枚举所有元素.如果你有一个直接在集合上实现的Contains或Exists方法,它可以利用内部知识,也许只是做一个哈希表查找或其他一些快速操作.
我非常困惑,因为我认为微软应该已经为IEnumerable Contains/Exists实现了哈希表.List和IEnumerable的快速基准显示没有差异:
static void Main(string[] args)
{
Console.Write("input the number of elements: ");
int count = Convert.ToInt32(Console.ReadLine());
Console.Write("input the number of loops: ");
int loop = Convert.ToInt32(Console.ReadLine());
Random r = new Random();
Stopwatch sw = new Stopwatch();
for (int i = 0; i < loop; i++)
{
var list = CreateListOfInt(count);
sw.Start();
for (int j = 0; j < count; j++)
{
DoContains(list, r.Next());
}
sw.Stop();
}
Console.WriteLine("List<T> native method: Iterated {0} times on {1} elements, elapsed :{2}",loop,count,sw.Elapsed); …
Run Code Online (Sandbox Code Playgroud) .net ×4
asp.net ×2
c# ×2
sql-server ×2
ado.net ×1
azure ×1
caching ×1
cloud ×1
database ×1
exception ×1
failover ×1
javascript ×1
linq ×1
performance ×1
resharper ×1
return-value ×1
web-services ×1