以下是我尝试过的内容和发生的事情的成绩单.
我正在寻找如何调用特定的重载以及解释为什么以下不起作用.如果您的答案是"您应该使用此命令行开关"或"两次调用",请在我不接受您的答案时理解.
PS C:\> [System.IO.Path]::Combine("C:\", "foo")
C:\foo
PS C:\> [System.IO.Path]::Combine("C:\", "foo", "bar")
Cannot find an overload for "Combine" and the argument count: "3".
At line:1 char:26
+ [System.IO.Path]::Combine <<<< ("C:\", "foo", "bar")
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
PS C:\> [System.IO.Path]::Combine(, "C:\", "foo", "bar")
Missing ')' in method call.
At line:1 char:27
+ [System.IO.Path]::Combine( <<<< , "C:\", "foo", "bar")
+ CategoryInfo : ParserError: (CloseParenToken:TokenId) [], Paren
tContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndParenthesisInMethodCall
PS C:\> [System.IO.Path]::Combine($("C:\", "foo", …Run Code Online (Sandbox Code Playgroud) 我有一个类,我正在序列化一些数据:
[Serializable]
public class SomeData {
public int NumericField;
public string StringField;
}
Run Code Online (Sandbox Code Playgroud)
我有一个很好的方便的扩展方法:
public static string ToJson<T> (this T value) {
// yay no compile-time checks for [Serializable]?
if (!typeof(T).IsSerializable)
throw new SerializationException("Object lacks [Serializable] attribute");
var serializer = new DataContractJsonSerializer(typeof(T));
using (var stream = new MemoryStream()) {
using (var writer = JsonReaderWriterFactory.CreateJsonWriter(stream, Encoding.UTF8)) {
serializer.WriteObject(writer, value);
}
return Encoding.UTF8.GetString(stream.ToArray());
}
}
Run Code Online (Sandbox Code Playgroud)
我真的很喜欢我的课程SomeData实现ISerializable,但是当我添加它时,我被告知我需要添加一个方法:
error CS0535: 'SomeData' does not implement interface member
System.Runtime.Serialization.ISerializable.GetObjectData(
System.Runtime.Serialization.SerializationInfo,
System.Runtime.Serialization.StreamingContext)'
Run Code Online (Sandbox Code Playgroud)
问题只是我希望它 …