我有几个方法看起来像这样:
public void foo()
{
try
{
doSomething();
}
catch(Exception e)
{
Log.Error(e);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以更改代码吗?
[LogException()]
public void foo()
{
doSomething();
}
Run Code Online (Sandbox Code Playgroud)
如何实现此自定义属性?这样做的利弊是什么?
-----编辑1 ------------
我可以自己实现它,我的意思是只写一个类,还是我需要使用postharp或其他解决方案?
这应该很简单,但显然不是.由于..Windows 3左右,有一个名为Phone或Phone&Modem的控制面板.在那个控制面板中有一堆关于调制解调器如何拨号的信息,假设你有一个调制解调器连接起来.例如,您是否需要拨打9才能离开,区号是什么,等等.如何以编程方式访问此信息?我正在使用C#.NET 2010.
有没有办法实现这一目标?我想传递一些文本并让它出现在输入行 - 而不是" 输入你的名字:<游标> ",我想要" 输入你的名字:默认可编辑文本<游标> "
我需要创建一个维护WCF会话的服务.在构造函数中,我从数据库中读取数据,当会话结束时,我必须将其保存回来.
如果我理解正确,当我在客户端上调用Close()时会话结束(我的客户端ServiceClient是使用SvcUtil.exe创建的).
当我测试它时,我发现它有时在大约后被调用.10分钟,有时20分钟后,有时根本没有.
那么析构函数何时被调用?
服务
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Service:IService
{
private User m_User = null;
public Service()
{
m_User = User.LoadFromDB();
}
~Service()
{
m_User.SaveToDB();
}
public void SetName(string p_Name)
{
m_User.Name = p_Name;
}
}
Run Code Online (Sandbox Code Playgroud)
Web.config文件
<?xml version="1.0"?>
<configuration>
<system.web>
<sessionState timeout="2" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="Karatasi.Services.B2C" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:19401/B2C.svc"/>
</baseAddresses>
</host>
<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration="test"
contract="Karatasi.Services.IB2C"
/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="test" receiveTimeout="00:01:00" > …Run Code Online (Sandbox Code Playgroud) 我正在使用C#创建一个"Gujarati To English Dictionary"应用程序.
我想要的是,如果用户从键盘"તાજમહાલ"键入"tajmhal"将同时显示在TEXTBOX中.
即.如果显示"koml","કોમલ".等等...
我已经下载并将文本框的字体设置为"Gujarati Saral-1"并且它可以正常工作.
但是当我将文本框的文本存储到数据库时,它存储为"tajmhal"而不是"તાજમહાલ".
所以,你能告诉我另一个解决方案吗?
有没有人知道.net winforms(或webforms)的对象资源管理器控件?
通过"对象浏览器",我的意思是像我可以在我自己的程序中使用它的视觉工作室对象浏览器.
我发现在网络上这些链接:
1. http://www.codeproject.com/KB/trace/oe.aspx -这是很老,我不知道,如果今天相关.
2. http://www.pcreview.co.uk/forums/can-embed-vs-nets-object-explorer-program-t1342274.html - 没有人回答他..
因此,经过大量搜索我的问题的答案后,我终于放弃了我的Google技能.
我有一个基类Base和一个派生类Derived.我想在Derived类中使用一个类重写Base类中的类型.这是一个例子:
class Apple {
public:
Apple() { }
// ...
};
class Orange {
public:
Orange() { }
// ...
};
class Base {
public:
typedef Apple fruit;
// ...
virtual fruit func() { return Apple(); }
};
class Derived : public Base {
public:
typedef Orange fruit;
// ...
fruit func() override { return Orange(); } // <-- Error C2555!
};
Run Code Online (Sandbox Code Playgroud)
这段代码不起作用,它给出了一个
C2555 error ('Derived::func': overriding virtual function return type …Run Code Online (Sandbox Code Playgroud) 我很难让我的表单在vb.net中拥有透明的背景
目前以New I的形式设置
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, true)
Run Code Online (Sandbox Code Playgroud)
但是表单仍然显示为具有默认的灰色背景
谁能帮忙?
编辑:我需要窗体上的控件可见,所以我不认为将不透明度设置为0将起作用
编辑:我尝试了透明度密钥解决方案,但它不起作用.我有一个黑色背景的圆形图像.OnPaint我将透明度键设置为0,0的img像素,然后这给我留下了圆形图像(我想要的)它隐藏了黑色背景,但我仍然保留了表单的默认灰色矩形.
下面是我的代码 -
Public Sub New()
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.BackColor = Color.Transparent
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.Timer1.Start()
End Sub
Private Sub frmWoll_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim img As Bitmap = CType(Me.BackgroundImage, Bitmap)
img.MakeTransparent(img.GetPixel(2, 2))
Me.TransparencyKey = img.GetPixel(2, 2)
End Sub
Run Code Online (Sandbox Code Playgroud) 我有一个DataGridview1和a ListView,当我选择列表视图项时(我将ListView项目传递给查询并DataGrid根据该项填充视图)
我写了一些像这样的代码....
private void listview_selectedindexchanged(object sender event args)
{
if (listview.SelectedItems.Count > 0 && listview.SelectedItems[0].Group.Name == "abc")
{
if(lstview.SelectedItems[0].Text.ToString() == "sfs")
{
method1();
}
else
{
// datagrid view1 binding
blah.....
}
}
if (lstview.SelectedItems.Count > 0 && lstview.SelectedItems[0].Group.Name == "def")
{
if(lstview.SelectedItems[0].Text.ToString() == "xyz")
{
method 1();
}
if(lstview.SelectedItems[0].Text.ToString() == "ghi")
{
method 2(a,b);
}
if(lstview.SelectedItems[0].Text.ToString() == "jkl")
{
method 2(c,d);
}
if(lstview.SelectedItems[0].Text.ToString() == "mno")
{
method 3();
}
}
} …Run Code Online (Sandbox Code Playgroud) 嗨,我有以下代码,产生一种奇怪的行为.由linq到Objects生成的IEnumerable中包含的对象实例的属性不会在后续的foreach语句中更新.foreach语句应该枚举IEnumerable.相反,解决方案是先将其枚举.
虽然我找到了解决方案,但我没有在书籍或文章中的任何地方看到这些,并处理类似的例子.也许对linq有错综复杂知识的人可以解释它.
我花了一天的时间来确定错误的确切原因,并且在大型应用程序中调试并不容易.然后我在一个更简单的环境中复制它,如下所示.
public class MyClass
{
public int val ;
}
public class MyClassExtrax
{
public MyClass v1 { get; set; }
public int prop1 { get; set; }
}
void Main()
{
List <MyClass> list1 = new List<MyClass>();
MyClass obj1 = new MyClass(); obj1.val = 10;
list1.Add(obj1);
MyClass obj2 = new MyClass();
obj2.val = 10;
list1.Add(obj2);
IEnumerable<MyClassExtrax> query1 =
from v in list1
where v.val >= 0
select new MyClassExtrax{ v1=v , prop1=0 } ;
//query1=query1.ToList(); solves the …Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×3
winforms ×3
asp.net ×1
attributes ×1
c++ ×1
console ×1
datagridview ×1
deferred ×1
destructor ×1
dialing ×1
inheritance ×1
linq ×1
listview ×1
overriding ×1
refactoring ×1
rules ×1
session ×1
tapi ×1
try-catch ×1
typedef ×1
vb.net ×1
virtual ×1
wcf ×1