private static void RunDesignModeValueProvider(object target, IPlatform platform, ValueTranslationService valueTranslationService, IType type, Type runtimeType, PropertyIdentifier property, ReferenceStep referenceStep, bool isFirstTime) { if (!runtimeType.IsAssignableFrom(target.GetType())) { return; } ModelItem modelItemForObject = DesignModeValueProviderService.GetModelItemForObject(platform, target); if (modelItemForObject == null) { return; } ReferenceStep referenceStep1 = (ReferenceStep)DesignTimeProperties.GetShadowProperty((IProperty)referenceStep, (ITypeId)type); try { object valueToSet; if (isFirstTime && !referenceStep1.IsSet(target)) { valueToSet = referenceStep.GetValue(target); referenceStep1.SetValue(target, valueToSet); } else { valueToSet = referenceStep1.GetValue(target); } referenceStep.SetValue(target, valueTranslationService.TranslatePropertyValue(runtimeType, modelItemForObject, property, valueToSet)); } catch (Exception ex) { } }
public ExtensibilityManager(SceneViewModel viewModel) { this.viewModel = viewModel; this.viewModel.EarlySceneUpdatePhase += new SceneUpdatePhaseEventHandler(this.OnViewModelEarlySceneUpdatePhase); this.viewModel.LateSceneUpdatePhase += new SceneUpdatePhaseEventHandler(this.OnViewModelLateSceneUpdatePhase); this.viewModel.ProjectContext.TypesChanged += new EventHandler <TypesChangedEventArgs>(this.OnProjectContextTypesChanged); this.editingContext = new EditingContext(); this.featureManager = new FeatureManager(this.editingContext); this.featureManager.MetadataProvider = (MetadataProviderCallback)((type, attributeType) => { List <object> list = new List <object>(); foreach (Attribute attribute in TypeUtilities.GetAttributes((MemberInfo)type, attributeType, true)) { list.Add((object)attribute); } return((IEnumerable <object>)list); }); this.modelService = new SceneNodeModelService(viewModel); this.featureManager.Context.Services.Publish(typeof(ModelService), (object)this.modelService); this.viewService = new SceneNodeViewService(viewModel); this.featureManager.Context.Services.Publish(typeof(ViewService), (object)this.viewService); SelectionOperations.Subscribe(this.editingContext, new SubscribeContextCallback <Microsoft.Windows.Design.Interaction.Selection>(this.OnUserSelectionChanged)); this.UpdateSelection(); this.featureManager.Context.Items.SetValue((ContextItem) new SelectionTool()); this.valueProviderService = new DesignModeValueProviderService(this.viewModel.ProjectContext.Platform, this.featureManager); if (this.viewModel.RootNode != null) { this.ProcessSubtree(this.viewModel.RootNode.DocumentNode); } this.viewModel.Closing += new EventHandler(this.OnViewModelClosing); }
public void OnInitialized(IInstanceBuilderContext context, ViewNode target, object instance) { if (instance != null && this.targetType.IsAssignableFrom(instance.GetType())) { ITypeResolver typeResolver = target.DocumentNode.TypeResolver; IPlatform platform = context.Platform; platform.ViewObjectFactory.Instantiate(instance).SetValue(typeResolver, typeResolver.ResolveProperty(DesignTimeProperties.InstanceBuilderContextProperty), (object)new WeakReference((object)context)); IDesignModeValueProviderContext valueProviderContext = context as IDesignModeValueProviderContext; if (valueProviderContext != null) { ValueTranslationService valueTranslationService = valueProviderContext.ValueTranslationService; foreach (PropertyIdentifier identifier in valueTranslationService.GetProperties(this.targetType)) { if (valueTranslationService.HasValueTranslation(this.targetType, identifier)) { ReferenceStep referenceStep = target.Type.GetMember(MemberType.Property, identifier.Name, MemberAccessTypes.All) as ReferenceStep; if (referenceStep != null) { if (!target.Properties.ContainsKey((IProperty)referenceStep)) { ReferenceStep referenceStep1 = (ReferenceStep)DesignTimeProperties.GetShadowProperty((IProperty)referenceStep, (ITypeId)target.Type); object valueToSet = referenceStep.GetValue(instance); if (typeResolver.IsCapabilitySet(PlatformCapability.IsWpf) || valueToSet != null) { referenceStep1.SetValue(instance, valueToSet); } } PropertyIdentifier localProperty = identifier; UIThreadDispatcherHelper.BeginInvoke(DispatcherPriority.Send, (Delegate)(o => { if (target.Parent != null) { DesignModeValueProviderService.RunDesignModeValueProvider(instance, platform, valueTranslationService, target.Type, this.targetType, localProperty, referenceStep, true); } return((object)null); }), (object)null); } } } } } if (!context.IsSerializationScope) { return; } this.builder.OnInitialized(context, target, instance); }
private void ValueTranslationServicePropertyInvalidated(object sender, PropertyInvalidatedEventArgs e) { ISceneNodeModelItem sceneNodeModelItem = e.Item as ISceneNodeModelItem; if (sceneNodeModelItem == null || sceneNodeModelItem.SceneNode == null) { return; } SceneNode sceneNode = sceneNodeModelItem.SceneNode; ReferenceStep referenceStep = sceneNode.Type.GetMember(MemberType.Property, e.InvalidatedProperty.Name, MemberAccessTypes.All) as ReferenceStep; if (sceneNode.ViewObject != null && sceneNode.ViewObject.PlatformSpecificObject != null && referenceStep != null) { DesignModeValueProviderService.RunDesignModeValueProvider(sceneNode.ViewObject.PlatformSpecificObject, this.platform, this.ValueTranslationService, sceneNode.Type, sceneNode.TrueTargetType, e.InvalidatedProperty, referenceStep, false); } else { sceneNode.ViewModel.DefaultView.InstanceBuilderContext.ViewNodeManager.Invalidate(sceneNode.DocumentNode, InstanceState.Invalid); } }
public void ProcessType(IType type) { Type runtimeType = type.RuntimeType; if (!Enumerable.Any <FeatureProvider>(this.featureManager.CreateFeatureProviders(typeof(DesignModeValueProvider), runtimeType))) { return; } IInstanceBuilder builder = this.platform.InstanceBuilderFactory.GetBuilder(runtimeType); if (!builder.BaseType.Equals(runtimeType)) { ++DesignModeValueProviderService.uniqueId; TypeBuilder typeBuilder = RuntimeGeneratedTypesHelper.RuntimeGeneratedTypesAssembly.DefineType(runtimeType.Name + (object)".CustomDesignTimeProperties" + (string)(object)DesignModeValueProviderService.uniqueId, TypeAttributes.Public); foreach (PropertyIdentifier propertyIdentifier in this.ValueTranslationService.GetProperties(runtimeType)) { ReferenceStep referenceStep = type.GetMember(MemberType.Property, propertyIdentifier.Name, MemberAccessTypes.All) as ReferenceStep; if (referenceStep != null) { string str1 = "Runtime" + (object)referenceStep.Name + (string)(object)DesignModeValueProviderService.uniqueId; MethodBuilder methodBuilder = typeBuilder.DefineMethod("Get" + str1, MethodAttributes.Public | MethodAttributes.Static, referenceStep.PropertyType.RuntimeType, new Type[1] { typeof(object) }); methodBuilder.GetILGenerator().Emit(OpCodes.Ret); CustomAttributeBuilder customBuilder1 = new CustomAttributeBuilder(typeof(DesignerSerializationVisibilityAttribute).GetConstructor(new Type[1] { typeof(DesignerSerializationVisibility) }), new object[1] { (object)DesignerSerializationVisibility.Hidden }); methodBuilder.SetCustomAttribute(customBuilder1); typeBuilder.DefineMethod("Set" + str1, MethodAttributes.Public | MethodAttributes.Static, (Type)null, new Type[2] { typeof(object), referenceStep.PropertyType.RuntimeType }).GetILGenerator().Emit(OpCodes.Ret); IType type1 = type.PlatformMetadata.ResolveType(PlatformTypes.TypeConverterAttribute); List <string> results; if (PlatformNeutralAttributeHelper.TryGetAttributeValues <string>((IEnumerable)referenceStep.GetCustomAttributes(type1.RuntimeType, false), (ITypeId)type1, "ConverterTypeName", out results)) { foreach (string str2 in results) { CustomAttributeBuilder customBuilder2 = new CustomAttributeBuilder(type1.RuntimeType.GetConstructor(new Type[1] { typeof(string) }), new object[1] { (object)str2 }); methodBuilder.SetCustomAttribute(customBuilder2); } } typeBuilder.DefineField(str1 + "Property", this.platform.Metadata.ResolveType(PlatformTypes.DependencyProperty).RuntimeType, FieldAttributes.Public | FieldAttributes.Static); } } IType shadowSourceDeclaringType = (IType) new DesignModeValueProviderService.ShadowPropertyType((IPlatformMetadata)this.platform.Metadata, typeBuilder.CreateType()); foreach (PropertyIdentifier propertyIdentifier in this.ValueTranslationService.GetProperties(runtimeType)) { ReferenceStep referenceStep = type.GetMember(MemberType.Property, propertyIdentifier.Name, MemberAccessTypes.All) as ReferenceStep; if (referenceStep != null) { string propertyName = "Runtime" + (object)referenceStep.Name + (string)(object)DesignModeValueProviderService.uniqueId; PropertyIdentifier localProperty = propertyIdentifier; ValueTranslationService valueTranslationService = this.ValueTranslationService; object obj = this.platform.Metadata.DesignTimeProperties.ExternalRegisterShadow(propertyName, shadowSourceDeclaringType, (IProperty)referenceStep, DesignerSerializationVisibility.Hidden, true, (DesignTimeProperties.PropertyChangeCallback)(o => DesignModeValueProviderService.RunDesignModeValueProvider(o, this.platform, valueTranslationService, type, runtimeType, localProperty, referenceStep, false))); shadowSourceDeclaringType.RuntimeType.GetField(propertyName + "Property", BindingFlags.Static | BindingFlags.Public).SetValue((object)null, obj); } } DesignModeValueProviderService.DesignModeValueProviderBuilder valueProviderBuilder = new DesignModeValueProviderService.DesignModeValueProviderBuilder(runtimeType, builder); this.instanceBuilders.Add(valueProviderBuilder); this.platform.InstanceBuilderFactory.Register((IInstanceBuilder)valueProviderBuilder); } else { DesignModeValueProviderService.DesignModeValueProviderBuilder valueProviderBuilder = builder as DesignModeValueProviderService.DesignModeValueProviderBuilder; if (valueProviderBuilder == null) { return; } valueProviderBuilder.AddReference(); } }