/// <summary> /// 构造一个属性的属性 /// </summary> /// <param name="Col"></param> /// <returns></returns> protected virtual string GeneratePropertyAttribute(Column Col) { if (Col.IsPrimaryKey) { PrimaryKeyMappingAttribute Attribute = new PrimaryKeyMappingAttribute(); Attribute.ColumnName = Col.Name; Attribute.PropertyName = GeneratePropertyName(Col); Attribute.FieldType = DataTypeConvert.ConvertToFieldType((ADOType)Col.ADOType); Attribute.FieldLength = (int)Col.FieldLength; Attribute.Remark = Col.Comment; return(String.Format(PropertyAttribute, "PrimaryKeyMapping", Attribute.ToString())); } else { FieldMappingAttribute Attribute = new FieldMappingAttribute(); Attribute.ColumnName = Col.Name; Attribute.PropertyName = GeneratePropertyName(Col); Attribute.FieldType = DataTypeConvert.ConvertToFieldType((ADOType)Col.ADOType);// Attribute.IsNullable = Col.CanBeNull; Attribute.FieldLength = (int)Col.FieldLength; Attribute.DefauleValue = Col.Expression; Attribute.Remark = Col.Comment; return(String.Format(PropertyAttribute, "FieldMapping", Attribute.ToString())); } }
public void FieldTypeToWireTypeMapping() { foreach (FieldInfo field in typeof(FieldType).GetFields(BindingFlags.Static | BindingFlags.Public)) { FieldType fieldType = (FieldType)field.GetValue(null); FieldMappingAttribute mapping = (FieldMappingAttribute)field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0]; Assert.AreEqual(mapping.WireType, WireFormat.GetWireType(fieldType)); } }
public ExtensionDescriptorLite(string fullName, IEnumLiteMap enumTypeMap, int number, FieldType type, object defaultValue, bool isRepeated, bool isPacked) { this.fullName = fullName; this.enumTypeMap = enumTypeMap; this.number = number; this.type = type; this.mapType = FieldMappingAttribute.MappedTypeFromFieldType(type); this.isRepeated = isRepeated; this.isPacked = isPacked; this.defaultValue = defaultValue; }
protected IEnumerable <FieldToPropertyMapping> GetFieldMappings() { var properties = typeof(TEntity).GetProperties(); foreach (var property in properties) { object[] spFieldMappingAttributes = property .GetCustomAttributes(typeof(FieldMappingAttribute), false); FieldMappingAttribute mapping = spFieldMappingAttributes .Cast <FieldMappingAttribute>() .FirstOrDefault(); if (mapping is null) { continue; } yield return(new FieldToPropertyMapping( mapping.FieldName, property, mapping.Converter, mapping.IsReadOnly)); } }
public void Process(FieldDef field, FieldMappingAttribute attribute) => ProcessMappingName(field, attribute.Name, ValidationRule.Field);
protected override bool ParseUnknownField(CodedInputStream input, ExtensionRegistry extensionRegistry, uint tag) { FieldSet extensions = MessageBeingBuilt.Extensions; WireFormat.WireType wireType = WireFormat.GetTagWireType(tag); int fieldNumber = WireFormat.GetTagFieldNumber(tag); IGeneratedExtensionLite extension = extensionRegistry[DefaultInstanceForType, fieldNumber]; bool unknown = false; bool packed = false; if (extension == null) { unknown = true; // Unknown field. } else if (wireType == FieldMappingAttribute.WireTypeFromFieldType(extension.Descriptor.FieldType, false /* isPacked */)) { packed = false; // Normal, unpacked value. } else if (extension.Descriptor.IsRepeated && //?? just returns true ?? extension.Descriptor.type.isPackable() && wireType == FieldMappingAttribute.WireTypeFromFieldType(extension.Descriptor.FieldType, true /* isPacked */)) { packed = true; // Packed value. } else { unknown = true; // Wrong wire type. } if (unknown) // Unknown field or wrong wire type. Skip. { return(input.SkipField(tag)); } if (packed) { int length = (int)Math.Min(int.MaxValue, input.ReadRawVarint32()); int limit = input.PushLimit(length); if (extension.Descriptor.FieldType == FieldType.Enum) { while (!input.ReachedLimit) { int rawValue = input.ReadEnum(); Object value = extension.Descriptor.EnumType.FindValueByNumber(rawValue); if (value == null) { // If the number isn't recognized as a valid value for this // enum, drop it (don't even add it to unknownFields). return(true); } extensions.AddRepeatedField(extension.Descriptor, value); } } else { while (!input.ReachedLimit) { Object value = input.ReadPrimitiveField(extension.Descriptor.FieldType); extensions.AddRepeatedField(extension.Descriptor, value); } } input.PopLimit(limit); } else { Object value; switch (extension.Descriptor.MappedType) { case MappedType.Message: { IBuilderLite subBuilder = null; if (!extension.Descriptor.IsRepeated) { IMessageLite existingValue = extensions[extension.Descriptor] as IMessageLite; if (existingValue != null) { subBuilder = existingValue.WeakToBuilder(); } } if (subBuilder == null) { subBuilder = extension.MessageDefaultInstance.WeakCreateBuilderForType(); } if (extension.Descriptor.FieldType == FieldType.Group) { input.ReadGroup(extension.Number, subBuilder, extensionRegistry); } else { input.ReadMessage(subBuilder, extensionRegistry); } value = subBuilder.WeakBuild(); break; } case MappedType.Enum: int rawValue = input.ReadEnum(); value = extension.Descriptor.EnumType.FindValueByNumber(rawValue); // If the number isn't recognized as a valid value for this enum, // drop it. if (value == null) { return(true); } break; default: value = input.ReadPrimitiveField(extension.Descriptor.FieldType); break; } if (extension.Descriptor.IsRepeated) { extensions.AddRepeatedField(extension.Descriptor, value); } else { extensions[extension.Descriptor] = value; } } return(true); }