对于具有必须处理的内部数据结构的用户控件,将该代码添加到 .designer.cs 文件中的 Dispose 方法的正确位置是否正确,或者是否存在我们要使用的事件或其他内容?
编辑:这是一个winforms用户控件。
从注册表中,对于给定的文件类型,我得到一个包含以下内容的字符串:
"C:\Program Files\AppName\Executable.exe" /arg1 /arg2 /arg3
Run Code Online (Sandbox Code Playgroud)
或有时:
"C:\Program Files\AppName\Executable.exe" /arg1 /arg2 /arg3 "%1"
Run Code Online (Sandbox Code Playgroud)
为了让我执行这个程序,并传递一个文件名作为参数(我知道它接受),我是否必须自己解析这个字符串,或者是否有一个运行时类为我做这个?请注意,我不是要求处理两者之间是否有"%1"的区别,而是我需要拆分可执行文件的名称,分别获取命令行参数.
我尝试只是附加/注入文件的完整路径和文件的名称传递到上面的字符串并将整个shebang传递给Process.Start,但当然它只需要文件名作为单个参数,所以这不是工作.
基本上,上面必须像这样手动完成:
Process proc = new Process();
proc.StartInfo.FileName = @"C:\Program Files\AppName\Executable.exe";
proc.StartInfo.Arguments = "/arg1 /arg2 /arg3 \"" + fileName + "\"";
proc.Start();
Run Code Online (Sandbox Code Playgroud)
我尝试使用UseShellExecute,但这没有帮助.还有其他指针吗?
要清楚,我想要这个:
String commandPath = ReadFromRegistry();
String fullCommand = commandPath + " " + fileName; // assuming not %1
Process.Start(fullCommand); // <-- magic happens here
Run Code Online (Sandbox Code Playgroud) 通过一些练习来磨练我的二叉树技能,我决定实现一个splay树,如维基百科:Splay树中所述.
我没有得到的一件事是关于插入的部分.
它说:
首先,我们在splay树中搜索x.如果x尚不存在,那么我们将找不到它,而是它的父节点y.其次,我们对y执行一个splay操作,它将y移动到splay树的根.第三,我们以适当的方式将新节点x作为root插入.以这种方式,y是新根x的左或右子.
我的问题是:与文章中的其他例子相比,上述文字似乎过于简洁,为什么会这样?似乎这里遗漏了一些问题.例如,在将y节点向上扩展到根之后,我不能盲目地用x替换root,并将x作为左或右子进行处理.
我们假设树中不存在该值.
我有这棵树:
10
/ \
5 15
/ \ \
1 6 20
Run Code Online (Sandbox Code Playgroud)
我想插入8.通过上面的描述,我将找到6节点,并且在普通的二叉树中,8将被添加为6节点的右子节点,但是在这里我首先必须展开6节点到root:
6
/ \
5 10
/ \
1 15
\
20
Run Code Online (Sandbox Code Playgroud)
那么这两个中的任何一个都是明显错误的:
8 8
\ /
6 6
/ \ / \
5 10 5 10
/ \ / \
1 15 1 15
\ \
20 20
6 is not greater than 8 10 is not less than 8
Run Code Online (Sandbox Code Playgroud)
在我看来,首先进行splaying,然后以root身份正确添加新值的唯一方法意味着我必须检查以下条件(将splayed节点添加为新root的左子节点):
但是,如果我要拆分我显示的节点,通过选择正确的子节点并将其作为新节点的右子节点附加,我会得到:
8
/ \ …Run Code Online (Sandbox Code Playgroud) 我试图使用以下内容在C#中反序列化xml字符串
XmlSerializer serializer = new XmlSerializer(typeof(Application));
App = (Application)serializer.Deserialize(xmlString);
Run Code Online (Sandbox Code Playgroud)
当xml打印得非常好时,一切运行良好,但是当我将整个xml放在一行中时,反序列化会因错误而失败
XML文档中存在错误(1,2).名称不能以'.'开头.字符,十六进制值0x00.第1行,第2位."
我已经检查过xml是否有效.
任何人都知道可以做些什么来克服这个问题?
我正在寻找一个可能的解决方案,我可以添加ShapeMap.dll作为参考,但当我尝试添加引用时,我得到一个错误说明:
您无法添加对ShapeMap.dll的引用,因为它不是针对Silverlight运行时构建的.Silverlight项目仅适用于Silverlight程序集"
现在我该怎么做?
我正在尝试使用以下代码从localstorage加载json:
let
val = Storage.getItem "exercises" decodeExerciseList
in
({ model | exercises = val }, Cmd.none)
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个错误:第5和第6个分支case产生了不同类型的值. - 第5分支有这种类型:
( Model, Cmd Msg )
Run Code Online (Sandbox Code Playgroud)
但第六是:
( { exercise : Maybe Model.Exercise
, exercises : Task String (List Model.Exercise)
}
, Cmd msg
)
Run Code Online (Sandbox Code Playgroud)
我想也许这可能会有所帮助:
case val of
succeed -> ({ model | exercises = val }, Cmd.none)
fail -> ({model | exercises = []}, Cmd.none)
Run Code Online (Sandbox Code Playgroud)
但没有运气.在这种情况下,我得到了另一个错误:
第一和第二分支case产生不同类型的值. - 第一个分支有这种类型:
( { ..., exercises : Task String …Run Code Online (Sandbox Code Playgroud) When checking received calls on an interface I can do this:
void Main()
{
var logger = Substitute.For<ILogger>();
Test(logger);
logger.Received().Log(Arg.Any<string>());
}
public void Test(ILogger logger)
{
logger.Log("Test");
}
public interface ILogger
{
void Log(string message);
}
Run Code Online (Sandbox Code Playgroud)
If I comment out the logger.Log("Test"); call I get this:
ReceivedCallsException: Expected to receive a call matching:
Log(any String)
Actually received no matching calls.
However, I just recently discovered that NSubstitute can substitute for delegates. The question is, can I get it to check …
我们使用 Coverity 来分析 C# 代码是否存在缺陷。
我们有一些单元测试可以明确验证空参数是否得到正确处理。
这些被 Coverity 列为缺陷。如果这是 Microsoft 自己的代码分析,我们可以用 来标记执行 null 传递的方法[SuppressMessage(...)],Coverity 是否有类似的功能?
我们不想让代码变得混乱到让 Coverity 感到困惑。
这是给出此缺陷的示例代码片段:
[Test]
public void SomeRandomTest()
{
var obj = new SomeRandomObject();
Assert.Throws<ArgumentNullException>(() => obj.Method(null));
}
...
public class SomeRandomObject
{
public void Method(object value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
...
}
}
Run Code Online (Sandbox Code Playgroud)
显式错误显示为
显式 null 取消引用 (FORWARD_NULL)
var_deref_model:将 null 传递给 Method,该方法在检查 null 后抛出异常。
我有一些泛型类型,如下所示:
public struct Tuple<T1, T2> { ... }
public struct Tuple<T1, T2, T3> { ... }
etc.
Run Code Online (Sandbox Code Playgroud)
理论上这些应该能够将自己与相同类型的其他值进行比较,以便我可以编写以下类型的代码:
List<Tuple<Type, String>> l = new List<Tuple<Type, String>>();
l.Add(new Tuple<Type, String>(typeof(ISomeInterface), "123"));
if (l.Contains(new Tuple<Type, String>(typeof(ISomeOtherInterface), "123"))
...
Run Code Online (Sandbox Code Playgroud)
不幸的是,我的代码中存在一个错误,然后问题就变成了如何正确地执行此操作.
该bug与我的CompareTo>的实现有关,基本上如下所示:
Int32 result = HelperMethods.CompareTwoFields<T1>(_Value1, other._Value1);
if (result != 0)
return result;
Int32 result = HelperMethods.CompareTwoFields<T2>(_Value2, other._Value2);
if (result != 0)
return result;
return 0;
Run Code Online (Sandbox Code Playgroud)
HelperMethods.CompareTwoFields如下所示:
internal static Int32 CompareTwoFields<T>(T field1, T field2)
{
Int32 result = 0;
if (ReferenceEquals(field1, null) != ReferenceEquals(field2, null)) …Run Code Online (Sandbox Code Playgroud) 我在我正在使用的库中看到过这种定义.我对TObjectType:CSObject的位置感到疯狂.很明显,似乎我可以在约束中使用相同的时间,因为它可以工作和编译,但这究竟意味着什么?
public class CSList<TObjectType>: CSList, IList<TObjectType>, IList
where TObjectType: CSObject<TObjectType>
Run Code Online (Sandbox Code Playgroud) c# ×8
asp.net ×1
binary-tree ×1
compareto ×1
comparison ×1
controls ×1
coverity ×1
dispose ×1
elm ×1
generics ×1
icomparable ×1
idisposable ×1
nsubstitute ×1
shellexecute ×1
silverlight ×1
splay-tree ×1
wikipedia ×1
xml ×1