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 @@ -16,25 +16,21 @@ protected internal override bool CanSerializeToString(WorkflowMarkupSerializatio

protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj)
{
List<PropertyInfo> properties = new List<PropertyInfo>();
List<PropertyInfo> properties = [];
if (obj is Point)
{
properties.Add(typeof(Point).GetProperty("X"));
properties.Add(typeof(Point).GetProperty("Y"));
}
return properties.ToArray();
return [.. properties];
}

protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
{
string convertedValue = String.Empty;

TypeConverter converter = TypeDescriptor.GetConverter(value);
if (converter != null && converter.CanConvertTo(typeof(string)))
convertedValue = converter.ConvertTo(value, typeof(string)) as string;
else
convertedValue = base.SerializeToString(serializationManager, value);
return convertedValue;
return converter != null && converter.CanConvertTo(typeof(string))
? converter.ConvertTo(value, typeof(string)) as string
: base.SerializeToString(serializationManager, value);
}

protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
Expand All @@ -45,10 +41,9 @@ protected internal override object DeserializeFromString(WorkflowMarkupSerializa
if (!String.IsNullOrWhiteSpace(pointValue))
{
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Point));
if (converter != null && converter.CanConvertFrom(typeof(string)) && !IsValidCompactAttributeFormat(pointValue))
point = converter.ConvertFrom(value);
else
point = base.SerializeToString(serializationManager, value);
point = converter != null && converter.CanConvertFrom(typeof(string)) && !IsValidCompactAttributeFormat(pointValue)
? converter.ConvertFrom(value)
: base.SerializeToString(serializationManager, value);
}

return point;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,21 @@ protected internal override bool CanSerializeToString(WorkflowMarkupSerializatio

protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj)
{
List<PropertyInfo> properties = new List<PropertyInfo>();
List<PropertyInfo> properties = [];
if (obj is Size)
{
properties.Add(typeof(Size).GetProperty("Width"));
properties.Add(typeof(Size).GetProperty("Height"));
}
return properties.ToArray();
return [.. properties];
}

protected internal override string SerializeToString(WorkflowMarkupSerializationManager serializationManager, object value)
{
string convertedValue = String.Empty;

TypeConverter converter = TypeDescriptor.GetConverter(value);
if (converter != null && converter.CanConvertTo(typeof(string)))
convertedValue = converter.ConvertTo(value, typeof(string)) as string;
else
convertedValue = base.SerializeToString(serializationManager, value);
return convertedValue;
return converter != null && converter.CanConvertTo(typeof(string))
? converter.ConvertTo(value, typeof(string)) as string
: base.SerializeToString(serializationManager, value);
}

protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
Expand All @@ -45,10 +41,9 @@ protected internal override object DeserializeFromString(WorkflowMarkupSerializa
if (!String.IsNullOrWhiteSpace(sizeValue))
{
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Size));
if (converter != null && converter.CanConvertFrom(typeof(string)) && !IsValidCompactAttributeFormat(sizeValue))
size = converter.ConvertFrom(value);
else
size = base.SerializeToString(serializationManager, value);
size = converter != null && converter.CanConvertFrom(typeof(string)) && !IsValidCompactAttributeFormat(sizeValue)
? converter.ConvertFrom(value)
: base.SerializeToString(serializationManager, value);
}

