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 @@ -10,10 +10,9 @@ namespace LogicBuilder.Workflow.ComponentModel.Design
{
internal static class Helpers
{
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static XmlWriter CreateXmlWriter(object output)
{
XmlWriterSettings settings = new XmlWriterSettings
XmlWriterSettings settings = new()
{
Indent = true,
IndentChars = ("\t"),
Expand All @@ -32,7 +31,6 @@ internal static XmlWriter CreateXmlWriter(object output)
}
}

[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static DesignerSerializationVisibility GetSerializationVisibility(MemberInfo memberInfo)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ protected internal override IList GetChildren(WorkflowMarkupSerializationManager
if (!IsValidCollectionType(obj.GetType()))
throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));

IEnumerable enumerable = obj as IEnumerable;
ArrayList arrayList = new ArrayList();
foreach (object containedObj in enumerable)
arrayList.Add(containedObj);
IEnumerable enumerable = obj as IEnumerable ?? Enumerable.Empty<object>();
ArrayList arrayList = [.. enumerable];
return arrayList;
}

protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj)
{
return new PropertyInfo[] { };
return [];
}

protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializationManager serializationManager, object value)
Expand All @@ -52,7 +50,7 @@ protected internal override void ClearChildren(WorkflowMarkupSerializationManage
throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));

if (obj is ICollection) /*Updating from collection == null - appears to be a bug e.g. List of T passes IsValidCollectionType and implements System.Collections.ICollection.*/
obj.GetType().InvokeMember("Clear", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, obj, new object[] { }, CultureInfo.InvariantCulture);
obj.GetType().InvokeMember("Clear", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, obj, [], CultureInfo.InvariantCulture);
}

protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object parentObj, object childObj)
Expand All @@ -63,7 +61,7 @@ protected internal override void AddChild(WorkflowMarkupSerializationManager ser
if (!IsValidCollectionType(parentObj.GetType()))
throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, parentObj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName));

parentObj.GetType().InvokeMember("Add", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, parentObj, new object[] { childObj }, CultureInfo.InvariantCulture);
parentObj.GetType().InvokeMember("Add", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, parentObj, [childObj], CultureInfo.InvariantCulture);
}

internal static bool IsValidCollectionType(Type collectionType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ protected internal sealed override string SerializeToString(WorkflowMarkupSerial
int i = 0;
foreach (object argValue in instanceDescriptor.Arguments)
{
if (constructorArguments == null)
constructorArguments = new Dictionary<string, string>();
constructorArguments ??= [];
//
if (argValue == null)
continue;
Expand All @@ -70,7 +69,7 @@ protected internal sealed override string SerializeToString(WorkflowMarkupSerial
else if (argValue is System.Type)
{
Type argType = argValue as Type;
if (argType.Assembly != null)
if (argType?.Assembly != null)
{
XmlQualifiedName typeQualifiedName = serializationManager.GetXmlQualifiedName(argType, out _);
writer.WriteQualifiedName(XmlConvert.EncodeName(typeQualifiedName.Name), typeQualifiedName.Namespace);
Expand All @@ -91,14 +90,16 @@ protected internal sealed override string SerializeToString(WorkflowMarkupSerial
}
}

List<PropertyInfo> properties = new List<PropertyInfo>();
properties.AddRange(GetProperties(serializationManager, value));
properties.AddRange(serializationManager.GetExtendedProperties(value));
List<PropertyInfo> properties =
[
.. GetProperties(serializationManager, value),
.. serializationManager.GetExtendedProperties(value),
];
foreach (PropertyInfo serializableProperty in properties)
{
if (Helpers.GetSerializationVisibility(serializableProperty) != DesignerSerializationVisibility.Hidden && serializableProperty.CanRead && serializableProperty.GetValue(value, null) != null)
{
if (!(serializationManager.GetSerializer(serializableProperty.PropertyType, typeof(WorkflowMarkupSerializer)) is WorkflowMarkupSerializer propSerializer))
if (serializationManager.GetSerializer(serializableProperty.PropertyType, typeof(WorkflowMarkupSerializer)) is not WorkflowMarkupSerializer propSerializer)
{
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerNotAvailable, serializableProperty.PropertyType.FullName)));
continue;
Expand Down Expand Up @@ -142,13 +143,13 @@ protected internal sealed override string SerializeToString(WorkflowMarkupSerial
}
else
{
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerNoSerializeLogic, new object[] { serializableProperty.Name, value.GetType().FullName })));
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerNoSerializeLogic, [serializableProperty.Name, value.GetType().FullName])));
}
}
}
catch
{
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerNoSerializeLogic, new object[] { serializableProperty.Name, value.GetType().FullName })));
serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerNoSerializeLogic, [serializableProperty.Name, value.GetType().FullName])));
continue;
}
finally
Expand All @@ -165,9 +166,9 @@ protected internal sealed override string SerializeToString(WorkflowMarkupSerial

protected virtual InstanceDescriptor GetInstanceDescriptor(WorkflowMarkupSerializationManager serializationManager, object value)
{
return !(value is MarkupExtension markupExtension)
return value is not MarkupExtension markupExtension
? throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(MarkupExtension).FullName), "value")
: new InstanceDescriptor(markupExtension.GetType().GetConstructor(new Type[0]), null);
: new InstanceDescriptor(markupExtension.GetType().GetConstructor([]), null);
}

// more escaped characters can be consider here, hence a seperate fn instead of string.Replace
Expand All @@ -176,7 +177,7 @@ private string CreateEscapedValue(string value)
if (value == null)
throw new ArgumentNullException("value");

StringBuilder sb = new StringBuilder(64);
StringBuilder sb = new(64);
int length = value.Length;
for (int i = 0; i < length; i++)
{
Expand Down
Loading