public static IList GetListAdapter(object instance) { if (instance != null) { CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(instance.GetType()); if (adapterDescription != null) { return(adapterDescription.GetCollectionAdapter(instance) as IList); } } return(null); }
private static object CreateClrDataContext(DataSourceInfo dataSource, SceneViewModel viewModel) { DocumentNode sourceNode = dataSource.SourceNode; if (PlatformTypes.DataTemplate.IsAssignableFrom((ITypeId)sourceNode.Type)) { return((object)null); } object obj1 = (object)null; using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(viewModel.Document.DocumentContext, viewModel.DesignerContext)) { try { IInstanceBuilder builder = instanceBuilderContext.InstanceBuilderFactory.GetBuilder(sourceNode.TargetType); ViewNode viewNode = builder.GetViewNode((IInstanceBuilderContext)instanceBuilderContext, sourceNode); if (builder.Instantiate((IInstanceBuilderContext)instanceBuilderContext, viewNode)) { obj1 = DataContextEvaluator.GetEvaluatedValue(viewNode.Instance); } } catch { } } if (obj1 == null || string.IsNullOrEmpty(dataSource.Path)) { return(obj1); } object instance = obj1; try { IList <ClrPathPart> list1 = ClrPropertyPathHelper.SplitPath(dataSource.Path); if (list1 == null) { return((object)null); } for (int index = 0; index < list1.Count; ++index) { if (instance != null) { Type type = instance.GetType(); object obj2 = (object)null; ClrPathPart clrPathPart = list1[index]; if (clrPathPart.Category == ClrPathPartCategory.PropertyName) { PropertyInfo property = type.GetProperty(clrPathPart.Path); if (property != (PropertyInfo)null) { obj2 = property.GetValue(instance, (object[])null); } } else { CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(type); if (adapterDescription != null) { IList list2 = adapterDescription.GetCollectionAdapter(instance) as IList; if (list2 != null) { int result = 0; if (clrPathPart.Category == ClrPathPartCategory.IndexStep) { if (!int.TryParse(clrPathPart.Path.Trim('[', ']'), out result)) { goto label_23; } } obj2 = list2[result]; } } } label_23: instance = obj2; } else { break; } } } catch { instance = (object)null; } return(instance); }
private object ConvertInternalFast(object value, ITypeResolver sourceTypeResolver, ITypeResolver targetTypeResolver) { if (value == null) { return(value); } Type type = value.GetType(); IType platformType = ((IPlatformTypes)targetTypeResolver.PlatformMetadata).GetPlatformType(type.FullName); Type runtimeType = platformType.RuntimeType; object obj1; if (type.IsPrimitive || type.IsEnum) { if (runtimeType == (Type)null) { return((object)null); } if (runtimeType.Equals(type)) { obj1 = value; } else { TypeConverter typeConverter = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(type); obj1 = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(runtimeType).ConvertFromInvariantString(typeConverter.ConvertToInvariantString(value)); } } else { if (runtimeType == (Type)null) { return((object)null); } obj1 = InstanceBuilderOperations.InstantiateType(runtimeType, true); if (obj1 != null && PlatformTypes.ImageBrush.IsAssignableFrom((ITypeId)platformType)) { return(this.ConvertImageBrush(value, obj1, sourceTypeResolver, targetTypeResolver)); } if (!type.IsValueType) { CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(type); if (adapterDescription != null) { IList list = CollectionAdapterDescription.GetAdapterDescription(runtimeType).GetCollectionAdapter(obj1) as IList; foreach (object obj2 in (IEnumerable)adapterDescription.GetCollectionAdapter(value)) { object obj3 = this.ConvertInternalFast(obj2, sourceTypeResolver, targetTypeResolver); list.Add(obj3); } } } foreach (IProperty property in ((IPlatformTypes)sourceTypeResolver.PlatformMetadata).GetType(type).GetProperties(MemberAccessTypes.Public)) { ReferenceStep referenceStep1 = property as ReferenceStep; if (referenceStep1 != null && referenceStep1.ReadAccess == MemberAccessType.Public && referenceStep1.WriteAccess == MemberAccessType.Public) { ReferenceStep referenceStep2 = platformType.GetMember(MemberType.Property, referenceStep1.Name, MemberAccessTypes.Public) as ReferenceStep; if (referenceStep2 != null && referenceStep2.ReadAccess == MemberAccessType.Public && referenceStep2.WriteAccess == MemberAccessType.Public) { object valueToSet = this.ConvertInternalFast(referenceStep1.GetValue(value), sourceTypeResolver, targetTypeResolver); referenceStep2.SetValue(obj1, valueToSet); } } } } return(obj1); }