private ConversionResult TryListConversion(ConversionContext context) { var collectionTypeSpec = new SupportedCollectionTypeSpecification(); if (collectionTypeSpec.IsSatisfiedBy(context.DestinationPropertyType) == false || collectionTypeSpec.IsSatisfiedBy(context.Value)==false) return context.Unconverted(); var destColl = (IList)activate.CreateCollectionInstance(context.DestinationPropertyType,collectionTypeSpec.GetLength(context.Value)); var destElement = context.DestinationPropertyType.ElementType(); var srcList = (IEnumerable) context.Value; var enumerator = srcList.GetEnumerator(); int index = 0; while(enumerator.MoveNext()) { object element = enumerator.Current ?? destElement.DefaultValue(); destColl.AddElement(element,index++); } return context.Result(destColl); }
private object GetSourceValue(object src, IDescribeMappableProperty sourceProperty) { var collectionSpec = new SupportedCollectionTypeSpecification(); if (collectionSpec.IsSatisfiedBy(src) == false) { return(invoke.GetValue(sourceProperty.Name, src)); } return(collectionSpec.GetValue(src, sourceProperty as IDescribePropertyElement)); }
private object GetSourceValue(object src, IDescribeMappableProperty sourceProperty) { var collectionSpec = new SupportedCollectionTypeSpecification(); if (collectionSpec.IsSatisfiedBy(src) == false) { return invoke.GetValue(sourceProperty.Name, src); } return collectionSpec.GetValue(src, sourceProperty as IDescribePropertyElement); }
private object GetDestValue(object src, object dest, IDescribeMappableProperty destinationProperty) { var collectionSpec = new SupportedCollectionTypeSpecification(); if (collectionSpec.IsSatisfiedBy(src) == false) { if (collectionSpec.IsElement(destinationProperty)) { return(activate.CreateInstance(destinationProperty.PropertyType)); } return(invoke.GetValue(destinationProperty.Name, dest) ?? activate.CreateInstance(destinationProperty.PropertyType)); } return(activate.CreateCollectionInstance(destinationProperty.PropertyType, collectionSpec.GetLength(src))); }
private object GetDestValue(object src, object dest,IDescribeMappableProperty destinationProperty) { var collectionSpec = new SupportedCollectionTypeSpecification(); if (collectionSpec.IsSatisfiedBy(src) == false) { if (collectionSpec.IsElement(destinationProperty)) { return activate.CreateInstance(destinationProperty.PropertyType); } return invoke.GetValue(destinationProperty.Name, dest) ?? activate.CreateInstance(destinationProperty.PropertyType); } return activate.CreateCollectionInstance(destinationProperty.PropertyType, collectionSpec.GetLength(src)); }