我见过几个这样的例子:
[DllImport("user32.dll")]
static extern bool TranslateMessage([In] ref Message lpMsg);
[DllImport("user32.dll")]
static extern IntPtr DispatchMessage([In] ref Message lpmsg);
Run Code Online (Sandbox Code Playgroud)
但是,我不明白的是为什么有人会这样做只是像引用其他库一样引用DLL?MSDN声明:"在托管应用程序中重用现有的非托管代码时,DllImport属性非常有用.例如,托管应用程序可能需要调用非托管WIN32 API." 但是,那是说引用一个非托管的dll或者不可能引用它是没用的吗?
简单地说,微软定义了一个ReadOnlyCollectionBase,但没有使用它作为基类,ReadOnlyCollection<T>当它明显听起来应该是这样的.
我在这里错过了什么吗?我的意思是,是否有充分的理由不让这个类成为基类?
public class MultiSomething { } //CA1704:IdentifiersShouldBeSpelledCorrectly
Run Code Online (Sandbox Code Playgroud)
当我运行代码分析时,我收到一个错误,因为Microsoft不识别"Multi"这个词(他们使用它的数字IMultiValueConverter).因此,我所做的是更正CodeAnalysisDictionary.xml文件,并按照此处提供的步骤操作.但是,它似乎没有解决问题,我仍然收到代码分析警告消息.
为了确保这不是识别的单词部分的错误,我添加了另一个类和另一个异常.
public class MultiSomething { } //CA1704:IdentifiersShouldBeSpelledCorrectly
public class MutiiSomething { } //NO WARNING
<Dictionary>
<Words>
<Recognized>
<Word>Multi</Word> <-- This seems to not do anything... -->
<Word>Mutii</Word> <-- This actually does something... -->
</Recognized>
</Words>
</Dictionary>
Run Code Online (Sandbox Code Playgroud)
修复它的另一种方法是使用SuppressMessage,虽然如果我打算在整个地方使用这个词,这不是一个很好的解决方案.
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multi")]
public class MultiSomething { } //NO WARNING (Suppressed)
Run Code Online (Sandbox Code Playgroud)
微软是否真的阻止'Multi'被添加到已识别的单词中?
我正在尝试创建一个简单的Clamp(这样我就可以绑定任何类似的值...主要用于数字类型,如int,double等)
问题是如果我执行以下操作我得到一个错误,但根据MSDN IComparable的CompareTo应该能够处理空值.
Quote:"根据定义,任何对象都比较大于null,两个空引用比较相等."
public static T Clamp<T>(this T value, T min, T max)
where T : IComparable<T>
{
if (value.CompareTo(max) > 0)
return max;
if (value.CompareTo(min) < 0)
return min;
return value;
}
private Int32? _zip;
public Int32? Zip
{
get
{
return _zip;
}
set
{
_zip = value.Clamp<Int32?>(0, 99999);
}
}
Run Code Online (Sandbox Code Playgroud) 我从下面的代码中得到以下错误...不确定为什么(是的,它产生所有4,即使它是相同的2重复).哦,它并没有产生交替的行效果,即使在这些错误出现之前,相同的代码正在运行.
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=AreRowDetailsFrozen; DataItem=null; target element is 'DataGridDetailsPresenter' (Name=''); target property is 'SelectiveScrollingOrientation' (type 'SelectiveScrollingOrientation')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=HeadersVisibility; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=AreRowDetailsFrozen; DataItem=null; target element is 'DataGridDetailsPresenter' (Name=''); target …Run Code Online (Sandbox Code Playgroud) PersonVM.cs
public class MainWindowVM
{
public MainWindowVM()
{
PersonList = new ObservableCollection<Person>(Employees);
}
private Person[] Employees = new Person[]
{
new Person { ID = 1, Name = "Adam" },
new Person { ID = 2, Name = "Bill" },
new Person { ID = 10, Name = "Charlie" },
new Person { ID = 15, Name = "Donna" },
new Person { ID = 20, Name = "Edward" }
};
public ObservableCollection<Person> PersonList { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Person.cs …
有没有办法以编程方式获取ildasm.exe/ilasm.exe可执行文件的FileInfo/Path?我正在尝试反编译并重新编译一个dll/exe文件后对其进行一些修改(我猜测PostSharp会做类似的事情,在编译后改变IL).
我发现了一篇博文,指出:
var pfDir = Environment.GetFolderPath(Environment.SpecialFolders.ProgramFiles));
var sdkDir = Path.Combine(pfDir, @"Microsoft SDKs\Windows\v6.0A\bin");
...
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此代码时,目录不存在(主要是因为我的SDK版本是7.1),所以在我的本地机器上正确的路径是@"Microsoft SDKs\Windows\v7.1\bin".我怎样才能确保我能找到ildasm.exe?
同样,我发现了另一篇关于如何访问ilasm.exe的博文:
string windows = Environment.GetFolderPath(Environment.SpecialFolder.System);
string fwork = Path.Combine(windows, @"..\Microsoft.NET\Framework\v2.0.50727");
...
Run Code Online (Sandbox Code Playgroud)
虽然这有效,但我注意到我有Framework和Framework64,而在Framework本身中我拥有v4.0.30319的所有版本(与Framework64相同).那么,我怎么知道使用哪一个?它应该基于我正在瞄准的.NET Framework版本吗?
摘要:
阅读Adobe PDF 1.7(ISO 32000-1:2008)规范后,我仍然无法理解如何正确创建转换矩阵.
4.2/4.3节中的规范说明如下:
•翻译指定为[1 0 0 1 tx ty],其中tx和ty分别是在水平和垂直维度上平移坐标系原点的距离.
•通过[sx 0 0 sy 0 0]获得缩放.这缩放坐标,使得新坐标系的水平和垂直维度中的1个单位分别与先前坐标系中的sx和sy单位的大小相同.
•旋转由[cosθsinθ-sinθcosθ00]产生,其具有使坐标系轴逆时针旋转角度θ的效果.
•斜率由[1tanαtanβ10 0]指定,它将x轴倾斜角度α,将y轴倾斜角度β.
鉴于此,一个人如何按顺序使用转换?
我可以成功地使用Translation和Rotation一起,但当我尝试也使用Scaling或Skewing事情严重错误.也许我错误地使用了CTM,甚至我的数学都没有.我试图在坐标位置(50,50)创建文本,旋转45度,缩放2(按此顺序).我之所以说" 按此顺序 "是因为规范声明转换的顺序有所不同(规范给出了基于转换排序的差异的图形示例).那么流对象会是什么样子和/或矩阵数学如何适用于此?
工作((50,50)+ 45度旋转的转换)
[ 1 0 0 ] [ 0.707 0.707 0 ] [ 0.707 0.707 0 ]
[ 0 1 0 ] x [ -0.707 0.707 0 ] = [ -0.707 0.707 0 ]
[ 50 50 1 ] [ 0 0 1 ] [ 50.000 …Run Code Online (Sandbox Code Playgroud) 基本上,我正在寻找有关如何对WPF自定义控件进行单元测试的资源/指南.
在这个特定的实例中,我创建的自定义控件恰好扩展了Decorator类.它包装一个PasswordBox子项以将CLR密码属性公开为DependencyProperty.
public class BindablePasswordBox : Decorator
{
public BindablePasswordBox()
{
Child = new PasswordBox();
((PasswordBox)Child).PasswordChanged += this.PasswordChanged;
}
public static readonly DependencyProperty PasswordProperty =
DependencyProperty.Register("Password", typeof(String), typeof(BindablePasswordBox),
new FrameworkPropertyMetadata
{
BindsTwoWayByDefault = true,
DefaultUpdateSourceTrigger = UpdateSourceTrigger.LostFocus
});
public String Password
{
get { return (String)GetValue(PasswordProperty); }
set { SetValue(PasswordProperty, value); }
}
void PasswordChanged(Object sender, RoutedEventArgs e)
{
Password = ((PasswordBox)Child).Password;
}
}
Run Code Online (Sandbox Code Playgroud)
PS我正在使用内置的Visual Studio Testing Framework(Microsoft.VisualStudio.QualityTools.UnitTestFramework).
为了避免在内存中暴露明文密码的反对:我明白我通过在DependencyProperty中公开明文密码来反对微软的安全推理,但考虑到我能够使用Snoop从标准PasswordBox中公开明文密码再也找不到那么重要了.
根据MSDN - Panel.InternalChildren属性:
从Panel派生的类 应该使用此属性而不是Children 属性来进行内部重写,例如MeasureCore 和ArrangeCore.
所以,这实际上是一个2部分的问题:
如果我创建了一个我自己的Panel FooPanel,它来自Panel,我似乎无法覆盖MeasureCore或ArrangeCore.我不确定为什么那句话甚至存在.但是,我可以覆盖MeasureOverride和ArrangeOverride.所以,我想知道我是否还需要使用InternalChildren这两种方法的属性.
Children物业和InternalChildren物业之间的真正区别是什么?
c# ×5
wpf ×4
.net ×2
data-binding ×2
generics ×2
ca1704 ×1
casing ×1
children ×1
collections ×1
combobox ×1
dll ×1
dllimport ×1
filepath ×1
fxcop ×1
icomparable ×1
ilasm ×1
ildasm ×1
itemtemplate ×1
matrix ×1
nullable ×1
panel ×1
pdf ×1
reference ×1
unit-testing ×1
wpfdatagrid ×1