public void GetItemForMember_NoAttribute() { Setup(); var ctx = new IntermediateMappingContext(); var member = typeof(ClassWithSkippableItem).GetProperty(nameof(ClassWithSkippableItem.Skippable)); Assert.IsNull(IntermediateReflectionMapper.GetItemForMember(ref ctx, member)); }
static void AddMembers(ref IntermediateMappingContext ctx, MemberInfo[] members, List <IntermediateItem> dest) { for (int i = 0; i < members.Length; i++) { IntermediateItem?newItem = GetItemForMember(ref ctx, members[i]); if (newItem != null) { dest.Add(newItem); } } }
public void ProcessItemAttributes() { Setup(); var ctx = new IntermediateMappingContext(); var member = typeof(VersionedClass).GetProperty(nameof(VersionedClass.B)); var item = IntermediateReflectionMapper.GetItemForMember(ref ctx, member); Assert.AreEqual(1, item.Order); Assert.AreEqual(1u, item.StartVer); Assert.AreEqual(2u, item.EndVer); }
public static IntermediateItem[] FillInfo(ref IntermediateMappingContext ctx) { BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly; Type? classType = ctx.ClassType; // Get the members FieldInfo[] currentFields = GetFields(bindingFlags, classType, ctx.Mode); PropertyInfo[] currentProperties = GetProperties(bindingFlags, classType, ctx.Mode); // Process the members var dest = new List <IntermediateItem>(currentFields.Length + currentProperties.Length); AddMembers(ref ctx, currentFields, dest); AddMembers(ref ctx, currentProperties, dest); return(dest.ToArray()); }
public void FillMainInfo_CorrectHighestVersion_CustomHighs() { var ctx = new IntermediateMappingContext(); IntermediateItem info = new IntermediateItem(); IntermediateMapper.FillMainInfo(info, 3, 6, 7); IntermediateMapper.UpdateContextFromItem(ref ctx, info); IntermediateMapper.FillMainInfo(info, 5, 8, 34); IntermediateMapper.UpdateContextFromItem(ref ctx, info); IntermediateMapper.FillMainInfo(info, 9, 11, 59); IntermediateMapper.UpdateContextFromItem(ref ctx, info); Assert.AreEqual(9, ctx.TranslationCurrentOrderInfo); Assert.AreEqual(59u, ctx.HighestVersion); }
public void FillMainInfo_CorrectOrderInfo_Ordered() { Setup(); var ctx = new IntermediateMappingContext(); IntermediateItem info = new IntermediateItem(); IntermediateMapper.FillMainInfo(info, 3, 0, uint.MaxValue); IntermediateMapper.UpdateContextFromItem(ref ctx, info); IntermediateMapper.FillMainInfo(info, 5, 0, uint.MaxValue); IntermediateMapper.UpdateContextFromItem(ref ctx, info); IntermediateMapper.FillMainInfo(info, 9, 0, uint.MaxValue); IntermediateMapper.UpdateContextFromItem(ref ctx, info); Assert.AreEqual(9, ctx.TranslationCurrentOrderInfo); }
internal static IntermediateItem?GetItemForMember(ref IntermediateMappingContext ctx, MemberInfo info) { // Get the attributes - skip this item if there are none object[]? attributes = info.GetCustomAttributes(typeof(SaveAttribute), false); if (attributes.Length == 0) { return(null); } var newItem = new IntermediateItem(); // Create the item. bool successful = FillItemFromAttributes(newItem, info, attributes); if (!successful) { throw new IncompleteDetailsException(info); } IntermediateMapper.UpdateContextFromItem(ref ctx, newItem); return(newItem); }