diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionItem.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionItem.cs
index 545959df806..34d64277245 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionItem.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionItem.cs
@@ -15,61 +15,25 @@ namespace System.ComponentModel.Design
///
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;
}
}
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionList.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionList.cs
index 15789da42e8..0b11c725058 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionList.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionList.cs
@@ -14,53 +14,23 @@ namespace System.ComponentModel.Design
///
public class DesignerActionList
{
- private bool _autoShow = false;
- private readonly IComponent _component;
-
- ///
- /// takes the related component as a parameter
- ///
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; }
- ///
- /// this will be null for list created from upgraded verbs collection...
- ///
- 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 items = new SortedList();
+ var items = new SortedList();
// we want to ignore the public methods and properties for THIS class (only take the inherited ones)
IList originalMethods = Array.AsReadOnly(typeof(DesignerActionList).GetMethods(BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public));
@@ -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));
}
}
@@ -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)
{
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionListCollection.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionListCollection.cs
index 29c32c4aea4..8d708ab5032 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionListCollection.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/DesignerActionListCollection.cs
@@ -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
@@ -26,10 +25,7 @@ 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)
{
@@ -37,6 +33,7 @@ public void AddRange(DesignerActionList[] value)
{
throw new ArgumentNullException(nameof(value));
}
+
for (int i = 0; i < value.Length; i++)
{
Add(value[i]);
@@ -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++)
{
@@ -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!");
}
}
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ExceptionCollection.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ExceptionCollection.cs
index af19d3b4f67..65e09f954b2 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ExceptionCollection.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ExceptionCollection.cs
@@ -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;
}
- ///
- /// Need this constructor since Exception implements ISerializable.
- ///
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();
- ///
- /// Need this since Exception implements ISerializable and we have fields to save out.
- ///
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ProjectTargetFrameworkAttribute.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ProjectTargetFrameworkAttribute.cs
index 24956e289c2..7a0c4917196 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ProjectTargetFrameworkAttribute.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/ProjectTargetFrameworkAttribute.cs
@@ -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; }
}
}
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/CodeDomSerializerException.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/CodeDomSerializerException.cs
index c714c72095e..02b56516b6e 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/CodeDomSerializerException.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/CodeDomSerializerException.cs
@@ -9,68 +9,47 @@
namespace System.ComponentModel.Design.Serialization
{
///
- /// The exception that is thrown when the code dom serializer experiences an error.
+ /// The exception that is thrown when the code dom serializer experiences an error.
///
[Serializable]
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")]
public class CodeDomSerializerException : SystemException
{
-
- private readonly CodeLinePragma _linePragma;
-
- ///
- /// Initializes a new instance of the CodeDomSerializerException class.
- ///
public CodeDomSerializerException(string message, CodeLinePragma linePragma) : base(message)
{
- _linePragma = linePragma;
+ LinePragma = linePragma;
}
- ///
- /// Initializes a new instance of the CodeDomSerializerException class.
- ///
- public CodeDomSerializerException(Exception ex, CodeLinePragma linePragma) : base(ex.Message, ex)
+ public CodeDomSerializerException(Exception ex, CodeLinePragma linePragma) : base(ex?.Message, ex)
{
- _linePragma = linePragma;
+ LinePragma = linePragma;
}
- ///
- /// Initializes a new instance of the CodeDomSerializerException class.
- ///
public CodeDomSerializerException(string message, IDesignerSerializationManager manager) : base(message)
{
- FillLinePragmaFromContext(manager);
+ if (manager == null)
+ {
+ throw new ArgumentNullException(nameof(manager));
+ }
}
- ///
- /// Initializes a new instance of the CodeDomSerializerException class.
- ///
- public CodeDomSerializerException(Exception ex, IDesignerSerializationManager manager) : base(ex.Message, ex)
+ public CodeDomSerializerException(Exception ex, IDesignerSerializationManager manager) : base(ex?.Message, ex)
{
- FillLinePragmaFromContext(manager);
+ if (manager == null)
+ {
+ throw new ArgumentNullException(nameof(manager));
+ }
}
protected CodeDomSerializerException(SerializationInfo info, StreamingContext context) : base(info, context)
{
- _linePragma = (CodeLinePragma)info.GetValue("linePragma", typeof(CodeLinePragma));
+ LinePragma = (CodeLinePragma)info.GetValue("linePragma", typeof(CodeLinePragma));
}
///
/// Gets the line pragma object that is related to this error.
///
- public CodeLinePragma LinePragma
- {
- get => _linePragma;
- }
-
- ///
- /// Sniffs around in the context looking for a code statement. if it finds one, it will add the statement's line # information to the exception.
- ///
- private void FillLinePragmaFromContext(IDesignerSerializationManager manager)
- {
- if (manager == null)
- throw new ArgumentNullException(nameof(manager));
- }
+ public CodeLinePragma LinePragma { get; }
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
@@ -78,7 +57,8 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
{
throw new ArgumentNullException(nameof(info));
}
- info.AddValue("linePragma", _linePragma);
+
+ info.AddValue("linePragma", LinePragma);
base.GetObjectData(info, context);
}
}
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ExpressionContext.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ExpressionContext.cs
index 37118a94e1d..051de753676 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ExpressionContext.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/ExpressionContext.cs
@@ -16,27 +16,14 @@ namespace System.ComponentModel.Design.Serialization
///
public sealed class ExpressionContext
{
- private readonly CodeExpression _expression;
- private readonly Type _expressionType;
- private readonly object _owner;
- private readonly object _presetValue;
-
- ///
- /// Creates a new expression context.
- ///
public ExpressionContext(CodeExpression expression, Type expressionType, object owner, object presetValue)
{
- // To make this public, we cannot have random special cases for what the args mean.
- Debug.Assert(expression != null && expressionType != null && owner != null, "Obsolete use of expression context.");
- _expression = expression ?? throw new ArgumentNullException(nameof(expression));
- _expressionType = expressionType ?? throw new ArgumentNullException(nameof(expressionType));
- _owner = owner ?? throw new ArgumentNullException(nameof(owner));
- _presetValue = presetValue;
+ Expression = expression ?? throw new ArgumentNullException(nameof(expression));
+ ExpressionType = expressionType ?? throw new ArgumentNullException(nameof(expressionType));
+ Owner = owner ?? throw new ArgumentNullException(nameof(owner));
+ PresetValue = presetValue;
}
- ///
- /// Creates a new expression context.
- ///
public ExpressionContext(CodeExpression expression, Type expressionType, object owner) : this(expression, expressionType, owner, null)
{
}
@@ -44,38 +31,42 @@ public ExpressionContext(CodeExpression expression, Type expressionType, object
///
/// The expression this context represents.
///
- public CodeExpression Expression
- {
- get => _expression;
- }
+ public CodeExpression Expression { get; }
///
- /// The type of the expression. This can be used to determine if a cast is needed when assigning to the expression.
+ /// The type of the expression. This can be used to determine if a
+ /// cast is needed when assigning to the expression.
///
- public Type ExpressionType
- {
- get => _expressionType;
- }
+ public Type ExpressionType { get; }
///
- /// The object owning this expression. For example, if the expression was a property reference to button1's Text property, Owner would return button1.
+ /// The object owning this expression. For example, if the expression
+ /// was a property reference to button1's Text property, Owner would
+ /// return button1.
///
- public object Owner
- {
- get => _owner;
- }
+ public object Owner { get; }
///
- /// Contains the preset value of an expression, should one exist. For example, if the expression is a property reference expression referring to the Controls property of a button, PresetValue will contain the instance of Controls property because the property is read-only and preset by the object to contain a value. On the other hand, a property such as Text or Visible does not have a preset value and therefore the PresetValue property will return null. Serializers can use this information to guide serialization. For example, take the following two snippts of code:
+ /// Contains the preset value of an expression, should one exist.
+ /// For example, if the expression is a property reference expression
+ /// referring to the Controls property of a button, PresetValue will
+ /// contain the instance of Controls property because the property is
+ /// read-only and preset by the object to contain a value. On the other
+ /// hand, a property such as Text or Visible does not have a preset
+ /// value and therefore the PresetValue property will return null.
+ /// Serializers can use this information to guide serialization.
+ /// For example, take the following two snippts of code:
/// Padding p = new Padding();
/// p.Left = 5;
/// button1.Padding = p;
/// button1.Padding.Left = 5;
- /// The serializer of the Padding class needs to know if it should generate the first or second form. The first form would be generated by default. The second form will only be generated if there is an ExpressionContext on the stack that contains a PresetValue equal to the value of the Padding object currently being serialized.
+ /// The serializer of the Padding class needs to know if it should
+ /// generate the first or second form. The first form would be
+ /// generated by default. The second form will only be generated
+ /// if there is an ExpressionContext on the stack that contains a
+ /// PresetValue equal to the value of the Padding object currently
+ /// being serialized.
///
- public object PresetValue
- {
- get => _presetValue;
- }
+ public object PresetValue { get; }
}
}
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/RootContext.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/RootContext.cs
index b5bae9ae838..123c7f8096c 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/RootContext.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/RootContext.cs
@@ -3,39 +3,35 @@
// See the LICENSE file in the project root for more information.
using System.CodeDom;
+
namespace System.ComponentModel.Design.Serialization
{
///
- /// The root context is added by a type code dom serailizier to provide a definiton of the "root" object.
+ /// The root context is added by a type code dom serailizier to provide a
+ /// definiton of the "root" object.
///
public sealed class RootContext
{
- private readonly CodeExpression _expression;
- private readonly object _value;
-
///
- /// This object can be placed on the context stack to represent the object that is the root of the serialization hierarchy. In addition to this instance, the RootContext also contains an expression that can be used to reference the RootContext.
+ /// This object can be placed on the context stack to represent the
+ /// object that is the root of the serialization hierarchy. In addition
+ /// to this instance, the RootContext also contains an expression that
+ /// can be used to reference the RootContext.
///
public RootContext(CodeExpression expression, object value)
{
- _expression = expression ?? throw new ArgumentNullException(nameof(expression));
- _value = value ?? throw new ArgumentNullException(nameof(value));
+ Expression = expression ?? throw new ArgumentNullException(nameof(expression));
+ Value = value ?? throw new ArgumentNullException(nameof(value));
}
///
- /// The expression representing the root object in the object graph.
+ /// The expression representing the root object in the object graph.
///
- public CodeExpression Expression
- {
- get => _expression;
- }
+ public CodeExpression Expression { get; }
///
- /// The root object of the object graph.
+ /// The root object of the object graph.
///
- public object Value
- {
- get => _value;
- }
+ public object Value { get; }
}
}
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/SerializeAbsoluteContext.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/SerializeAbsoluteContext.cs
index a9d99a9ba96..05ad465d3db 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/SerializeAbsoluteContext.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/SerializeAbsoluteContext.cs
@@ -5,40 +5,47 @@
namespace System.ComponentModel.Design.Serialization
{
///
- /// The ComponentSerializationService supports "absolute" serialization, where instead of just serializing values that differ from an object's default values, all values are serialized in such a way as to be able to reset values to their defaults for objects that may have already been initialized. When a component serialization service wishes to indicate this to CodeDomSerializer objects, it will place a SerializeAbsoluteContext on the context stack. The member in this context may be null, to indicate that all members are serialized, or a member indicating that only a specific member is being serialized at this time.
+ /// The ComponentSerializationService supports "absolute" serialization,
+ /// where instead of just serializing values that differ from an object's
+ // default values, all values are serialized in such a way as to be able
+ /// to reset values to their defaults for objects that may have already
+ /// been initialized. When a component serialization service wishes to
+ /// indicate this to CodeDomSerializer objects, it will place a
+ /// SerializeAbsoluteContext on the context stack. The member in this
+ /// context may be null, to indicate that all members are serialized, or
+ /// a member indicating that only a specific member is being serialized at
+ /// this time.
///
public sealed class SerializeAbsoluteContext
{
- private readonly MemberDescriptor _member;
///
- /// Creeates a new SerializeAbsoluteContext. Member can be null or omitted to indicate this context should be used for all members.
+ /// Creeates a new SerializeAbsoluteContext. Member can be null or
+ /// omitted to indicate this context should be used for all members.
///
public SerializeAbsoluteContext()
{
}
///
- /// Creeates a new SerializeAbsoluteContext. Member can be null or omitted to indicate this context should be used for all members.
+ /// Creeates a new SerializeAbsoluteContext. Member can be null or
+ /// omitted to indicate this context should be used for all members.
///
public SerializeAbsoluteContext(MemberDescriptor member)
{
- _member = member;
+ Member = member;
}
///
/// This property returns the member this context is bound to. It may be null to indicate the context is bound to all members of an object.
///
- public MemberDescriptor Member
- {
- get => _member;
- }
+ public MemberDescriptor Member { get; }
///
/// Returns true if the given member should be serialized in this context.
///
public bool ShouldSerialize(MemberDescriptor member)
{
- return (_member == null || _member == member);
+ return Member == null || Member == member;
}
}
}
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/StatementContext.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/StatementContext.cs
index cfdd12703a6..659ceb462c7 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/StatementContext.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/StatementContext.cs
@@ -9,7 +9,16 @@
namespace System.ComponentModel.Design.Serialization
{
///
- /// This object can be placed on the context stack to provide a place for statements to be serialized into. Normally, statements are serialized into whatever statement collection that is on the context stack. You can modify this behavior by creating a statement context and calling Populate with a collection of objects whose statements you would like stored in the statement table. As each object is serialized in SerializeToExpression it will have its contents placed in the statement table. saved in a table within the context. If you push this object on the stack it is your responsibility to integrate the statements added to it into your own collection of statements.
+ /// This object can be placed on the context stack to provide a place for
+ /// statements to be serialized into. Normally, statements are serialized
+ /// into whatever statement collection that is on the context stack. You
+ /// can modify this behavior by creating a statement context and calling
+ /// Populate with a collection of objects whose statements you would like
+ /// stored in the statement table. As each object is serialized in
+ /// SerializeToExpression it will have its contents placed in the statement
+ /// table. saved in a table within the context. If you push this object on
+ /// the stack it is your responsibility to integrate the statements added
+ /// to it into your own collection of statements.
///
public sealed class StatementContext
{
@@ -20,15 +29,7 @@ public sealed class StatementContext
///
public ObjectStatementCollection StatementCollection
{
- get
- {
- if (_statements == null)
- {
- _statements = new ObjectStatementCollection();
- }
-
- return _statements;
- }
+ get => _statements ?? (_statements = new ObjectStatementCollection());
}
}
diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionMethodItem.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionMethodItem.cs
index bfcc3c1f36a..4a541b92421 100644
--- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionMethodItem.cs
+++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionMethodItem.cs
@@ -8,8 +8,6 @@ namespace System.ComponentModel.Design
{
public class DesignerActionMethodItem : DesignerActionItem
{
- private readonly string _memberName;
- private readonly bool _includeAsDesignerVerb;
private readonly DesignerActionList _actionList;
private MethodInfo _methodInfo;
@@ -17,8 +15,8 @@ public DesignerActionMethodItem(DesignerActionList actionList, string memberName
: base(displayName, category, description)
{
_actionList = actionList;
- _memberName = memberName;
- _includeAsDesignerVerb = includeAsDesignerVerb;
+ MemberName = memberName;
+ IncludeAsDesignerVerb = includeAsDesignerVerb;
}
public DesignerActionMethodItem(DesignerActionList actionList, string memberName, string displayName) : this(actionList, memberName, displayName, null, null, false)
@@ -41,45 +39,25 @@ public DesignerActionMethodItem(DesignerActionList actionList, string memberName
{
}
- internal DesignerActionMethodItem()
- {
- }
-
- public virtual string MemberName
- {
- get => _memberName;
- }
+ public virtual string MemberName { get; }
public IComponent RelatedComponent { get; set; }
- public virtual bool IncludeAsDesignerVerb
- {
- get => _includeAsDesignerVerb;
- }
-
- // this is only use for verbs so that a designer action method item can be converted to a verb.
- // Verbs use an EventHandler to call their invoke so we need a way to translate the EventHandler Invoke into ou own Invoke
- internal void Invoke(object sender, EventArgs args)
- {
- Invoke();
- }
+ public virtual bool IncludeAsDesignerVerb { get; }
public virtual void Invoke()
{
if (_methodInfo == null)
{
- // we look public AND private or protected methods
- _methodInfo = _actionList.GetType().GetMethod(_memberName, BindingFlags.Default | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+ _methodInfo = _actionList?.GetType()?.GetMethod(MemberName, BindingFlags.Default | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
- if (_methodInfo != null)
- {
- _methodInfo.Invoke(_actionList, null);
- }
- else
+ if (_methodInfo == null)
{
throw new InvalidOperationException(string.Format(SR.DesignerActionPanel_CouldNotFindMethod, MemberName));
}
+
+ _methodInfo.Invoke(_actionList, null);
}
}
}
diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionPropertyItem.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionPropertyItem.cs
index 706ab1a6dc1..c2efd9b22f2 100644
--- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionPropertyItem.cs
+++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionPropertyItem.cs
@@ -6,12 +6,9 @@ namespace System.ComponentModel.Design
{
public sealed class DesignerActionPropertyItem : DesignerActionItem
{
- private readonly string _memberName;
- private IComponent _relatedComponent;
-
public DesignerActionPropertyItem(string memberName, string displayName, string category, string description) : base(displayName, category, description)
{
- _memberName = memberName;
+ MemberName = memberName;
}
public DesignerActionPropertyItem(string memberName, string displayName) : this(memberName, displayName, null, null)
@@ -22,16 +19,8 @@ public DesignerActionPropertyItem(string memberName, string displayName, string
{
}
- public string MemberName
- {
- get => _memberName;
- }
-
- public IComponent RelatedComponent
- {
- get => _relatedComponent;
- set => _relatedComponent = value;
- }
+ public string MemberName { get; }
+ public IComponent RelatedComponent { get; set; }
}
}
diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionVerbItem.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionVerbItem.cs
index d771812b3e0..9ae7300020c 100644
--- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionVerbItem.cs
+++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionVerbItem.cs
@@ -8,32 +8,14 @@ internal class DesignerActionVerbItem : DesignerActionMethodItem
{
private readonly DesignerVerb _targetVerb;
- public DesignerActionVerbItem(DesignerVerb verb)
+ public DesignerActionVerbItem(DesignerVerb verb) : base(null, null, null)
{
- _targetVerb = verb ?? throw new ArgumentNullException();
+ _targetVerb = verb ?? throw new ArgumentNullException(nameof(verb));
}
- public override string Category
- {
- get => "Verbs";
- }
-
- public override string Description { get; }
-
- public override string DisplayName
- {
- get => _targetVerb.Text;
- }
+ public override string Category => "Verbs";
- public override string MemberName
- {
- get => null;
- }
-
- public override bool IncludeAsDesignerVerb
- {
- get => false;
- }
+ public override string DisplayName => _targetVerb.Text;
public override void Invoke() => _targetVerb.Invoke();
}
diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionVerbList.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionVerbList.cs
index 6ef7876dfe0..2837b836b23 100644
--- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionVerbList.cs
+++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerActionVerbList.cs
@@ -13,10 +13,7 @@ public DesignerActionVerbList(DesignerVerb[] verbs) : base(null)
_verbs = verbs;
}
- public override bool AutoShow
- {
- get => false;
- }
+ public override bool AutoShow => false;
public override DesignerActionItemCollection GetSortedActionItems()
{
diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/UndoEngine.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/UndoEngine.cs
index 120d2c1146a..37249235932 100644
--- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/UndoEngine.cs
+++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/UndoEngine.cs
@@ -578,8 +578,6 @@ public ReferencingComponent(IComponent component, MemberDescriptor member)
///
protected class UndoUnit
{
- private readonly string _name; // the name of the undo unit
- private readonly UndoEngine _engine; // the undo engine we're tied to
private ArrayList _events; // the list of events we've captured
private ArrayList _changeEvents; // the list of change events we're currently capturing. Only valid until Commit is called.
private ArrayList _removeEvents; // the list of remove events we're currently capturing. Only valid until a matching Removed is encountered.
@@ -588,22 +586,19 @@ protected class UndoUnit
private bool _reverse; // if true, we walk the events list from the bottom up
private readonly Hashtable _lastSelection; // the selection as it was before we gathered undo info
- ///
- /// Creates a new UndoUnit.
- ///
public UndoUnit(UndoEngine engine, string name)
{
if (name == null)
{
- Debug.Fail("Null name passed to new undo unit");
name = string.Empty;
}
+
UndoEngine.Trace("Creating undo unit '{0}'", name);
- _name = name;
- _engine = engine ?? throw new ArgumentNullException(nameof(engine));
+ Name = name;
+ UndoEngine = engine ?? throw new ArgumentNullException(nameof(engine));
_reverse = true;
- if (_engine.GetService(typeof(ISelectionService)) is ISelectionService ss)
+ if (UndoEngine.GetService(typeof(ISelectionService)) is ISelectionService ss)
{
ICollection selection = ss.GetSelectedComponents();
Hashtable selectedNames = new Hashtable();
@@ -618,29 +613,14 @@ public UndoUnit(UndoEngine engine, string name)
}
}
- ///
- /// The name of the unit.
- ///
- public string Name
- {
- get => _name;
- }
+ public string Name { get; }
///
/// This returns true if the undo unit has nothing in it to undo. The unit will be discarded.
///
- public virtual bool IsEmpty
- {
- get => _events == null || _events.Count == 0;
- }
+ public virtual bool IsEmpty => _events == null || _events.Count == 0;
- ///
- /// The undo engine that was passed into the constructor.
- ///
- protected UndoEngine UndoEngine
- {
- get => _engine;
- }
+ protected UndoEngine UndoEngine { get; }
///
/// Adds the given event to our event list.
@@ -651,6 +631,7 @@ private void AddEvent(UndoEvent e)
{
_events = new ArrayList();
}
+
_events.Add(e);
}
@@ -663,7 +644,7 @@ public virtual void Close()
{
foreach (ChangeUndoEvent e in _changeEvents)
{
- e.Commit(_engine);
+ e.Commit(UndoEngine);
}
}
@@ -671,7 +652,7 @@ public virtual void Close()
{
foreach (AddRemoveUndoEvent e in _removeEvents)
{
- e.Commit(_engine);
+ e.Commit(UndoEngine);
}
}
@@ -693,7 +674,7 @@ public virtual void ComponentAdded(ComponentEventArgs e)
// do nothing
}
else
- AddEvent(new AddRemoveUndoEvent(_engine, e.Component, true));
+ AddEvent(new AddRemoveUndoEvent(UndoEngine, e.Component, true));
if (_ignoreAddingList != null)
{
@@ -795,7 +776,7 @@ public virtual void ComponentChanging(ComponentChangingEventArgs e)
}
// The site check here is done because the data team is calling us for components that are not yet sited. We end up writing them out as Guid-named locals. That's fine, except that we cannot capture after state for these types of things so we assert.
- if (_engine != null && _engine.GetName(e.Component, false) != null)
+ if (UndoEngine.GetName(e.Component, false) != null)
{
// The caller provided us with a component. This is the common case. We will add a new change event provided there is not already one open for this component.
bool hasChange = false;
@@ -814,7 +795,7 @@ public virtual void ComponentChanging(ComponentChangingEventArgs e)
(e.Member != null && e.Member.Attributes != null && e.Member.Attributes.Contains(DesignerSerializationVisibilityAttribute.Content)))
{
#if DEBUG
- string name = _engine.GetName(e.Component, false);
+ string name = UndoEngine.GetName(e.Component, false);
string memberName = "(none)";
if (e.Member != null && e.Member.Name != null) {
memberName = e.Member.Name;
@@ -836,7 +817,7 @@ public virtual void ComponentChanging(ComponentChangingEventArgs e)
if (e.Component is IComponent comp && comp.Site != null)
{
- changeEvent = new ChangeUndoEvent(_engine, e, serializeBeforeState);
+ changeEvent = new ChangeUndoEvent(UndoEngine, e, serializeBeforeState);
}
else if (e.Component != null)
{
@@ -846,7 +827,7 @@ public virtual void ComponentChanging(ComponentChangingEventArgs e)
if (owningComp != null)
{
- changeEvent = new ChangeUndoEvent(_engine, new ComponentChangingEventArgs(owningComp, null), serializeBeforeState);
+ changeEvent = new ChangeUndoEvent(UndoEngine, new ComponentChangingEventArgs(owningComp, null), serializeBeforeState);
}
}
}
@@ -881,7 +862,7 @@ public virtual void ComponentRemoved(ComponentEventArgs e)
if (_events[idx] is AddRemoveUndoEvent evt && evt.OpenComponent == e.Component)
{
- evt.Commit(_engine);
+ evt.Commit(UndoEngine);
// We should only reorder events if there are change events coming between OnRemoving and OnRemoved.
// If there are other events (such as AddRemoving), the serialization done in OnComponentRemoving might refer to components that aren't available.
if (idx != _events.Count - 1 && changeEvt != null)
@@ -927,7 +908,7 @@ public virtual void ComponentRemoving(ComponentEventArgs e)
}
try
{
- AddRemoveUndoEvent evt = new AddRemoveUndoEvent(_engine, e.Component, false);
+ AddRemoveUndoEvent evt = new AddRemoveUndoEvent(UndoEngine, e.Component, false);
AddEvent(evt);
_removeEvents.Add(evt);
}
@@ -947,7 +928,7 @@ public virtual void ComponentRename(ComponentRenameEventArgs e)
///
protected object GetService(Type serviceType)
{
- return _engine.GetService(serviceType);
+ return UndoEngine.GetService(serviceType);
}
///
@@ -964,17 +945,17 @@ public override string ToString()
public void Undo()
{
UndoEngine.Trace("Performing undo '{0}'", Name);
- UndoUnit savedUnit = _engine._executingUnit;
- _engine._executingUnit = this;
+ UndoUnit savedUnit = UndoEngine._executingUnit;
+ UndoEngine._executingUnit = this;
DesignerTransaction transaction = null;
try
{
if (savedUnit == null)
{
- _engine.OnUndoing(EventArgs.Empty);
+ UndoEngine.OnUndoing(EventArgs.Empty);
}
// create a transaction here so things that do work on componentchanged can ignore that while the transaction is opened...big perf win.
- transaction = _engine._host.CreateTransaction();
+ transaction = UndoEngine._host.CreateTransaction();
UndoCore();
}
catch (CheckoutException)
@@ -990,10 +971,10 @@ public void Undo()
transaction.Commit();
}
- _engine._executingUnit = savedUnit;
+ UndoEngine._executingUnit = savedUnit;
if (savedUnit == null)
{
- _engine.OnUndone(EventArgs.Empty);
+ UndoEngine.OnUndone(EventArgs.Empty);
}
}
}
@@ -1028,12 +1009,12 @@ protected virtual void UndoCore()
for (int beforeIdx = idx; beforeIdx >= groupEndIdx; beforeIdx--)
{
- ((UndoEvent)_events[beforeIdx]).BeforeUndo(_engine);
+ ((UndoEvent)_events[beforeIdx]).BeforeUndo(UndoEngine);
}
for (int undoIdx = idx; undoIdx >= groupEndIdx; undoIdx--)
{
- ((UndoEvent)_events[undoIdx]).Undo(_engine);
+ ((UndoEvent)_events[undoIdx]).Undo(UndoEngine);
}
Debug.Assert(idx >= groupEndIdx, "We're going backwards");
@@ -1043,7 +1024,7 @@ protected virtual void UndoCore()
// Now, if we have a selection, apply it.
if (_lastSelection != null)
{
- if (_engine.GetService(typeof(ISelectionService)) is ISelectionService ss)
+ if (UndoEngine.GetService(typeof(ISelectionService)) is ISelectionService ss)
{
string[] names = new string[_lastSelection.Keys.Count];
_lastSelection.Keys.CopyTo(names, 0);
@@ -1084,12 +1065,12 @@ protected virtual void UndoCore()
for (int beforeIdx = idx; beforeIdx <= groupEndIdx; beforeIdx++)
{
- ((UndoEvent)_events[beforeIdx]).BeforeUndo(_engine);
+ ((UndoEvent)_events[beforeIdx]).BeforeUndo(UndoEngine);
}
for (int undoIdx = idx; undoIdx <= groupEndIdx; undoIdx++)
{
- ((UndoEvent)_events[undoIdx]).Undo(_engine);
+ ((UndoEvent)_events[undoIdx]).Undo(UndoEngine);
}
Debug.Assert(idx <= groupEndIdx, "We're going backwards");
diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionItemCollectionTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionItemCollectionTests.cs
deleted file mode 100644
index ea258c17671..00000000000
--- a/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionItemCollectionTests.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.ComponentModel.Design;
-using Xunit;
-
-namespace System.Windows.Forms.Design.Tests
-{
- public class DesignerActionItemCollectionTests
- {
- [Fact]
- public void DesignerActionItemCollection_Constructor()
- {
- DesignerActionItemCollection underTest = new DesignerActionItemCollection();
- Assert.NotNull(underTest);
- Assert.Empty(underTest);
- }
-
- [Fact]
- public void DesignerActionItemCollection_Add_Contains_IndexOf()
- {
- DesignerActionItemCollection underTest = new DesignerActionItemCollection();
-
- DesignerActionItem item1 = new DesignerActionItemTest("name", "category", "description");
- underTest.Add(item1);
- Assert.True(underTest.Contains(item1));
- Assert.Equal(0, underTest.IndexOf(item1));
-
- DesignerActionItem item2 = new DesignerActionItemTest("name1", "category1", "description1");
- underTest.Add(item2);
- Assert.True(underTest.Contains(item2));
- Assert.Equal(1, underTest.IndexOf(item2));
- }
-
- [Fact]
- public void DesignerActionItemCollection_Insert_Remove_Count()
- {
- DesignerActionItemCollection underTest = new DesignerActionItemCollection();
- DesignerActionItem item1 = new DesignerActionItemTest("name", "category", "description");
- DesignerActionItem item2 = new DesignerActionItemTest("name1", "category1", "description1");
- DesignerActionItem item3 = new DesignerActionItemTest("name2", "category2", "description2");
- DesignerActionItem item4 = new DesignerActionItemTest("name3", "category3", "description3");
-
- underTest.Add(item1);
- underTest.Add(item2);
-
- underTest.Add(item3);
- Assert.Equal(2, underTest.IndexOf(item3));
-
- underTest.Insert(2, item4);
- Assert.Equal(3, underTest.IndexOf(item3));
- Assert.Equal(2, underTest.IndexOf(item4));
-
- underTest.Remove(item4);
- Assert.False(underTest.Contains(item4));
- Assert.Equal(2, underTest.IndexOf(item3));
- Assert.Equal(3, underTest.Count);
- }
-
- private class DesignerActionItemTest : DesignerActionItem
- {
- public DesignerActionItemTest(string displayName, string category, string description) : base(displayName, category, description)
- {
- }
- }
- }
-}
diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionListCollectionTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionListCollectionTests.cs
deleted file mode 100644
index e871d4719e4..00000000000
--- a/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionListCollectionTests.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.ComponentModel.Design;
-using WinForms.Common.Tests;
-using Xunit;
-
-namespace System.Windows.Forms.Design.Tests
-{
- public class DesignerActionListCollectionTests
- {
- [Fact]
- public void DesignerActionListCollection_Constructor()
- {
- DesignerActionListCollection underTest = new DesignerActionListCollection();
- Assert.NotNull(underTest);
- }
-
- [Fact]
- public void DesignerActionListCollection_Constructor_DesignerActionList()
- {
- DesignerActionListCollection underTest = CreateNewCollectionOfItems();
- Assert.NotNull(underTest);
- }
-
- [Fact]
- public void DesignerActionItemCollection_Add_AddRange()
- {
- DesignerActionListCollection underTest = CreateNewCollectionOfItems(5);
- Assert.Equal(5, underTest.Count);
-
- Button button = new Button();
- DesignerActionList list = new DesignerActionList(button);
- underTest.Add(list);
- Assert.Equal(6, underTest.Count);
-
- DesignerActionListCollection other = CreateNewCollectionOfItems(3);
- underTest.AddRange(other);
- Assert.Equal(9, underTest.Count);
- }
-
-
- [Fact]
- public void DesignerActionItemCollection_Insert_Contains_IndexOf()
- {
- DesignerActionListCollection underTest = CreateNewCollectionOfItems(5);
-
- Button button = new Button();
- DesignerActionList list = new DesignerActionList(button);
- underTest.Insert(3, list);
- Assert.True(underTest.Contains(list));
- Assert.Equal(3, underTest.IndexOf(list));
- }
-
- [Fact]
- public void DesignerActionItemCollection_Remove()
- {
- DesignerActionListCollection underTest = CreateNewCollectionOfItems(5);
-
- Button button = new Button();
- DesignerActionList list = new DesignerActionList(button);
- underTest.Insert(3, list);
- underTest.Remove(list);
- Assert.False(underTest.Contains(list));
- Assert.Equal(5, underTest.Count);
- }
-
- private DesignerActionListCollection CreateNewCollectionOfItems(int numberOfItems = 1)
- {
- Button button = new Button();
- DesignerActionList[] list = new DesignerActionList[] { new DesignerActionList(button) };
- DesignerActionListCollection underTest = new DesignerActionListCollection(list);
-
- for (int i = 1; i < numberOfItems; i++)
- {
- underTest.Add(new DesignerActionList(button));
- }
-
- return underTest;
- }
- }
-}
diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionMethodItemTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionMethodItemTests.cs
deleted file mode 100644
index eee7ac462eb..00000000000
--- a/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionMethodItemTests.cs
+++ /dev/null
@@ -1,94 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.ComponentModel.Design;
-using WinForms.Common.Tests;
-using Xunit;
-
-namespace System.Windows.Forms.Design.Tests
-{
- public class DesignerActionMethodItemTests
- {
- [Theory]
- [InlineData("memberName", "displayName", "category", "description", true)]
- [InlineData("memberName", "displayName", "category", "", true)]
- [InlineData("memberName", "displayName", "", "", false)]
- [InlineData("memberName", "", "", "", false)]
- public void DesignerActionMethodItem_Constructor(string memberName, string displayName, string category, string description, bool includeAsDesignerVerb)
- {
- DesignerActionMethodItem underTest = CreateDesignerActionMethodItem(memberName, displayName, category, description, includeAsDesignerVerb);
- Assert.NotNull(underTest);
- Assert.Equal(memberName, underTest.MemberName);
- Assert.Equal(displayName, underTest.DisplayName);
- Assert.Equal(category, underTest.Category);
- Assert.Equal(description, underTest.Description);
- Assert.Equal(includeAsDesignerVerb, underTest.IncludeAsDesignerVerb);
- }
-
- [Fact]
- public void DesignerActionMethodItem_Constructor2()
- {
- DesignerActionMethodItem underTest = CreateDesignerActionMethodItem("memberName", "displayName", "category");
- Assert.NotNull(underTest);
- Assert.Equal("memberName", underTest.MemberName);
- Assert.Equal("displayName", underTest.DisplayName);
- Assert.Equal("category", underTest.Category);
- Assert.Null(underTest.Description);
- }
-
- [Fact]
- public void DesignerActionMethodItem_Constructor3()
- {
- DesignerActionMethodItem underTest = CreateDesignerActionMethodItem("memberName", "displayName");
- Assert.NotNull(underTest);
- Assert.Equal("memberName", underTest.MemberName);
- Assert.Equal("displayName", underTest.DisplayName);
- Assert.Null(underTest.Category);
- Assert.Null(underTest.Description);
- }
-
- [Fact]
- public void DesignerActionMethodItem_RelatedComponent_getter_setter()
- {
- DesignerActionMethodItem underTest = CreateDesignerActionMethodItem("memberName", "displayName");
-
- Button button = new Button();
- underTest.RelatedComponent = button;
- Assert.Equal(button, underTest.RelatedComponent);
- }
-
- private DesignerActionMethodItem CreateDesignerActionMethodItem(string memberName, string displayName, string category, string description, bool includeAsDesignerVerb)
- {
- Button button = new Button();
- DesignerActionList actionList = new DesignerActionList(button);
-
- if (category == null && description == null)
- {
- return new DesignerActionMethodItem(actionList, memberName, displayName, includeAsDesignerVerb);
- }
- else if (description == null)
- {
- return new DesignerActionMethodItem(actionList, memberName, displayName, category, includeAsDesignerVerb);
- }
- else
- {
- return new DesignerActionMethodItem(actionList, memberName, displayName, category, description, includeAsDesignerVerb);
- }
- }
-
- private DesignerActionMethodItem CreateDesignerActionMethodItem(string memberName, string displayName, string category, string description)
- {
- return CreateDesignerActionMethodItem(memberName, displayName, category, description, false);
- }
-
- private DesignerActionMethodItem CreateDesignerActionMethodItem(string memberName, string displayName, string category)
- {
- return CreateDesignerActionMethodItem(memberName, displayName, category, null, false);
- }
- private DesignerActionMethodItem CreateDesignerActionMethodItem(string memberName, string displayName)
- {
- return CreateDesignerActionMethodItem(memberName, displayName, null, null, false);
- }
- }
-}
diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionPropertyItemTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionPropertyItemTests.cs
deleted file mode 100644
index 4ce807673e4..00000000000
--- a/src/System.Windows.Forms.Design/tests/UnitTests/DesignerActionPropertyItemTests.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.ComponentModel.Design;
-using WinForms.Common.Tests;
-using Xunit;
-
-namespace System.Windows.Forms.Design.Tests
-{
- public class DesignerActionPropertyItemTests
- {
- [Theory]
- [InlineData("memberName", "displayName", "category", "description")]
- [InlineData("memberName", "displayName", "category", "")]
- [InlineData("memberName", "displayName", "", "")]
- [InlineData("memberName", "", "", "")]
- public void DesignerActionPropertyItem_Constructor(string memberName, string displayName, string category, string description)
- {
- DesignerActionPropertyItem underTest = new DesignerActionPropertyItem(memberName, displayName, category, description);
- Assert.NotNull(underTest);
- Assert.Equal(memberName, underTest.MemberName);
- Assert.Equal(displayName, underTest.DisplayName);
- Assert.Equal(category, underTest.Category);
- Assert.Equal(description, underTest.Description);
- }
-
- [Fact]
- public void DesignerActionPropertyItem_Constructor2()
- {
- DesignerActionPropertyItem underTest = new DesignerActionPropertyItem("memberName", "displayName", "category");
- Assert.NotNull(underTest);
- Assert.Equal("memberName", underTest.MemberName);
- Assert.Equal("displayName", underTest.DisplayName);
- Assert.Equal("category", underTest.Category);
- Assert.Null(underTest.Description);
- }
-
- [Fact]
- public void DesignerActionPropertyItem_Constructor3()
- {
- DesignerActionPropertyItem underTest = new DesignerActionPropertyItem("memberName", "displayName");
- Assert.NotNull(underTest);
- Assert.Equal("memberName", underTest.MemberName);
- Assert.Equal("displayName", underTest.DisplayName);
- Assert.Null(underTest.Category);
- Assert.Null(underTest.Description);
- }
-
- [Fact]
- public void DesignerActionPropertyItem_RelatedComponent_getter_setter()
- {
- DesignerActionPropertyItem underTest = new DesignerActionPropertyItem("name", "displayname");
-
- Button button = new Button();
- underTest.RelatedComponent = button;
- Assert.Equal(button, underTest.RelatedComponent);
-
- }
- }
-}
diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/Serialization/CodeDomSerializerExceptionTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/Serialization/CodeDomSerializerExceptionTests.cs
deleted file mode 100644
index eb09161140c..00000000000
--- a/src/System.Windows.Forms.Design/tests/UnitTests/Serialization/CodeDomSerializerExceptionTests.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.CodeDom;
-using System.ComponentModel.Design.Serialization;
-using Moq;
-using Xunit;
-
-namespace System.Windows.Forms.Design.Serialization.Tests
-{
- public class CodeDomSerializerExceptionTests
- {
- Mock _mockDesignerSerializationManager;
-
- [Fact]
- public void CodeDomSerializerException_Constructor_Message_Pragma()
- {
- var pragma = new CodeLinePragma();
- var underTest = new CodeDomSerializerException("message", pragma);
- Assert.NotNull(underTest);
- Assert.Equal(pragma, underTest.LinePragma);
- }
-
- [Fact]
- public void CodeDomSerializerException_Constructor_Exception_Pragma()
- {
- var ex = new Exception();
- var pragma = new CodeLinePragma();
- var underTest = new CodeDomSerializerException(ex, pragma);
- Assert.NotNull(underTest);
- Assert.Equal(pragma, underTest.LinePragma);
- }
-
- [Fact]
- public void CodeDomSerializerException_Constructor_SerializationManager()
- {
- _mockDesignerSerializationManager = new Mock(MockBehavior.Strict);
- var underTest = new CodeDomSerializerException("message", _mockDesignerSerializationManager.Object);
- Assert.NotNull(underTest);
- }
-
- [Fact]
- public void CodeDomSerializerException_Constructor_Exception_SerializationManager()
- {
- var ex = new Exception();
- _mockDesignerSerializationManager = new Mock(MockBehavior.Strict);
- var underTest = new CodeDomSerializerException(ex, _mockDesignerSerializationManager.Object);
- Assert.NotNull(underTest);
- }
- }
-}
diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/Serialization/ExpressionContextTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/Serialization/ExpressionContextTests.cs
deleted file mode 100644
index d03fa06e376..00000000000
--- a/src/System.Windows.Forms.Design/tests/UnitTests/Serialization/ExpressionContextTests.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.CodeDom;
-using System.ComponentModel.Design.Serialization;
-using Xunit;
-
-namespace System.Windows.Forms.Design.Serialization.Tests
-{
- public class ExpressionContextTests
- {
- [Fact]
- public void ExpressionContext_Constructor()
- {
- CodeExpression expression = new CodeExpression();
- Type type = expression.GetType();
- object owner = "owner";
- object presetValue = null;
-
- var underTest = new ExpressionContext(expression, type, owner, presetValue);
- Assert.NotNull(underTest);
- Assert.Equal(expression, underTest.Expression);
- }
- }
-}
diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj b/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj
index 2db090483e3..58d353fd39d 100644
--- a/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj
+++ b/src/System.Windows.Forms.Design/tests/UnitTests/System.Windows.Forms.Design.Tests.csproj
@@ -14,6 +14,7 @@
+
diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionHeaderItemTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionHeaderItemTests.cs
new file mode 100644
index 00000000000..93c48db9808
--- /dev/null
+++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionHeaderItemTests.cs
@@ -0,0 +1,48 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Collections.Specialized;
+using Xunit;
+
+namespace System.ComponentModel.Design.Tests
+{
+ public class DesignerActionHeaderItemTests
+ {
+ [Theory]
+ [InlineData("displayName", "category", "displayName")]
+ [InlineData("displa(&a)yName", "cate(&a)gory", "displayName")]
+ [InlineData("", "", "")]
+ [InlineData(null, null, null)]
+ public void DesignerActionItem_Ctor_String_String(string displayName, string category, string expectedDisplayName)
+ {
+ var item = new DesignerActionHeaderItem(displayName, category);
+ Assert.Equal(expectedDisplayName, item.DisplayName);
+ Assert.Equal(category, item.Category);
+ Assert.Null(item.Description);
+ Assert.False(item.AllowAssociate);
+ Assert.Empty(item.Properties);
+ Assert.Same(item.Properties, item.Properties);
+ Assert.IsType(item.Properties);
+ Assert.True(item.ShowInSourceView);
+ }
+
+ [Theory]
+ [InlineData("displayName", "displayName")]
+ [InlineData("displa(&a)yName", "displayName")]
+ [InlineData("", "")]
+ [InlineData(null, null)]
+ public void DesignerActionItem_Ctor_String(string displayName, string expectedDisplayName)
+ {
+ var item = new DesignerActionHeaderItem(displayName);
+ Assert.Equal(expectedDisplayName, item.DisplayName);
+ Assert.Equal(displayName, item.Category);
+ Assert.Null(item.Description);
+ Assert.False(item.AllowAssociate);
+ Assert.Empty(item.Properties);
+ Assert.Same(item.Properties, item.Properties);
+ Assert.IsType(item.Properties);
+ Assert.True(item.ShowInSourceView);
+ }
+ }
+}
diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionItemCollectionTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionItemCollectionTests.cs
new file mode 100644
index 00000000000..453e955f5b8
--- /dev/null
+++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/DesignerActionItemCollectionTests.cs
@@ -0,0 +1,175 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Linq;
+using Xunit;
+
+namespace System.ComponentModel.Design.Tests
+{
+ public class DesignerActionItemCollectionTests
+ {
+ [Fact]
+ public void DesignerActionItemCollection_Ctor_Default()
+ {
+ var collection = new DesignerActionItemCollection();
+ Assert.Empty(collection);
+ }
+
+ [Fact]
+ public void DesignerActionItemCollection_Add_DesignerActionItem_Success()
+ {
+ var collection = new DesignerActionItemCollection();
+
+ var value1 = new SubDesignerActionItem("displayName", "category", "description");
+ collection.Add(value1);
+ Assert.Same(value1, Assert.Single(collection));
+ Assert.Same(value1, collection[0]);
+ Assert.True(collection.Contains(value1));
+ Assert.Equal(0, collection.IndexOf(value1));
+
+ var value2 = new SubDesignerActionItem("displayName", "category", "description");
+ collection.Add(value2);
+ Assert.Equal(new object[] { value1, value2 }, collection.Cast