internal static object CreateTriggerFromDefaultTriggerAttribute(IEnumerable attributes, Type targetType) { List <Type> results1; List <Type> results2; List <object[]> results3; if (PlatformNeutralAttributeHelper.TryGetAttributeValues <Type>(attributes, ProjectNeutralTypes.DefaultTriggerAttribute, "TargetType", out results1) && PlatformNeutralAttributeHelper.TryGetAttributeValues <Type>(attributes, ProjectNeutralTypes.DefaultTriggerAttribute, "TriggerType", out results2) && PlatformNeutralAttributeHelper.TryGetAttributeValues <object[]>(attributes, ProjectNeutralTypes.DefaultTriggerAttribute, "Parameters", out results3)) { int index1 = -1; for (int index2 = 0; index2 < results1.Count; ++index2) { Type c = results1[index2]; if (c.IsAssignableFrom(targetType) && (index1 < 0 || results1[index1].IsAssignableFrom(c) && !c.IsAssignableFrom(results1[index1]))) { index1 = index2; } } if (index1 >= 0) { try { return(Activator.CreateInstance(results2[index1], results3[index1])); } catch { } } } return((object)null); }
public static bool IsSceneNodeValidHost(SceneNode candidateNode, IType constrainedIType) { if (ProjectNeutralTypes.BehaviorEventTriggerBase.IsAssignableFrom((ITypeId)constrainedIType) || ProjectNeutralTypes.BehaviorTargetedTriggerAction.IsAssignableFrom((ITypeId)constrainedIType)) { if (!candidateNode.Platform.Metadata.IsCapabilitySet(PlatformCapability.SupportsAttachingToRootElements) && candidateNode.ViewModel.ActiveEditingContainer.Equals((object)candidateNode)) { return(false); } Type result; if (PlatformNeutralAttributeHelper.TryGetAttributeValue <Type>((IEnumerable)TypeUtilities.GetAttributes(constrainedIType.RuntimeType), ProjectNeutralTypes.TypeConstraintAttribute, "Constraint", out result)) { return(candidateNode.ProjectContext.GetType(result).IsAssignableFrom((ITypeId)candidateNode.Type)); } return(true); } Type runtimeType1 = candidateNode.ProjectContext.ResolveType(ProjectNeutralTypes.Behavior).RuntimeType; Type runtimeType2 = candidateNode.ProjectContext.ResolveType(ProjectNeutralTypes.BehaviorTriggerBase).RuntimeType; Type runtimeType3 = candidateNode.ProjectContext.ResolveType(ProjectNeutralTypes.BehaviorTriggerAction).RuntimeType; Type type = constrainedIType.RuntimeType; while (type != (Type)null && type.BaseType != (Type)null && (!type.BaseType.Equals(runtimeType1) && !type.BaseType.Equals(runtimeType2)) && !type.BaseType.Equals(runtimeType3)) { type = type.BaseType; } Type[] genericArguments = type.GetGenericArguments(); return(candidateNode.ProjectContext.GetType(genericArguments[0]).IsAssignableFrom((ITypeId)candidateNode.Type)); }
public static PropertyValueEditor GetCustomPropertyValueEditor(PropertyReferenceProperty property) { PropertyValueEditor propertyValueEditor = (PropertyValueEditor)null; object result; if (PlatformNeutralAttributeHelper.TryGetAttributeValue <object>((IEnumerable)property.Attributes, ProjectNeutralTypes.CustomPropertyValueEditorAttribute, "CustomPropertyValueEditor", out result)) { switch (Enum.GetName(property.PropertyTypeId.PlatformMetadata.ResolveType(ProjectNeutralTypes.CustomPropertyValueEditor).RuntimeType, result)) { case "Element": propertyValueEditor = (PropertyValueEditor) new ElementPickerPropertyValueEditor(); break; case "Storyboard": propertyValueEditor = (PropertyValueEditor) new StoryboardPickerPropertyValueEditor(); break; case "StateName": propertyValueEditor = (PropertyValueEditor) new StatePickerPropertyValueEditor(); break; case "ElementBinding": propertyValueEditor = (PropertyValueEditor) new ElementBindingPickerPropertyValueEditor(); break; case "PropertyBinding": propertyValueEditor = (PropertyValueEditor) new PropertyBindingPickerPropertyValueEditor(); break; } } return(propertyValueEditor); }
public static SceneNode CreateTrigger(SceneNode targetNode, IType triggerType) { ProjectContext projectContext = ProjectContext.GetProjectContext(targetNode.ProjectContext); BehaviorHelper.EnsureSystemWindowsInteractivityReferenced((ITypeResolver)projectContext); targetNode.DesignerContext.ViewUpdateManager.RebuildPostponedViews(); using (SceneEditTransaction editTransaction = targetNode.ViewModel.CreateEditTransaction(StringTable.CreateTriggerActionUndoString)) { SceneNode sceneNode1 = targetNode; ISceneNodeCollection <SceneNode> collectionForProperty = sceneNode1.GetCollectionForProperty(BehaviorHelper.BehaviorTriggersProperty); BehaviorTriggerBaseNode behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)null; SceneViewModel viewModel = targetNode.ViewModel; object triggerAttribute = BehaviorHelper.CreateTriggerFromDefaultTriggerAttribute((IEnumerable)TypeUtilities.GetAttributes(triggerType.RuntimeType), targetNode.TargetType); if (triggerAttribute != null) { behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)viewModel.CreateSceneNode(triggerAttribute); } if (behaviorTriggerBaseNode == null) { BehaviorEventTriggerNode eventTriggerNode = (BehaviorEventTriggerNode)sceneNode1.ViewModel.CreateSceneNode(ProjectNeutralTypes.BehaviorEventTrigger); string result; if (!PlatformNeutralAttributeHelper.TryGetAttributeValue <string>(targetNode.TargetType, PlatformTypes.DefaultEventAttribute, "Name", out result)) { result = "Loaded"; } eventTriggerNode.EventName = result; behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)eventTriggerNode; } bool flag = false; viewModel.BehaviorSelectionSet.Clear(); foreach (SceneNode sceneNode2 in (IEnumerable <SceneNode>)collectionForProperty) { if (BehaviorHelper.CompareTriggerNodes(behaviorTriggerBaseNode.DocumentNode as DocumentCompositeNode, sceneNode2.DocumentNode as DocumentCompositeNode)) { behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)sceneNode2; flag = true; break; } } if (!flag) { collectionForProperty.Add((SceneNode)behaviorTriggerBaseNode); } BehaviorTriggerActionNode triggerActionNode = (BehaviorTriggerActionNode)sceneNode1.ViewModel.CreateSceneNode((ITypeId)triggerType); if (projectContext.IsCapabilitySet(PlatformCapability.SupportsAttachingToRootElements) && ProjectNeutralTypes.BehaviorTargetedTriggerAction.IsAssignableFrom((ITypeId)triggerActionNode.Type) && targetNode.ViewModel.ActiveEditingContainer.Equals((object)targetNode)) { IProperty property = projectContext.ResolveProperty(BehaviorTargetedTriggerActionNode.BehaviorTargetObjectProperty); if (property != null) { BehaviorHelper.CreateAndSetElementNameBinding((IPropertyId)property, (SceneNode)triggerActionNode, targetNode); } } behaviorTriggerBaseNode.Actions.Add((SceneNode)triggerActionNode); viewModel.BehaviorSelectionSet.SetSelection((BehaviorBaseNode)triggerActionNode); editTransaction.Commit(); return((SceneNode)triggerActionNode); } }
public static string GetDescription(Type type) { string result = (string)null; if (type != (Type)null) { PlatformNeutralAttributeHelper.TryGetAttributeValue <string>(type, PlatformTypes.DescriptionAttribute, "Description", out result); } return(result); }
private static ReferenceStep GetDefaultBindingPropertyInternal(IType type, IProjectContext projectContext) { if (type.RuntimeType == (Type)null) { return((ReferenceStep)null); } string result; if (!PlatformNeutralAttributeHelper.TryGetAttributeValue <string>(type.RuntimeType, PlatformTypes.DefaultBindingPropertyAttribute, "Name", out result) || string.IsNullOrEmpty(result)) { return((ReferenceStep)null); } MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess((ITypeResolver)projectContext, type); return(type.GetMember(MemberType.Property, result, allowableMemberAccess) as ReferenceStep); }
public override bool Verify(DocumentNode node) { DocumentCompositeNode compositeNode = node as DocumentCompositeNode; if (this.builder == null) { this.builder = new StateNameBuilder(this.designerContext); this.builder.Begin(); } if (compositeNode != null) { string referentialPropertyValue = this.GetReferentialPropertyValue(compositeNode); DocumentNode targetElement = GoToStateActionNode.FindTargetElement(node, true); List <string> results; if (targetElement != null && (DocumentNodeUtilities.IsBinding(targetElement) && !GoToStateActionNode.CanResolveTargetFromBinding(targetElement) || Enumerable.Contains <string>(this.builder.GetStateNamesForNode(targetElement), referentialPropertyValue) || PlatformNeutralAttributeHelper.TryGetAttributeValues <string>((IEnumerable)TypeUtilities.GetAttributes(targetElement.TargetType), ProjectNeutralTypes.TemplateVisualStateAttribute, "Name", out results) && results.Contains(referentialPropertyValue))) { return(true); } } return(false); }
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(); } }
public static ChildPropertyTimelineItem CreateChildPropertyTimelineItem(TimelineItemManager timelineItemManager, IProperty key, ElementTimelineItem elementTimelineItem) { ChildPropertyTimelineItem propertyTimelineItem = (ChildPropertyTimelineItem)null; foreach (ChildPropertyTimelineItemFactory.ChildPropertyTimelineItemEntry timelineItemEntry in ChildPropertyTimelineItemFactory.childPropertyTimelineItemFactory) { if (key.Equals((object)timelineItemEntry.property)) { propertyTimelineItem = timelineItemEntry.creator(timelineItemManager, key, elementTimelineItem, timelineItemEntry.type); propertyTimelineItem.EnableSelection = timelineItemEntry.enableSelection; propertyTimelineItem.ExpandParentOnInsertion = timelineItemEntry.expandParentOnInsertion; break; } } if (propertyTimelineItem == null) { ReferenceStep referenceStep = key as ReferenceStep; bool isAlternateContent = referenceStep != null && (referenceStep.Attributes[typeof(AlternateContentPropertyAttribute)] != null || PlatformNeutralAttributeHelper.AttributeExists((IEnumerable)referenceStep.Attributes, PlatformTypes.AlternateContentPropertyAttribute)); propertyTimelineItem = new ChildPropertyTimelineItem(timelineItemManager, key, elementTimelineItem, ChildPropertyTimelineItemType.Default, isAlternateContent); } return(propertyTimelineItem); }