public static object InstantiateTargetType(IAssembly projectAssembly, IInstanceBuilderContext context, Type type) { bool flag = (projectAssembly == null ? false : projectAssembly.CompareTo(type.Assembly)); IInstanceBuilder builder = context.InstanceBuilderFactory.GetBuilder(type); if (builder.ReplacementType == null) { return(InstanceBuilderOperations.InstantiateType(type, flag)); } return(InstanceBuilderOperations.InstantiateType(builder.ReplacementType, true)); }
private object ConvertImageBrush(object value, object result, ITypeResolver sourceTypeResolver, ITypeResolver targetTypeResolver) { ReferenceStep referenceStep1 = (ReferenceStep)sourceTypeResolver.ResolveProperty(TileBrushNode.StretchProperty); ReferenceStep referenceStep2 = (ReferenceStep)targetTypeResolver.ResolveProperty(TileBrushNode.StretchProperty); object valueToSet1 = this.ConvertInternalFast(referenceStep1.GetValue(value), sourceTypeResolver, targetTypeResolver); referenceStep2.SetValue(result, valueToSet1); object objToInspect = ((ReferenceStep)sourceTypeResolver.ResolveProperty(ImageBrushNode.ImageSourceProperty)).GetValue(value); if (!PlatformTypes.IsInstance(objToInspect, PlatformTypes.BitmapImage, sourceTypeResolver)) { return(result); } object obj1 = ((ReferenceStep)sourceTypeResolver.ResolveProperty(BitmapImageNode.UriSourceProperty)).GetValue(objToInspect); if (obj1 == null) { return(result); } Type type1 = obj1.GetType(); IType type2 = targetTypeResolver.ResolveType(PlatformTypes.Uri); string text = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(type1).ConvertToInvariantString(obj1); if (string.IsNullOrEmpty(text)) { return(result); } object valueToSet2 = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(type2.RuntimeType).ConvertFromInvariantString(text); ReferenceStep referenceStep3 = (ReferenceStep)targetTypeResolver.ResolveProperty(ImageBrushNode.ImageSourceProperty); object obj2 = InstanceBuilderOperations.InstantiateType(targetTypeResolver.ResolveType(PlatformTypes.BitmapImage).RuntimeType, true); referenceStep3.SetValue(result, obj2); try { BitmapImage bitmapImage = obj2 as BitmapImage; if (bitmapImage != null) { bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; } ((ReferenceStep)targetTypeResolver.ResolveProperty(BitmapImageNode.UriSourceProperty)).SetValue(obj2, valueToSet2); if (bitmapImage != null) { bitmapImage.EndInit(); } } catch (Exception ex) { result = (object)null; } return(result); }
private object ConvertInternal(object value, IDocumentContext sourcePlatformDocumentContext, IDocumentContext targetPlatformDocumentContext, PlatformConverter.ConvertToType convertType) { if (value == null) { return((object)null); } if (value == PlatformConverter.PortableUserInterfaceFont) { value = (object)new FontFamily(PlatformConverter.portableUserInterfaceString); } if (PlatformConverter.IsPlatformValue(value, targetPlatformDocumentContext)) { if (convertType == PlatformConverter.ConvertToType.DocumentNode) { return((object)targetPlatformDocumentContext.CreateNode(value.GetType(), value)); } return(value); } Type type1 = value.GetType(); if (convertType == PlatformConverter.ConvertToType.InstanceValue && PlatformConverter.CanUseFastConversion(type1)) { return(this.ConvertInternalFast(value, sourcePlatformDocumentContext.TypeResolver, targetPlatformDocumentContext.TypeResolver)); } SceneDocument activeDocument = this.designerContext.ActiveDocument; ((PurePlatformProjectContext)this.StandaloneWpfDocumentContext.TypeResolver).SetActualProjectContext(activeDocument != null ? activeDocument.ProjectContext : (IProjectContext)null); DocumentNode documentNode1 = value as DocumentNode; DocumentNode node; using (((IProjectContext)sourcePlatformDocumentContext.TypeResolver).Platform.DocumentNodeBuilderFactory.ForceBuildAnimatedValue) node = documentNode1 ?? sourcePlatformDocumentContext.CreateNode(value.GetType(), value); if (node == null) { return((object)null); } object obj = (object)null; IType type2 = node.Type; IType platformType = ((IPlatformTypes)targetPlatformDocumentContext.TypeResolver.PlatformMetadata).GetPlatformType(type2.FullName); if (node is DocumentPrimitiveNode) { if (convertType == PlatformConverter.ConvertToType.DocumentNode) { return((object)this.ConvertSubtree(node, sourcePlatformDocumentContext, targetPlatformDocumentContext)); } if (platformType == null || type2.TypeConverter == null || platformType.TypeConverter == null) { return((object)null); } DocumentPrimitiveNode documentPrimitiveNode1 = value as DocumentPrimitiveNode; string text; if (documentPrimitiveNode1 != null) { text = documentPrimitiveNode1.GetValue <string>(); } else { DocumentPrimitiveNode documentPrimitiveNode2 = node as DocumentPrimitiveNode; text = documentPrimitiveNode2 == null || !(documentPrimitiveNode2.Value is DocumentNodeStringValue) ? type2.TypeConverter.ConvertToString((ITypeDescriptorContext)null, CultureInfo.InvariantCulture, value) : documentPrimitiveNode2.GetValue <string>(); } try { obj = platformType.TypeConverter.ConvertFromString((ITypeDescriptorContext)null, CultureInfo.InvariantCulture, text); } catch { } } else { DocumentNode documentNode2 = this.ConvertSubtree(node, sourcePlatformDocumentContext, targetPlatformDocumentContext); if (convertType == PlatformConverter.ConvertToType.DocumentNode) { return((object)documentNode2); } if (documentNode2 != null) { DocumentNodePath documentNodePath = new DocumentNodePath(documentNode2, documentNode2); using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(targetPlatformDocumentContext, this.designerContext)) { instanceBuilderContext.ViewNodeManager.RootNodePath = documentNodePath; instanceBuilderContext.ViewNodeManager.Instantiate(instanceBuilderContext.ViewNodeManager.Root); using (instanceBuilderContext.DisablePostponedResourceEvaluation()) obj = instanceBuilderContext.ViewNodeManager.ValidRootInstance; instanceBuilderContext.ViewNodeManager.RootNodePath = (DocumentNodePath)null; } } } if (obj == null && platformType != null && (!platformType.SupportsNullValues && platformType.RuntimeType != (Type)null)) { obj = InstanceBuilderOperations.InstantiateType(platformType.RuntimeType, true); } return(obj); }
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); }