Last active
September 19, 2015 21:17
-
-
Save controlflow/d00f999fd69633b9486f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using JetBrains.Annotations; | |
namespace JetBrains.VsIntegration.ProjectModel.PropertiesExtender | |
{ | |
public sealed class AggregatedPropertyDescriptor : PropertyDescriptor | |
{ | |
[NotNull] private readonly IList<PropertyDescriptor> myPropertyDescriptors; | |
public AggregatedPropertyDescriptor([NotNull] IList<PropertyDescriptor> propertyDescriptors) | |
: base(propertyDescriptors[0]) | |
{ | |
myPropertyDescriptors = propertyDescriptors; | |
} | |
public override bool CanResetValue(object component) | |
{ | |
foreach (var propertyDescriptor in myPropertyDescriptors) | |
{ | |
if (propertyDescriptor.CanResetValue(component)) return true; | |
} | |
return false; | |
} | |
public override void ResetValue(object component) | |
{ | |
foreach (var propertyDescriptor in myPropertyDescriptors) | |
{ | |
if (propertyDescriptor.CanResetValue(component)) | |
propertyDescriptor.ResetValue(component); | |
} | |
} | |
public override object GetValue(object component) | |
{ | |
object value = null; | |
var first = true; | |
foreach (var propertyDescriptor in myPropertyDescriptors) | |
{ | |
var decriptorValue = propertyDescriptor.GetValue(component); | |
if (first) | |
{ | |
value = decriptorValue; | |
first = false; | |
} | |
else | |
{ | |
if (!Equals(value, decriptorValue)) return null; | |
} | |
} | |
return value; | |
} | |
public override void SetValue(object component, object value) | |
{ | |
foreach (var propertyDescriptor in myPropertyDescriptors) | |
{ | |
propertyDescriptor.SetValue(component, value); | |
} | |
} | |
public override bool ShouldSerializeValue(object component) | |
{ | |
return false; | |
} | |
public override Type ComponentType | |
{ | |
get { return typeof(PropertiesExtender); } | |
} | |
public override bool IsReadOnly { get { return false; } } | |
public override Type PropertyType | |
{ | |
get | |
{ | |
foreach (var propertyDescriptor in myPropertyDescriptors) | |
return propertyDescriptor.PropertyType; | |
return typeof(object); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class ProjectAndSolutionExtenderProviderBase : ProjectPropertiesExtenderProviderBase, IPropertiesExtenderProvider | |
{ | |
protected ProjectAndSolutionExtenderProviderBase([NotNull] IShellLocks locks, [NotNull] ISettingsStore settingsStore) | |
: base(locks, settingsStore) { } | |
public new bool CanExtend(IProjectItem projectItem) | |
{ | |
if (base.CanExtend(projectItem)) return true; | |
return projectItem is ISolution; | |
} | |
public new IEnumerable<PropertyDescriptor> GetPropertyDescriptors(IProjectItem projectItem) | |
{ | |
var project = projectItem as IProject; | |
if (project != null) | |
{ | |
return GetProjectPropertyDescriptors(project); | |
} | |
var solution = projectItem as ISolution; | |
if (solution != null) | |
{ | |
var allDescriptors = new List<PropertyDescriptor>(); | |
foreach (var solutionProject in solution.GetAllProjects()) | |
{ | |
if (!CanExtend(solutionProject)) continue; | |
foreach (var propertyDescriptor in GetProjectPropertyDescriptors(solutionProject)) | |
allDescriptors.Add(propertyDescriptor); | |
} | |
if (allDescriptors.Count > 0) | |
{ | |
return allDescriptors | |
.GroupBy(descriptor => descriptor.Name) | |
.Select(group => new AggregatedPropertyDescriptor(group.ToList())); | |
} | |
} | |
return EmptyList<PropertyDescriptor>.InstanceList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment