.net-2.0

.NET XML Serialization without <?xml> text declaration

寵の児 提交于 2019-12-17 10:46:11
问题 I'm trying to generate XML like this: <?xml version="1.0"?> <!DOCTYPE APIRequest SYSTEM "https://url"> <APIRequest> <Head> <Key>123</Key> </Head> <ObjectClass> <Field>Value</Field </ObjectClass> </APIRequest> I have a class (ObjectClass) decorated with XMLSerialization attributes like this: [XmlRoot("ObjectClass")] public class ObjectClass { [XmlElement("Field")] public string Field { get; set; } } And my really hacky intuitive thought to just get this working is to do this when I serialize:

.net: System.Web.Mail vs System.Net.Mail

丶灬走出姿态 提交于 2019-12-17 08:45:11
问题 I am considering converting a project that I've inherited from .net 1.1 to .net 2.0. The main warning I'm concerned about is that it wants me to switch from System.Web.Mail to using System.Net.Mail . I'm not ready to re-write all the components using the obsolete System.Web.Mail , so I'm curious to hear if any community members have had problems using it under .net 2.0? 回答1: System.Web.Mail is not a full .NET native implementation of the SMTP protocol. Instead, it uses the pre-existing COM

System.Web.Caching vs. Enterprise Library Caching Block

帅比萌擦擦* 提交于 2019-12-17 08:09:24
问题 For a .NET component that will be used in both web applications and rich client applications, there seem to be two obvious options for caching: System.Web.Caching or the Ent. Lib. Caching Block. What do you use? Why? System.Web.Caching Is this safe to use outside of web apps? I've seen mixed information, but I think the answer is maybe-kind-of-not-really. a KB article warning against 1.0 and 1.1 non web app use The 2.0 page has a comment that indicates it's OK: http://msdn.microsoft.com/en-us

System.ValueType Understanding

回眸只為那壹抹淺笑 提交于 2019-12-17 07:23:48
问题 I tried to create a ValueType. I understand that creating a struct would help me. I also tried to derive a type from System.ValueType which is an abstract class. But I got a compiler error message " .. cannot derive from special class System.ValueType " When I see the metadata of ValueType, it looks to be a regular abstract class. What made it special? Is it the C# compilor that senses it as special? If so, is it recommended as a rule for compiler design? I mean is it part of Common Language

XmlSerializer - There was an error reflecting type

独自空忆成欢 提交于 2019-12-17 07:02:56
问题 Using C# .NET 2.0, I have a composite data class that does have the [Serializable] attribute on it. I am creating an XMLSerializer class and passing that into the constructor: XmlSerializer serializer = new XmlSerializer(typeof(DataClass)); I am getting an exception saying: There was an error reflecting type. Inside the data class there is another composite object. Does this also need to have the [Serializable] attribute, or by having it on the top object, does it recursively apply it to all

Registry Watcher C#

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 06:38:35
问题 I'm a newbie to WMI and I need to implement RegistryValueChangeEvent in a C# service. I need an event handler that gets triggered each time any one of a set of registry values is changed. I want behavior similar to the FileSystemWatcher class's Changed event, but for registry values. If there's some other technique I could use to accomplish the same task, I'd appreciate that as well. My minimum requirement is that it be a better solution than what I have now: polling every 20 seconds and

Is there an alternative to string.Replace that is case-insensitive?

纵然是瞬间 提交于 2019-12-17 02:42:08
问题 I need to search a string and replace all occurrences of %FirstName% and %PolicyAmount% with a value pulled from a database. The problem is the capitalization of FirstName varies. That prevents me from using the String.Replace() method. I've seen web pages on the subject that suggest Regex.Replace(strInput, strToken, strReplaceWith, RegexOptions.IgnoreCase); However for some reason when I try and replace %PolicyAmount% with $0 , the replacement never takes place. I assume that it has

How do I send ctrl+c to a process in c#?

ぐ巨炮叔叔 提交于 2019-12-17 02:38:06
问题 I'm writing a wrapper class for a command line executable. This exe accepts input from stdin until I hit Ctrl+C in the command prompt shell, in which case it prints output to stdout based on the input. I want to simulate that Ctrl+C press in C# code, sending the kill command to a .NET Process object. I've tried calling Process.Kill() , but that doesn't seem to give me anything in the process's StandardOutput StreamReader . Might there be anything I'm not doing right? Here's the code I'm

How do I send ctrl+c to a process in c#?

泄露秘密 提交于 2019-12-17 02:38:04
问题 I'm writing a wrapper class for a command line executable. This exe accepts input from stdin until I hit Ctrl+C in the command prompt shell, in which case it prints output to stdout based on the input. I want to simulate that Ctrl+C press in C# code, sending the kill command to a .NET Process object. I've tried calling Process.Kill() , but that doesn't seem to give me anything in the process's StandardOutput StreamReader . Might there be anything I'm not doing right? Here's the code I'm

LINQ on the .NET 2.0 Runtime

天涯浪子 提交于 2019-12-17 00:24:32
问题 Can a LINQ enabled app run on a machine that only has the .NET 2.0 runtime installed? In theory, LINQ is nothing more than syntactic sugar, and the resulting IL code should look the same as it would have in .NET 2.0. How can I write LINQ without using the .NET 3.5 libraries? Will it run on .NET 2.0? 回答1: There are some "Hacks" that involve using a System.Core.dll from the 3.5 Framework to make it run with .net 2.0, but personally I would not want use such a somewhat shaky foundation. See here