public ConvertedViewIntersectionField( string fieldName, bool canRead, bool canWrite, TypeModel declaringTypeModel, PropertyInfoField originPropertyField, IFieldPath <ViewIntersectionModel, ViewIntersectionField> path, TryConvertDelegate <TSourceData, TDestinationData> tryConvertDelegate ) : base( fieldName, canRead, canWrite, typeof(TDestinationData), declaringTypeModel, originPropertyField ) { _path = path; _tryConvertDelegate = tryConvertDelegate; }
/// <summary> /// The try set values. /// </summary> /// <typeparam name="TAttribute"> the attribute type</typeparam> /// <param name="target">The target.</param> /// <param name="values">The values.</param> /// <param name="convertMethod"> The convert method.</param> /// <param name="missingParams">The missing params.</param> /// <param name="invalidParams">The invalid params.</param> /// <returns>true if successful.</returns> public static bool TrySetValues <TAttribute>(object target, IDictionary <byte, object> values, TryConvertDelegate <TAttribute> convertMethod, out List <ObjectMemberInfo <TAttribute> > missingParams, out List <ObjectMemberInfo <TAttribute> > invalidParams) where TAttribute : DataMemberAttribute { missingParams = null; invalidParams = null; foreach (ObjectMemberInfo <TAttribute> info in ObjectMemberInfoCache <TAttribute> .GetMembers(target.GetType())) { object obj2; if (!values.TryGetValue(info.MemberAttribute.Code, out obj2) || (obj2 == null)) { if (!info.MemberAttribute.IsOptional) { if (missingParams == null) { missingParams = new List <ObjectMemberInfo <TAttribute> >(); } missingParams.Add(info); } } else if (info.ValueType.IsInstanceOfType(obj2)) { info.SetValue(target, obj2); } else if (convertMethod(info, ref obj2) && info.ValueType.IsInstanceOfType(obj2)) { info.SetValue(target, obj2); } else { if (invalidParams == null) { invalidParams = new List <ObjectMemberInfo <TAttribute> >(); } invalidParams.Add(info); } } return(missingParams == null && invalidParams == null); }
public TryConvertDelegateFactory(TryConvertDelegate <TFrom, TTo> tryConvertDelegate) { _tryConvertDelegate = tryConvertDelegate; }