From 16f919acbf0f5008c9008ea292dd8a6dceee6cc8 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 17 Jan 2009 19:54:38 -0800 Subject: [PATCH] Added support for message types to contain const fields to represent message parts that should have a constant value. --- src/DotNetOpenAuth/Messaging/Reflection/MessageDescription.cs | 2 +- src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/DotNetOpenAuth/Messaging/Reflection/MessageDescription.cs b/src/DotNetOpenAuth/Messaging/Reflection/MessageDescription.cs index e10311f..dcd5b9c 100644 --- a/src/DotNetOpenAuth/Messaging/Reflection/MessageDescription.cs +++ b/src/DotNetOpenAuth/Messaging/Reflection/MessageDescription.cs @@ -94,7 +94,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { Type currentType = this.messageTypeAndVersion.Type; do { - foreach (MemberInfo member in currentType.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) { + foreach (MemberInfo member in currentType.GetMembers(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) { if (member is PropertyInfo || member is FieldInfo) { MessagePartAttribute partAttribute = (from a in member.GetCustomAttributes(typeof(MessagePartAttribute), true).OfType() diff --git a/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs b/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs index 6cd2c02..3a1432a 100644 --- a/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs +++ b/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs @@ -117,7 +117,11 @@ namespace DotNetOpenAuth.Messaging.Reflection { str => encoder.Decode(str)); } - if (this.field != null && (this.field.Attributes & FieldAttributes.InitOnly) != 0) { + // readonly and const fields are considered legal, and "constants" for message transport. + FieldAttributes constAttributes = FieldAttributes.Static | FieldAttributes.Literal | FieldAttributes.HasDefault; + if (this.field != null && ( + (this.field.Attributes & FieldAttributes.InitOnly) == FieldAttributes.InitOnly || + (this.field.Attributes & constAttributes) == constAttributes)) { this.IsConstantValue = true; } else if (this.property != null && !this.property.CanWrite) { this.IsConstantValue = true; -- 2.11.4.GIT