From 7d396f9d8a937ebfd7e27d7b253b11c47038491e Mon Sep 17 00:00:00 2001 From: csharptest Date: Mon, 8 Nov 2010 20:06:46 -0600 Subject: Testing and related fixes --- src/ProtocolBuffers/GeneratedExtensionLite.cs | 34 ++++++++------------------- 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'src/ProtocolBuffers/GeneratedExtensionLite.cs') diff --git a/src/ProtocolBuffers/GeneratedExtensionLite.cs b/src/ProtocolBuffers/GeneratedExtensionLite.cs index 87009cf8..a26088f8 100644 --- a/src/ProtocolBuffers/GeneratedExtensionLite.cs +++ b/src/ProtocolBuffers/GeneratedExtensionLite.cs @@ -44,25 +44,10 @@ namespace Google.ProtocolBuffers { int Number { get; } object ContainingType { get; } IMessageLite MessageDefaultInstance { get; } + IFieldDescriptorLite Descriptor { get; } } public class ExtensionDescriptorLite : IFieldDescriptorLite { - /// - /// Immutable mapping from field type to mapped type. Built using the attributes on - /// FieldType values. - /// - public static readonly IDictionary FieldTypeToMappedTypeMap = MapFieldTypes(); - - private static IDictionary MapFieldTypes() { - var map = new Dictionary(); - foreach (System.Reflection.FieldInfo field in typeof(FieldType).GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public)) { - FieldType fieldType = (FieldType)field.GetValue(null); - FieldMappingAttribute mapping = (FieldMappingAttribute)field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0]; - map[fieldType] = mapping.MappedType; - } - return Dictionaries.AsReadOnly(map); - } - private readonly IEnumLiteMap enumTypeMap; private readonly int number; private readonly FieldType type; @@ -75,7 +60,7 @@ namespace Google.ProtocolBuffers { this.enumTypeMap = enumTypeMap; this.number = number; this.type = type; - this.mapType = FieldTypeToMappedTypeMap[type]; + this.mapType = FieldMappingAttribute.MappedTypeFromFieldType(type); this.isRepeated = isRepeated; this.isPacked = isPacked; this.defaultValue = defaultValue; @@ -99,7 +84,7 @@ namespace Google.ProtocolBuffers { #warning ToDo - Discover the meaning and purpose of this durring serialization and return the correct value public bool MessageSetWireFormat { - get { return true; } + get { return false; } } public int FieldNumber { @@ -135,11 +120,11 @@ namespace Google.ProtocolBuffers { } public override object ToReflectionType(object value) { - IList result = new List(); - foreach (object element in (IEnumerable)value) { - result.Add((TExtensionType)SingularToReflectionType(element)); - } - return result; + IList result = new List(); + foreach (object element in (IEnumerable) value) { + result.Add(SingularToReflectionType(element)); + } + return result; } public override object FromReflectionType(object value) { @@ -191,6 +176,7 @@ namespace Google.ProtocolBuffers { false /* isRepeated */, false /* isPacked */)) { } + private static readonly IList Empty = new object[0]; /** Repeating fields: For use by generated code only. */ protected GeneratedExtensionLite( TContainingType containingTypeDefaultInstance, @@ -201,7 +187,7 @@ namespace Google.ProtocolBuffers { FieldType type, bool isPacked) : this(containingTypeDefaultInstance, defaultValue, messageDefaultInstance, - new ExtensionDescriptorLite(enumTypeMap, number, type, defaultValue, + new ExtensionDescriptorLite(enumTypeMap, number, type, Empty, true /* isRepeated */, isPacked)) { } -- cgit v1.2.3