public override void VisitSetItem(IEnumerable set, SetDescriptor descriptor, object item, ITypeDescriptor itemDescriptor) { if (ProcessObject(item, itemDescriptor.Type)) { return; } base.VisitSetItem(set, descriptor, item, itemDescriptor); }
/// <summary> /// Creates a new ISetDescriptor /// </summary> /// <param name="component"></param> /// <param name="model"></param> /// <param name="keyType"></param> /// <param name="url"></param> /// <param name="description"></param> /// <returns></returns> public static ISetDescriptor NewSetDescriptor(string component, string model, string keyType, string url, string description) { SetDescriptor _instance = new SetDescriptor(); _instance.Component = component; _instance.Model = model; _instance.KeyType = keyType; _instance.URL = url; _instance.Description = description; return(_instance); }
public override void VisitSetItem(IEnumerable set, SetDescriptor descriptor, object item, ITypeDescriptor itemDescriptor) { if (CurrentPath.Match(MemberPath)) { VisitAssetMember(item, itemDescriptor); } else { base.VisitSetItem(set, descriptor, item, itemDescriptor); } }
public override void VisitSet(IEnumerable set, SetDescriptor descriptor) { if (ShouldGenerateItemIdCollection(set)) { IEnumerator enumerator = (set as IEnumerable).GetEnumerator(); var itemIds = CollectionItemIdHelper.GetCollectionItemIds(set); while (enumerator.MoveNext()) { itemIds.Add(enumerator.Current, ItemId.New()); } } base.VisitSet(set, descriptor); }
public override void VisitSetItem(IEnumerable setObject, SetDescriptor descriptor, object item, ITypeDescriptor itemDescriptor) { base.VisitSetItem(setObject, descriptor, item, itemDescriptor); var assetReference = item as AssetReference; var attachedReference = AttachedReferenceManager.GetAttachedReference(item); if (assetReference != null) { AddLink(assetReference, (guid, location) => { var link = AssetReference.New(guid ?? assetReference.Id, location); descriptor.Add(setObject, link); return(link); }); } else if (attachedReference != null) { AddLink(attachedReference, (guid, location) => { object link = guid.HasValue && guid.Value != AssetId.Empty ? AttachedReferenceManager.CreateProxyObject(descriptor.ElementType, guid.Value, location) : null; descriptor.Add(setObject, link); return(link); }); } else if (item is UFile) { AddLink(item, (guid, location) => { var link = new UFile(location); descriptor.Add(setObject, link); return(link); }); } else if (item is UDirectory) { AddLink(item, (guid, location) => { var link = new UDirectory(location); descriptor.Add(setObject, link); return(link); }); } }
/// <summary> /// Tries to convert the <paramref name="sourceSet"/> to the type described by <paramref name="setDescriptor"/>. /// </summary> /// <param name="sourceSet"></param> /// <param name="setDescriptor"></param> /// <param name="convertedSet"></param> /// <returns><c>true</c> if the <paramref name="sourceSet"/> could be converted to the type described by <paramref name="setDescriptor"/>; otherwise, <c>false</c>.</returns> private static bool TryConvertSetData([NotNull] object sourceSet, [NotNull] SetDescriptor setDescriptor, out object convertedSet) { try { var sourceSetType = sourceSet.GetType(); // Already same type if (setDescriptor.Type == sourceSetType) { convertedSet = sourceSet; return(true); } convertedSet = Activator.CreateInstance(setDescriptor.Type, true); var sourceSetDescriptor = (ListDescriptor)TypeDescriptorFactory.Default.Find(sourceSetType); foreach (var item in EnumerateList(sourceSet, sourceSetDescriptor)) { object obj; if (!TypeConverterHelper.TryConvert(item, setDescriptor.ElementType, out obj)) { // (optimistic) try to convert the remaining items continue; } setDescriptor.Add(sourceSet, obj); } return(setDescriptor.GetCollectionCount(convertedSet) > 0); } catch (InvalidCastException) { } catch (InvalidOperationException) { } catch (FormatException) { } catch (NotSupportedException) { } catch (Exception ex) when(ex.InnerException is InvalidCastException) { } catch (Exception ex) when(ex.InnerException is InvalidOperationException) { } catch (Exception ex) when(ex.InnerException is FormatException) { } catch (Exception ex) when(ex.InnerException is NotSupportedException) { } // Incompatible type and no conversion available convertedSet = null; return(false); }
private static bool ConvertForSet(SetDescriptor setDescriptor, ref object data) { if (SetDescriptor.IsSet(data.GetType())) { if (!TryConvertSetData(data, setDescriptor, out data)) { return(false); } } else { object convertedData; if (!TypeConverterHelper.TryConvert(data, setDescriptor.ElementType, out convertedData)) { return(false); } var convertedCollection = Activator.CreateInstance(setDescriptor.Type, true); setDescriptor.Add(convertedCollection, convertedData); data = convertedCollection; } return(true); }
public override void VisitSet(IEnumerable set, SetDescriptor descriptor) { Fixup(set); base.VisitSet(set, descriptor); }
private static bool HasCollectionReference(Type type) { return(type.IsArray || ListDescriptor.IsList(type) || DictionaryDescriptor.IsDictionary(type) || SetDescriptor.IsSet(type) || OldCollectionDescriptor.IsCollection(type)); }