/// <summary> /// Creates any custom commands for this element based on it's <see cref="Attributes"/>. /// </summary> /// <returns></returns> protected IEnumerable <CommandModel> CreateCustomCommands() { foreach (var command in ContainingSection.CreateCustomCommands(this, Attributes)) { yield return(command); } }
/// <summary> /// Creates or collections all the commands related to this <see cref="ElementViewModel"/>. /// </summary> /// <returns></returns> protected override IEnumerable <CommandModel> GetAllCommands() { var baseCommands = base.CreateCustomCommands() .Union(GetPromotedCommands()); return(baseCommands.Union(new CommandModel[] { ContainingSection.CreateElementCollectionAddCommands(Attributes, this) })); }
public virtual IEnumerable <Validator> GetValidators() { var validations = GetDefaultPropertyValidators() .Union(Attributes.OfType <ValidationAttribute>() .Select(v => ContainingSection.CreateValidatorInstance(v.ValidatorType))); return(validations); }
protected override IEnumerable <Property> GetAllProperties() { return(base.GetAllProperties().Union( new Property[] { ContainingSection.CreateProperty <ProtectedKeySettingsProperty>( new ParameterOverride("configuration", ConfigurationElement)) })); }
private IEnumerable <CommandModel> GetOtherSectionCommands() { var overrides = new Dictionary <Type, object>() { { typeof(SectionViewModel), this } }; yield return(ContainingSection.CreateCommand <ToggleExpandedCommand>(overrides)); }
protected override IEnumerable <Property> GetAllProperties() { return(base.GetAllProperties() .Union(new Property[] { ContainingSection.CreateProperty <CustomTraceListenerFormatterProperty>( new DependencyOverride <ElementViewModel>(this), new DependencyOverride <PropertyDescriptor>(formatterPropertyDescriptor)) })); }
protected override IEnumerable <Property> GetAllProperties() { return(base.GetAllProperties() .Union(new Property[] { ContainingSection.CreateProperty <SystemDiagnosticInitDataProperty>( new DependencyOverride <ElementViewModel>(this), new DependencyOverride <PropertyDescriptor>(initDataPropertyDescriptor)) })); }
public PropertyElementViewModel(ElementCollectionViewModel containingCollection, ConfigurationElement thisElement) : base(containingCollection, thisElement) { var valueProperty = TypeDescriptor.GetProperties(typeof(PropertyElement)) .Cast <PropertyDescriptor>() .Where(x => x.Name == "Value") .First(); propertyValueProperty = ContainingSection.CreateProperty <ValueElementProperty>( new DependencyOverride <ElementViewModel>(this), new DependencyOverride <PropertyDescriptor>(valueProperty)); }
/// <summary> /// Gets all the <see cref="ElementViewModel"/> instances that are directly contained in this <see cref="ElementViewModel"/> instance. /// </summary> /// <returns> /// </returns> protected override IEnumerable <ElementViewModel> GetAllChildElements() { var leaf = base.GetAllChildElements(); var contained = thisElementCollection .OfType <ConfigurationElement>() .Select(x => new { Browasble = TypeDescriptor.GetAttributes(x).OfType <BrowsableAttribute>().FirstOrDefault(), Instance = x }) .Where(x => x.Browasble == null || x.Browasble.Browsable) .Select(x => ContainingSection.CreateCollectionElement(this, x.Instance)) .Cast <ElementViewModel>(); return(leaf.Union(contained)); }
/// <summary> /// Creates commands other than Add, Delete, or custom command specified via attribute, for this element. /// </summary> /// <returns> /// An enumerable containing instances of <see cref="ToggleShowPropertiesCommand"/> and <see cref="ValidateCommand"/>. /// </returns> protected IEnumerable <CommandModel> CreateOtherCommands() { yield return(ContainingSection.CreateCommand <ToggleShowPropertiesCommand>( new Dictionary <Type, object>() { { typeof(ElementViewModel), this } })); yield return(ContainingSection.CreateCommand <ValidateCommand>( new Dictionary <Type, object>() { { typeof(ElementViewModel), this } })); }
/// <summary> /// Initializes a new instance of <see cref="CollectionElementViewModel"/>. /// </summary> /// <param name="containingCollection">The collection containing this element.</param> /// <param name="thisElement">The <see cref="ConfigurationElement"/> modeled by the <see cref="CollectionElementViewModel"/>.</param> /// <param name="additionalAttributes">Additional <see cref="Attribute"/> items to apply when describing this <paramref name="thisElement"/>.</param> public CollectionElementViewModel(ElementCollectionViewModel containingCollection, ConfigurationElement thisElement, IEnumerable <Attribute> additionalAttributes) : base(containingCollection, thisElement, additionalAttributes) { this.containingCollection = containingCollection; configurationCollectionAttribute = containingCollection.Attributes.OfType <ConfigurationCollectionAttribute>().First(); var overrides = new Dictionary <Type, object>() { { typeof(ElementCollectionViewModel), containingCollection }, { typeof(CollectionElementViewModel), this } }; MoveUp = ContainingSection.CreateCommand <MoveUpCommand>(overrides); MoveDown = ContainingSection.CreateCommand <MoveDownCommand>(overrides); }
public RegisterElementViewModel(IServiceProvider serviceProvider, ElementCollectionViewModel containingCollection, ConfigurationElement thisElement) : base(containingCollection, thisElement) { registrationTypeDependentPropertyChangedHandler = new PropertyChangedEventHandler(RegistrationTypeDependentPropertyChanged); var lifetimeElementPropertyDescriptor = TypeDescriptor.GetProperties(thisElement). OfType <PropertyDescriptor>(). Where(x => x.Name == "Lifetime"). First(); lifetimeElementProperty = (LifetimeElementProperty)ContainingSection.CreateProperty( typeof(LifetimeElementProperty), new DependencyOverride <IServiceProvider>(serviceProvider), new DependencyOverride <ElementViewModel>(this), new DependencyOverride <PropertyDescriptor>(lifetimeElementPropertyDescriptor)); }
/// <summary> /// Retrieves child properties for this <see cref="Property"/>. /// </summary> /// <returns></returns> protected virtual IEnumerable <Property> GetChildProperties() { if (Converter == null) { return(Enumerable.Empty <Property>()); } var properties = Converter.GetProperties(this, Value); if (properties == null) { return(Enumerable.Empty <Property>()); } return(properties .OfType <PropertyDescriptor>() .Select(x => ContainingSection.CreateProperty(Value, x)).ToArray()); }
/// <summary> /// Adds a new item of type <paramref name="elementType"/> to the collection. /// </summary> /// <param name="elementType">The <see cref="Type"/> of element to add. It should be of, or derive from, the type indicated in <see cref="CollectionElementType"/>.</param> /// <returns>An <see cref="ElementViewModel"/> for the added type.</returns> public virtual ElementViewModel AddNewCollectionElement(Type elementType) { EnsureHasChildElements(); var element = mergeableConfigurationCollection.CreateNewElement(elementType); var childElementModel = ContainingSection.CreateCollectionElement(this, element); if (childElementModel.NameProperty != null) { childElementModel.NameProperty.Value = CalculateNameFromType(elementType); } // add the new element to the configuration. mergeableConfigurationCollection.ResetCollection( thisElementCollection.OfType <ConfigurationElement>() .Concat(new[] { element }) .ToArray()); foreach (var property in childElementModel.Properties) { DesigntimeDefaultAttribute defaultDesigntimeValue = property.Attributes.OfType <DesigntimeDefaultAttribute>().FirstOrDefault(); if (defaultDesigntimeValue != null) { property.Value = property.ConvertFromBindableValueInvariant(defaultDesigntimeValue.BindableDefaultValue); } } childElementModel.Initialize(new InitializeContext()); InitializeElementProperties(childElementModel); // add the new element to the view model. AddChildToView(childElementModel); Validate(); return(childElementModel); }
protected override IEnumerable <Property> GetChildProperties() { var properties = subject.Properties.Where(EnvironmentSourceViewModel.CanOverrideProperty) .Select(x => ContainingSection.CreateProperty(typeof(EnvironmentOverriddenProperty), new ParameterOverride("overridesProperty", this), new ParameterOverride("originalProperty", x), new ParameterOverride("overrides", new InjectionParameter <EnvironmentOverriddenElementPayload>(overrides)), new ParameterOverride("environment", environment))).ToArray(); SectionViewModel subjectAsSectionViewModel = subject as SectionViewModel; if (subjectAsSectionViewModel != null) { var protectionProviderProperty = subjectAsSectionViewModel.Properties.OfType <ProtectionProviderProperty>().FirstOrDefault(); var overriddenProtectionProviderProperty = ContainingSection.CreateProperty <OverriddenProtectionProviderProperty>( new DependencyOverride <ProtectionProviderProperty>(protectionProviderProperty), new DependencyOverride <EnvironmentOverriddenElementPayload>(overrides), new DependencyOverride <EnvironmentOverriddenElementProperty>(this)); properties = properties.Union(new Property[] { overriddenProtectionProviderProperty }).ToArray(); } return(properties); }
public IEnumerable <Property> GetExtendedProperties(ElementViewModel subject) { var overriddenElementReference = overriddenElements.Where(x => x.ElementId == subject.ElementId).FirstOrDefault(); if (overriddenElementReference == null) { overriddenElementReference = new EnvironmentOverriddenElementReference(elementLookup, environmentSection); overriddenElementReference.InitializeWithElementViewModel(subject); overriddenElements.Add(overriddenElementReference); } Type environmentalOverriddenElementProperty = typeof(EnvironmentOverriddenElementProperty); var overridesAttribute = subject.Attributes.OfType <EnvironmentalOverridesAttribute>().FirstOrDefault(); if (overridesAttribute != null && overridesAttribute.CustomOverridesPropertyType != null) { environmentalOverriddenElementProperty = overridesAttribute.CustomOverridesPropertyType; } yield return(ContainingSection.CreateProperty(environmentalOverriddenElementProperty, new ParameterOverride("environmentModel", this), new ParameterOverride("subject", subject), new DependencyOverride <EnvironmentOverriddenElementPayload>(new InjectionParameter <EnvironmentOverriddenElementPayload>(overriddenElementReference.EnvironmentOverriddenElementPayload)))); }
protected virtual IEnumerable <Validator> GetValidators() { return(Attributes.OfType <ElementValidationAttribute>() .Select(v => ContainingSection.CreateValidatorInstance(v.ValidatorType))); }
protected override IEnumerable <Property> GetAllProperties() { return(base.GetAllProperties().Union(new Property[] { ContainingSection.CreateProperty <EnvironmentSourceViewModelDeltaFileProperty>() }));; }
private IEnumerable <CommandModel> CreateSectionDeleteCommand() { yield return(ContainingSection.CreateDeleteCommand(this, Attributes, typeof(DefaultSectionDeleteCommandModel))); }
public void Configure(IUnityContainer container) { ContainingSection.Configure(container, Name); }
/// <summary> /// Creates a delete <see cref="CommandModel"/> for this element based on it's <see cref="Attributes"/>. /// </summary> /// <returns></returns> protected IEnumerable <CommandModel> CreateDeleteCommand() { yield return(ContainingSection.CreateDeleteCommand(this, Attributes)); }