在利用Outlook com组件编程的时候发现,Outlook中接受的邮件的发件人的Email地址不能正确的获得,他的属性里面只有一个SenderName属性,(ol2003之前的版本).而网上的解决办法大多使用CDO。而且大部分代码使用VB写,迁移到csharp不知道如何去做。
郁闷了几个小时之后,终于找到了一个简单有效的解决版本。
具体做法是利用MailItem接口的replay()方法。得到reply后的mail对象,再从这个对象的Recipients获得Address,这个Address就是发件人的Email地址了。
具体的Csharp代码如下:
MSOutlook.MailItem replymail = olmail.Reply();
MSOutlook.Recipients rec = replymail.Recipients;
string from = string.Empty;
for (int i = 1; i <= rec.Count; i++) {
from += rec[i].Address + ";";
}
Track.WriteLine(from.Substring(0, from.Length - 1));
IsolatedStorageFile是MS推出的用来安全存储应用程序信息的一种安全方式。是信息持久化的理想的存储方式。
HashTable可以存储任意可以序列化的实例。So,如果将两种方式结合,就可以持久化任何可以序列化的实例到硬盘上面,而且是很安全。
[Serializable]
public class ApplicationStorage : Hashtable {
#region Private fields
// File name. Let us use the entry assembly name with .dat as the extension.
private string settingsFileName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name + ".dat";
#endregion
#region Constructor
// The default constructor.
public ApplicationStorage() {
LoadData();
}
// This constructor is required for deserializing our class from persistent storage.
protected ApplicationStorage(SerializationInfo info, StreamingContext context)
: base(info, context) {
}
#endregion
#region Private methods
private void LoadData() {
IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
if (isoStore.GetFileNames(settingsFileName).Length == 0) {
// File not exists. Let us NOT try to DeSerialize it.
return;
}
// Read the stream from Isolated Storage.
Stream stream = new IsolatedStorageFileStream(settingsFileName, FileMode.OpenOrCreate, isoStore);
if (stream != null) {
try {
// DeSerialize the Hashtable from stream.
IFormatter formatter = new BinaryFormatter();
Hashtable appData = (Hashtable)formatter.Deserialize(stream);
// Enumerate through the collection and load our base Hashtable.
IDictionaryEnumerator enumerator = appData.GetEnumerator();
while (enumerator.MoveNext()) {
this[enumerator.Key] = enumerator.Value;
}
}
finally {
// We are done with it.
stream.Close();
}
}
}
#endregion
#region Public Methods
public void ReLoad() {
LoadData();
}
/// <summary>
/// Saves the configuration data to the persistent storage.
/// </summary>
public void Save() {
// Open the stream from the IsolatedStorage.
IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
Stream stream = new IsolatedStorageFileStream(settingsFileName, FileMode.Create, isoStore);
if (stream != null) {
try {
// Serialize the Hashtable into the IsolatedStorage.
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, (Hashtable)this);
}
finally {
stream.Close();
}
}
}
#endregion
}
该类集成hashtable,因此拥有Hashtable 的功能,该类的两个重要方法,一个是Load 一个是Save。一个是将流序列化成对象,一个是将对象序列化为流。
用法如下:
ApplicationStorage storage = new ApplicationStorage();
if (storage["Key1"] != null) {
object ht = storage[Key1];
if (ht != null) {
...
}
}
其实就像hashtable 一样用啦!
1. After you. 你先请。
这是一句很常用的客套话,在进/出门,上车得场合你都可以表现一下。
2. I just couldn't help it. 我就是忍不住。
想想看,这样一个漂亮的句子可用于多少个场合?下面是随意举的一个例子:
I was deeply moved by the film and I cried and cried. I just couldn't help it.
3. Don't take it to heart. 别往心里去,别为此而忧虑伤神。
生活实例:This test isn't that important. Don't take it to heart.
4. We'd better be off. 我们该走了。It's getting late. We'd better be off .
5. Let's face it. 面对现实吧。常表明说话人不愿意逃避困难的现状。
参考例句:I know it's a difficult situation. Let's face it, OK?
6. Let's get started. 咱们开始干吧。
劝导别人时说:Don't just talk. Let's get started.
7. I'm really dead. 我真要累死了。
坦诚自己的感受时说:After all that work, I'm really dead.
8. I've done my best. 我已尽力了。
9. Is that so? 真是那样吗?常用在一个人听了一件事后表示惊讶、怀疑。
10. Don't play games with me! 别跟我耍花招!
11. I don't know for sure. 我不确切知道。例如:
Stranger:Could you tell me how to get to the town hall?
Tom:I don't know for sure. Maybe you could ask the policeman over there.
12. I'm not going to kid you. 我不是跟你开玩笑的。 例如:
Karin:You quit the job? You are kidding.
Jack:I'm not going to kid you. I'm serious.
13. That's something. 太好了,太棒了。例如:
A:I'm granted a full scholarship for this semester.
B:Congratulations. That's something.
14. Brilliant idea! 这主意真棒!这主意真高明!
15. Do you really mean it? 此话当真?例如:
Michael:Whenever you are short of money, just come to me.
David:Do you really mean it?
16. You are a great help. 你帮了大忙。
17. I couldn't be more sure. 我再也肯定不过。
18. I am behind you. 我支持你。
Whatever decision you're going to make, I am behind you.
19. I'm broke. 我身无分文。
20. Mind you! 请注意!听着!(也可仅用Mind。)
模范例句:Mind you! He's a very nice fellow though bad-tempered.
21. You can count on it. 你尽管相信好了,尽管放心。例如:
A:Do you think he will come to my birthday party?
B:You can count on it.
22. I never liked it anyway. 我一直不太喜欢这东西。
当朋友或同事不小心摔坏你的东西时就可以用上这句话给他一个台阶,打破尴尬局面:Oh, don't worry. I'm thinking of buying a new one. I never liked it anyway.
23. That depends. 看情况再说。例如:
I may go to the airport to meet her. But that depends.
24. Congratulations. 恭喜你,祝贺你。
25. Thanks anyway. 无论如何我还是得谢谢你。当别人尽力要帮助你却没帮成时,你就可以用这个短语表示谢意。
26. It's a deal. 一言为定。
Harry:Haven't seen you for ages. Let's have a get-together next week.
Jenny:It's a deal.
在写oba项目的时候,以前一直考虑的实体类中忽略了拥有子类的情况,该子类可能是很多类共用的。
例如:
class B {
private int x;
public int X {
get { return x; }
set { x = value; }
}
}
class A {
private B _b;
public B b {
get { return _b; }
set { _b = value; }
}
}
这种情况下:如果我得到一个A的实例a,(假定当获得a实例的时候b肯定不为null)我想给该实例的a.b.X利用反射进行赋值。实际编写如下:
static void SetValue(Object obj, string str, object value) {
object temp = obj;
object key = null;
PropertyInfo values = null;
string[] strs = str.Split('.');
int length = strs.Length;
if (length > 1) {
for (int i = 0; i < length; i++) {
key = temp;
PropertyInfo propinfo = temp.GetType().GetProperty(strs[i]);
object o = temp.GetType().InvokeMember(strs[i], BindingFlags.GetProperty, null, temp, null);
if (o == null) {
return;
}
temp = o;
if (i == length - 2) {
values = propinfo;
}
}
}
else {
}
values.SetValue(key, value, null);
}
TestDriven:
static void Main(string[] args) {
A a = new A();
B b = new B();
b.X = 1000;
a.b = b;
Type t = a.GetType();
PropertyInfo propinfo=t.GetProperty("b");
object o = t.InvokeMember("b", BindingFlags.GetProperty, null, a, null);
if (o != null) {
PropertyInfo propinfo2 = o.GetType().GetProperty("X");
propinfo2.SetValue(o, 1000000, null);
propinfo.SetValue(a, o, null);
}
SetValue(a, "b.X", 1233);
Console.Write(a.b.X);
Console.ReadLine();
}
最后得到该需求的通用写法。