return size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected internal override string SerializeToString(WorkflowMarkupSerialization
if (value == null)
throw new ArgumentNullException("value");

if (!(value is CodeTypeReference reference))
if (value is not CodeTypeReference reference)
return string.Empty;

// make the typename as best we can, and try to get the fully qualified name
Expand All @@ -55,15 +55,9 @@ protected internal override string SerializeToString(WorkflowMarkupSerialization
// to make sure that writers (such as Xoml) are given types that exist in the target framework
// This makes it the job of the rules designer or rules validator to not call the Xoml stack
// with types that do not exist in the target framework
if (string.IsNullOrEmpty(assemblyFullName))
{
typeName = type.AssemblyQualifiedName;
}
else
{
typeName = string.Format(CultureInfo.InvariantCulture, "{0}, {1}", type.FullName, assemblyFullName);
}
return typeName;
return string.IsNullOrEmpty(assemblyFullName)
? type.AssemblyQualifiedName
: string.Format(CultureInfo.InvariantCulture, "{0}, {1}", type.FullName, assemblyFullName);
}

protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ public override MethodInfo GetSetMethod(bool nonPublic)

public override object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
{
if (OnGetValue != null)
return OnGetValue(this, obj);
else
return null;
return OnGetValue != null
? OnGetValue(this, obj)
: null;
}

public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
Expand All @@ -119,10 +118,9 @@ public override void SetValue(object obj, object value, BindingFlags invokeAttr,
public XmlQualifiedName GetXmlQualifiedName(WorkflowMarkupSerializationManager managerLocal, out string prefix)
{
prefix = String.Empty;
if (OnGetXmlQualifiedName != null)
return OnGetXmlQualifiedName(this, managerLocal, out prefix);
else
return null;
return OnGetXmlQualifiedName != null
? OnGetXmlQualifiedName(this, managerLocal, out prefix)
: null;
}

public override ParameterInfo[] GetIndexParameters()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ protected internal override object DeserializeFromString(WorkflowMarkupSerializa
// ICollection<string> or its derivative, special case! (A synchronization
// handle cannot begin with a * because it won't be a language independent
// identifier :) )
if (IsValidCompactAttributeFormat(value))
return DeserializeFromCompactFormat(serializationManager, serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader, value);
else
return SynchronizationHandlesTypeConverter.UnStringify(value);
return IsValidCompactAttributeFormat(value)
? DeserializeFromCompactFormat(serializationManager, serializationManager.WorkflowMarkupStack[typeof(XmlReader)] as XmlReader, value)
: SynchronizationHandlesTypeConverter.UnStringify(value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,9 @@ public virtual Type GetType(string typeName)
}

typeName = typeName.Trim();
if (assembly != null)
type = assembly.GetType(typeName, false);
else
type = Type.GetType(fullyQualifiedTypeName, false);
type = assembly != null
? assembly.GetType(typeName, false)
: Type.GetType(fullyQualifiedTypeName, false);
}
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,9 @@ internal void SerializeContents(WorkflowMarkupSerializationManager serialization
else
{
TypeConverter typeConverter = TypeDescriptor.GetConverter(obj.GetType());
if (typeConverter != null && typeConverter.CanConvertTo(typeof(string)))
stringValue = typeConverter.ConvertTo(null, CultureInfo.InvariantCulture, obj, typeof(string)) as string;
else
stringValue = Convert.ToString(obj, CultureInfo.InvariantCulture);
stringValue = typeConverter != null && typeConverter.CanConvertTo(typeof(string))
? typeConverter.ConvertTo(null, CultureInfo.InvariantCulture, obj, typeof(string)) as string
: Convert.ToString(obj, CultureInfo.InvariantCulture);
}

writer.WriteValue(stringValue);
Expand Down Expand Up @@ -1212,10 +1211,9 @@ internal static WorkflowMarkupSerializationException CreateSerializationError(st
if (string.IsNullOrEmpty(errorMsg))
errorMsg = e?.Message ?? string.Empty;

if (reader is IXmlLineInfo xmlLineInfo)
return new WorkflowMarkupSerializationException(errorMsg, xmlLineInfo.LineNumber, xmlLineInfo.LinePosition);
else
return new WorkflowMarkupSerializationException(errorMsg, 0, 0);
return reader is IXmlLineInfo xmlLineInfo
? new WorkflowMarkupSerializationException(errorMsg, xmlLineInfo.LineNumber, xmlLineInfo.LinePosition)
: new WorkflowMarkupSerializationException(errorMsg, 0, 0);
}
#endregion

Expand Down Expand Up @@ -2071,12 +2069,9 @@ internal PropertyInfo Property

internal object GetContents()
{
object value;
if (this.contentProperty != null)
value = this.contentProperty.GetValue(this.parentObject, null);
else
value = this.parentObjectSerializer.GetChildren(this.serializationManager, this.parentObject);
return value;
return this.contentProperty != null
? this.contentProperty.GetValue(this.parentObject, null)
: this.parentObjectSerializer.GetChildren(this.serializationManager, this.parentObject);
}

internal void SetContents(IList<ContentInfo> contents)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ internal static void GetMappingsFromXmlNamespace(WorkflowMarkupSerializationMana
string assemblyName = String.Empty;
if (serializationManager.LocalAssembly != assembly)
{
if (xmlnsDefinition.AssemblyName != null && xmlnsDefinition.AssemblyName.Trim().Length > 0)
assemblyName = xmlnsDefinition.AssemblyName;
else
assemblyName = assembly.FullName;
assemblyName = xmlnsDefinition.AssemblyName != null && xmlnsDefinition.AssemblyName.Trim().Length > 0
? xmlnsDefinition.AssemblyName
: assembly.FullName;
}

if (xmlnsDefinition.XmlNamespace.Equals(xmlNamespace, StringComparison.Ordinal))
Expand Down Expand Up @@ -287,14 +286,9 @@ private static string GetAssemblyName(Type type)
{
//
// Handle DesignTimeType
if (type.Assembly == null)
{
return string.Empty;
}
else
{
return type.Assembly.FullName;
}
return type.Assembly == null
? string.Empty
: type.Assembly.FullName;
}

//Format for the xmlnamespace: clr-namespace:[Namespace][;Assembly=[AssemblyName]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,9 @@ public override object ProvideValue(IServiceProvider provider)
return type;

// To Support types whose assembly is not available, we need to still resolve the clr namespace
if (manager.XmlNamespaceBasedMappings.TryGetValue(reader.LookupNamespace(prefix), out List<WorkflowMarkupSerializerMapping> xmlnsMappings) && xmlnsMappings != null && xmlnsMappings.Count > 0)
return xmlnsMappings[0].ClrNamespace + "." + typename;
else
return typename;
return manager.XmlNamespaceBasedMappings.TryGetValue(reader.LookupNamespace(prefix), out List<WorkflowMarkupSerializerMapping> xmlnsMappings) && xmlnsMappings != null && xmlnsMappings.Count > 0
? xmlnsMappings[0].ClrNamespace + "." + typename
: typename;
}
type = manager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(string.Empty)));

Expand Down
11 changes: 3 additions & 8 deletions LogicBuilder.Workflow.ComponentModel.Serialization/SR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,9 @@ internal static string GetString(CultureInfo culture, string name, params object
return null;
string res = sys.resources.GetString(name, culture);
System.Diagnostics.Debug.Assert(res != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", new object[] { name }));
if (args != null && args.Length > 0)
{
return string.Format(CultureInfo.CurrentCulture, res, args);
}
else
{
return res;
}
return args != null && args.Length > 0
? string.Format(CultureInfo.CurrentCulture, res, args)
: res;
}

internal static string GetString(string name)
Expand Down