Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,25 @@ namespace System.ComponentModel.Design
/// </summary>
public abstract class DesignerActionItem
{
private bool _allowAssociate;
private readonly string _displayName;
private readonly string _description;
private readonly string _category;
private IDictionary _properties;
private bool _showInSourceView = true;

public DesignerActionItem(string displayName, string category, string description)
{
_category = category;
_description = description;
_displayName = displayName == null ? null : Regex.Replace(displayName, @"\(\&.\)", "");
DisplayName = displayName == null ? null : Regex.Replace(displayName, @"\(\&.\)", "");
Category = category;
Description = description;
}

internal DesignerActionItem()
{
}
public bool AllowAssociate { get; set; }

public bool AllowAssociate
{
get => _allowAssociate;
set => _allowAssociate = value;
}
public virtual string Category { get; }

public virtual string Category
{
get => _category;
}
public virtual string Description { get; }

public virtual string Description
{
get => _description;
}
public virtual string DisplayName { get; }

public virtual string DisplayName
{
get => _displayName;
}
public IDictionary Properties => _properties ?? (_properties = new HybridDictionary());

public IDictionary Properties
{
get
{
if (_properties == null)
{
_properties = new HybridDictionary();
}
return _properties;
}
}

public bool ShowInSourceView
{
get => _showInSourceView;
set => _showInSourceView = value;
}
public bool ShowInSourceView { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,23 @@ namespace System.ComponentModel.Design
/// </summary>
public class DesignerActionList
{
private bool _autoShow = false;
private readonly IComponent _component;

/// <summary>
/// takes the related component as a parameter
/// </summary>
public DesignerActionList(IComponent component)
{
_component = component;
Component = component;
}

public virtual bool AutoShow
{
get => _autoShow;
set
{
if (_autoShow != value)
{
_autoShow = value;
}
}
}
public virtual bool AutoShow { get; set; }

/// <summary>
/// this will be null for list created from upgraded verbs collection...
/// </summary>
public IComponent Component
{
get => _component;
}
public IComponent Component { get; }

public object GetService(Type serviceType)
{
if (_component != null && _component.Site != null)
{
return _component.Site.GetService(serviceType);
}
else
{
return null;
}
return Component?.Site?.GetService(serviceType);
}

public virtual DesignerActionItemCollection GetSortedActionItems()
{
string dispName, desc, cat;
SortedList<string, DesignerActionItem> items = new SortedList<string, DesignerActionItem>();
var items = new SortedList<string, DesignerActionItem>();

// we want to ignore the public methods and properties for THIS class (only take the inherited ones)
IList<MethodInfo> originalMethods = Array.AsReadOnly(typeof(DesignerActionList).GetMethods(BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public));
Expand All @@ -71,11 +41,14 @@ public virtual DesignerActionItemCollection GetSortedActionItems()
foreach (MethodInfo info in methods)
{
if (originalMethods.Contains(info))
{
continue;
}

// Make sure there are only methods that take no parameters
if (info.GetParameters().Length == 0 && !info.IsSpecialName)
{
GetMemberDisplayProperties(info, out dispName, out desc, out cat);
GetMemberDisplayProperties(info, out string dispName, out string desc, out string cat);
items.Add(info.Name, new DesignerActionMethodItem(this, info.Name, dispName, cat, desc));
}
}
Expand All @@ -85,43 +58,46 @@ public virtual DesignerActionItemCollection GetSortedActionItems()
foreach (PropertyInfo info in properties)
{
if (originalProperties.Contains(info))
{
continue;
GetMemberDisplayProperties(info, out dispName, out desc, out cat);
}

GetMemberDisplayProperties(info, out string dispName, out string desc, out string cat);
items.Add(dispName, new DesignerActionPropertyItem(info.Name, dispName, cat, desc));
}

DesignerActionItemCollection returnValue = new DesignerActionItemCollection();
var returnValue = new DesignerActionItemCollection();
foreach (DesignerActionItem dai in items.Values)
{
returnValue.Add(dai);
}

return returnValue;
}

private object GetCustomAttribute(MemberInfo info, Type attributeType)
{
object[] attributes = info.GetCustomAttributes(attributeType, true);
if (attributes.Length > 0)
{
return attributes[0];
}
else
{
return null;
}
return attributes.Length > 0 ? attributes[0] : null;
}

private void GetMemberDisplayProperties(MemberInfo info, out string displayName, out string description, out string category)
{
displayName = description = category = "";
displayName = string.Empty;
description = string.Empty;
category = string.Empty;

if (GetCustomAttribute(info, typeof(DescriptionAttribute)) is DescriptionAttribute descAttr)
{
description = descAttr.Description;
}

DisplayNameAttribute dispNameAttr = GetCustomAttribute(info, typeof(DisplayNameAttribute)) as DisplayNameAttribute;
if (dispNameAttr != null)
{
displayName = dispNameAttr.DisplayName;
}

CategoryAttribute catAttr = GetCustomAttribute(info, typeof(CategoryAttribute)) as CategoryAttribute;
if (dispNameAttr != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.Collections;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace System.ComponentModel.Design
Expand All @@ -26,17 +25,15 @@ public DesignerActionList this[int index]
set => List[index] = value;
}

public int Add(DesignerActionList value)
{
return List.Add(value);
}
public int Add(DesignerActionList value) => List.Add(value);

public void AddRange(DesignerActionList[] value)
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}

for (int i = 0; i < value.Length; i++)
{
Add(value[i]);
Expand All @@ -49,6 +46,7 @@ public void AddRange(DesignerActionListCollection value)
{
throw new ArgumentNullException(nameof(value));
}

int currentCount = value.Count;
for (int i = 0; i < currentCount; i++)
{
Expand All @@ -66,22 +64,9 @@ public void AddRange(DesignerActionListCollection value)

public void CopyTo(DesignerActionList[] array, int index) => List.CopyTo(array, index);

protected override void OnSet(int index, object oldValue, object newValue)
{
}

protected override void OnInsert(int index, object value)
protected override void OnValidate(object value)
{
// Don't perform any validation.
}

protected override void OnClear()
{
}

protected override void OnRemove(int index, object value)
{
}

protected override void OnValidate(object value) => Debug.Assert(value != null, "Don't add null actionlist!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,26 @@

using System.Collections;
using System.Runtime.Serialization;
using System.Security;

namespace System.ComponentModel.Design
{
[Serializable]
public sealed class ExceptionCollection : Exception
{
readonly ArrayList _exceptions;
private readonly ArrayList _exceptions;

public ExceptionCollection(ArrayList exceptions)
{
_exceptions = exceptions;
}

/// <summary>
/// Need this constructor since Exception implements ISerializable.
/// </summary>
private ExceptionCollection(SerializationInfo info, StreamingContext context) : base(info, context)
{
_exceptions = (ArrayList)info.GetValue("exceptions", typeof(ArrayList));
}

public ArrayList Exceptions
{
get
{
if (_exceptions != null)
{
return (ArrayList)_exceptions.Clone();
}
return null;
}
}
public ArrayList Exceptions => (ArrayList)_exceptions?.Clone();

/// <summary>
/// Need this since Exception implements ISerializable and we have fields to save out.
/// </summary>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ namespace System.ComponentModel.Design
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct)]
public sealed class ProjectTargetFrameworkAttribute : Attribute
{
private string _targetFrameworkMoniker;
public ProjectTargetFrameworkAttribute(string targetFrameworkMoniker)
{
_targetFrameworkMoniker = targetFrameworkMoniker;
TargetFrameworkMoniker = targetFrameworkMoniker;
}

public string TargetFrameworkMoniker
{
get => _targetFrameworkMoniker;
}
public string TargetFrameworkMoniker { get; }
}
}
Loading