框架设计指南(第2版,第327页)说:
CONSIDER提供方法
Close(),除了Dispose(),如果close是该区域的标准术语.这样做时,重要的是使Close实现相同
Dispose并IDisposable.Dispose明确地考虑实现方法.
所以,按照提供的例子,我有这个类:
public class SomeClass : IDisposable {
private SomeDisposable someInnerDisposable;
public void Open() {
this.someInnerDisposable = new SomeDisposable();
}
void IDisposable.Dispose() {
this.Close();
}
public void Close() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
this.someInnerDisposable.Dispose();
this.someInnerDisposable = null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
FxCop似乎不喜欢这样:
CA1816:Microsoft.Usage:'SomeClass.Close()'调用'GC.SuppressFinalize(object)',这种方法通常仅在'IDisposable.Dispose'的实现中调用.有关更多信息,请参阅IDisposable模式.
CA1816:Microsoft.Usage:更改'SomeClass.IDisposable.Dispose()'以调用'GC.SuppressFinalize(object)'.这将防止对象一旦被处理并且已经超出范围而不必要地完成对象.
CA1063:Microsoft.Design:修改'SomeClass.IDisposable.Dispose()'以便它调用Dispose(true),然后在当前对象实例上调用GC.SuppressFinalize(在Visual Basic中为'this'或'Me'),然后回报.
CA1063:Microsoft.Design:将'SomeClass.IDisposable.Dispose()'重命名为'Dispose'并确保将其声明为public和sealed.
-要么-
我试过了
[SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly",
Justification = "Framework Design Guidelines say it's ok.")]
void IDisposable.Dispose() …Run Code Online (Sandbox Code Playgroud) 是否可以执行作为资源包含在项目中的exe文件?我可以将文件作为字节数组获取并在内存中执行吗?
我不想将文件写入临时位置并在那里执行.我正在寻找一种解决方案,我可以在内存中执行它.(这不是.NET程序集.)
我有以下XAML:
<UserControl x:Class="EMS.Controls.Dictionary.TOCControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:EMS.Controls.Dictionary.Models"
xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
x:Name="root" >
<TreeView
x:Name="TOCTreeView"
Background="White"
Padding="3,5"
ContextMenuOpening="TOCTreeView_ContextMenuOpening"
ItemsSource="{Binding Children}" BorderBrush="{x:Null}" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Children, Mode=OneTime}">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<!--<ColumnDefinition Width="Auto"/>-->
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--<CheckBox VerticalAlignment="Center" IsChecked="{Binding IsVisible}"/>-->
<ContentPresenter Grid.Column="0" Height="16" Width="20"
Content="{Binding LayerRepresentation}" />
<!--<ContentPresenter Grid.Column="1" >
<ContentPresenter.Content>
Test
</ContentPresenter.Content>
</ContentPresenter>-->
<TextBlock Grid.Column="2" FontWeight="Normal" Text="{Binding Path=Alias, Mode=OneWay}" >
<ToolTipService.ToolTip>
<TextBlock Text="{Binding Description}" TextWrapping="Wrap"/>
</ToolTipService.ToolTip>
</TextBlock>
</Grid>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Children, Mode=OneTime}">
<!--<DataTemplate>-->
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition …Run Code Online (Sandbox Code Playgroud) 我的三个同事告诉我,没有理由使用StringBuilder来代替使用+运算符的连接.换句话说,这对一堆字符串很好:myString1 + myString2 + myString3 + myString4 + mySt...
他们使用的基本原理是,从.NET 2开始,如果使用+运算符,C#编译器将构建相同的IL,就像使用StringBuilder一样.
这对我来说是新闻.他们是对的吗?
我不能在两种转换方法之间进行选择.从枚举转换为int的最佳实践是什么?
1:
public static int EnumToInt(Enum enumValue)
{
return Convert.ToInt32(enumValue);
}
Run Code Online (Sandbox Code Playgroud)
2:
public static int EnumToInt(Enum enumValue)
{
return (int)(ValueType)enumValue;
}
Run Code Online (Sandbox Code Playgroud) 我知道.NET Framework附带了一个图像转换类(System.Drawing.Image.Save方法).
但我需要一个24位(R8G8B8)位图图像转换为16位(X1R5G5B5),我真的得上这种转换不知道,并在BMP头止跌24到16位的变化"工作(因为我们需要转换整个图像数据).
另外我想知道我是否可以控制图像抖动等.
想法?任何形式的帮助将不胜感激.
我正在重构我的程序以使用Parallel.ForEach.之前,当我使用常规for循环时,我正在使用Dispatcher更新WPF进度条,通过将当前数组索引除以数组大小来显示%completed.使用并行的foreach循环,这不能正确显示,即%跳跃,这是预期的.
如何为每个循环从并行更新WPF进度条,以便跟踪已完成的迭代次数?
如何为我的房产添加文字说明?

我的代码:
private bool _SpaceKey;
public bool SpaceKey
{
get
{
return _SpaceKey;
}
set
{
_SpaceKey = value;
}
}
Run Code Online (Sandbox Code Playgroud) 我的一位同事声称在C#中使用非静态类中的静态成员可以防止这些类的实例被垃圾收集,并且这是C#内存泄漏的常见来源.因此,他总是将静态成员包装在静态类中,并通过该静态类上的静态属性或方法从那里获取对它们的访问权限.我一直认为静态是在堆栈上,而不是堆,因此与垃圾收集没有任何关系.这对我来说似乎不对.
这有什么道理?
每次我打电话给方法
XmlDocument.Save(fooFilepath);
Run Code Online (Sandbox Code Playgroud)
它在DOCTYPE标签的末尾插入两个方括号,例如
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ARCXML SYSTEM "G:\ArcIMS\DTD\arcxml.dtd"[]>
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么会这样?我显然不希望这种情况发生.