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 @@ -226,13 +226,11 @@ public IContainer Container
{
get
{
if (this.container == null)
if (this.container == null && this.GetService(typeof(IDesignerHost)) is IDesignerHost designerHost)
{
if (this.GetService(typeof(IDesignerHost)) is IDesignerHost designerHost)
{
this.container = designerHost.Container;
}
this.container = designerHost.Container;
}

return this.container;
}
set
Expand All @@ -250,10 +248,7 @@ public IList Errors
get
{
this.CheckSession();
if (this.errorList == null)
{
this.errorList = new ArrayList();
}
this.errorList ??= [];
return this.errorList;
}
}
Expand Down Expand Up @@ -352,7 +347,7 @@ PropertyDescriptorCollection IDesignerSerializationManager.Properties
PropertyDescriptor[] array;
if (obj == null)
{
array = new PropertyDescriptor[0];
array = [];
}
else
{
Expand All @@ -375,7 +370,7 @@ internal ArrayList SerializationProviders
{
if (this.designerSerializationProviders == null)
{
return new ArrayList();
return [];
}
return this.designerSerializationProviders.Clone() as ArrayList;
}
Expand Down Expand Up @@ -447,24 +442,20 @@ protected virtual object CreateInstance(Type type, ICollection arguments, string
obj = null;
}
}
if ((obj == null & addToContainer) && typeof(IComponent).IsAssignableFrom(type) && (array == null || array.Length == 0 || (array.Length == 1 && array[0] == this.Container)))
if ((obj == null & addToContainer)
&& typeof(IComponent).IsAssignableFrom(type)
&& (array == null || array.Length == 0 || (array.Length == 1 && array[0] == this.Container))
&& this.GetService(typeof(IDesignerHost)) is IDesignerHost designerHost && designerHost.Container == this.Container)
{
if (this.GetService(typeof(IDesignerHost)) is IDesignerHost designerHost && designerHost.Container == this.Container)
bool flag = false;
if (!this.PreserveNames && name != null && this.Container.Components[name] != null)
{
bool flag = false;
if (!this.PreserveNames && name != null && this.Container.Components[name] != null)
{
flag = true;
}
if (name == null | flag)
{
obj = designerHost.CreateComponent(type);
}
else
{
obj = designerHost.CreateComponent(type, name);
}
flag = true;
}

obj = (name == null | flag)
? designerHost.CreateComponent(type)
: designerHost.CreateComponent(type, name);
}
if (obj == null)
{
Expand Down Expand Up @@ -509,6 +500,8 @@ protected virtual object CreateInstance(Type type, ICollection arguments, string
}
catch (InvalidCastException)
{
// Type conversion failed - this constructor parameter doesn't match.
// Fall through to set flag2 = false and break.
}
}
flag2 = false;
Expand All @@ -532,7 +525,7 @@ protected virtual object CreateInstance(Type type, ICollection arguments, string
}
catch (MissingMethodException)
{
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder = new();
object[] array4 = array;
for (int l = 0; l < array4.Length; l++)
{
Expand All @@ -550,11 +543,11 @@ protected virtual object CreateInstance(Type type, ICollection arguments, string
stringBuilder.Append("null");
}
}
throw new SerializationException(SR.GetString("SerializationManagerNoMatchingCtor", new object[]
{
throw new SerializationException(SR.GetString("SerializationManagerNoMatchingCtor",
[
type.FullName,
stringBuilder.ToString()
}))
]))
{
HelpLink = "SerializationManagerNoMatchingCtor"
};
Expand Down Expand Up @@ -641,10 +634,7 @@ public object GetSerializer(Type objectType, Type serializerType)
}
if (obj != null && this.session != null)
{
if (this.serializers == null)
{
this.serializers = new Hashtable();
}
this.serializers ??= [];
this.serializers[objectType] = obj;
}
}
Expand All @@ -662,10 +652,7 @@ public object GetSerializer(Type objectType, Type serializerType)
((IDesignerSerializationManager)this).AddSerializationProvider(designerSerializationProvider);
}
}
if (this.defaultProviderTable == null)
{
this.defaultProviderTable = new Hashtable();
}
this.defaultProviderTable ??= [];
this.defaultProviderTable[serializerType] = type;
}
if (this.designerSerializationProviders != null)
Expand Down Expand Up @@ -712,15 +699,12 @@ protected virtual object GetService(Type serviceType)
protected virtual Type GetType(string typeName)
{
Type type = this.GetRuntimeType(typeName);
if (type != null)
if (type != null && this.GetService(typeof(TypeDescriptionProviderService)) is TypeDescriptionProviderService typeDescriptionProviderService)
{
if (this.GetService(typeof(TypeDescriptionProviderService)) is TypeDescriptionProviderService typeDescriptionProviderService)
TypeDescriptionProvider typeDescriptionProvider = typeDescriptionProviderService.GetProvider(type);
if (!typeDescriptionProvider.IsSupportedType(type))
{
TypeDescriptionProvider typeDescriptionProvider = typeDescriptionProviderService.GetProvider(type);
if (!typeDescriptionProvider.IsSupportedType(type))
{
type = null;
}
type = null;
}
}
return type;
Expand All @@ -736,16 +720,10 @@ public Type GetRuntimeType(string typeName)
this.typeResolver = (this.GetService(typeof(ITypeResolutionService)) as ITypeResolutionService);
this.searchedTypeResolver = true;
}
Type type;
if (this.typeResolver == null)
{
type = Type.GetType(typeName);
}
else
{
type = this.typeResolver.GetType(typeName);
}
return type;

return this.typeResolver == null
? Type.GetType(typeName)
: this.typeResolver.GetType(typeName);
}

/// <summary>Raises the <see cref="E:System.ComponentModel.Design.Serialization.IDesignerSerializationManager.ResolveName" /> event. </summary>
Expand Down Expand Up @@ -800,16 +778,13 @@ private PropertyDescriptor WrapProperty(PropertyDescriptor property, object owne
}

/// <summary>Adds a custom serialization provider to the serialization manager.</summary>
/// <param name="provider">The serialization provider to add.</param>
void IDesignerSerializationManager.AddSerializationProvider(IDesignerSerializationProvider provider)
/// <param name="serializationProvider">The serialization provider to add.</param>
void IDesignerSerializationManager.AddSerializationProvider(IDesignerSerializationProvider serializationProvider)
{
if (this.designerSerializationProviders == null)
{
this.designerSerializationProviders = new ArrayList();
}
if (!this.designerSerializationProviders.Contains(provider))
this.designerSerializationProviders ??= [];
if (!this.designerSerializationProviders.Contains(serializationProvider))
{
this.designerSerializationProviders.Add(provider);
this.designerSerializationProviders.Add(serializationProvider);
}
}

Expand All @@ -824,20 +799,20 @@ object IDesignerSerializationManager.CreateInstance(Type type, ICollection argum
this.CheckSession();
if (name != null && this.instancesByName != null && this.instancesByName.ContainsKey(name))
{
throw new SerializationException(SR.GetString("SerializationManagerDuplicateComponentDecl", new object[]
{
throw new SerializationException(SR.GetString("SerializationManagerDuplicateComponentDecl",
[
name
}))
]))
{
HelpLink = "SerializationManagerDuplicateComponentDecl"
};
}
object obj = this.CreateInstance(type, arguments, name, addToContainer);
if (name != null && (!(obj is IComponent) || !this.RecycleInstances))
if (name != null && (obj is not IComponent || !this.RecycleInstances))
{
if (this.instancesByName == null)
{
this.instancesByName = new Hashtable();
this.instancesByName = [];
this.namesByInstance = new Hashtable(new DesignerSerializationManager.ReferenceComparer());
}
this.instancesByName[name] = obj;
Expand Down Expand Up @@ -870,7 +845,7 @@ object IDesignerSerializationManager.GetInstance(string name)
}
if (obj == null)
{
ResolveNameEventArgs resolveNameEventArgs = new ResolveNameEventArgs(name);
ResolveNameEventArgs resolveNameEventArgs = new(name);
this.OnResolveName(resolveNameEventArgs);
obj = resolveNameEventArgs.Value;
}
Expand Down Expand Up @@ -900,14 +875,9 @@ string IDesignerSerializationManager.GetName(object value)
ISite site = component.Site;
if (site != null)
{
if (site is INestedSite nestedSite)
{
text = nestedSite.FullName;
}
else
{
text = site.Name;
}
text = site is INestedSite nestedSite
? nestedSite.FullName
: site.Name;
}
}
return text;
Expand Down Expand Up @@ -947,10 +917,10 @@ Type IDesignerSerializationManager.GetType(string typeName)
}

/// <summary>Removes a previously added serialization provider.</summary>
/// <param name="provider">The <see cref="T:System.ComponentModel.Design.Serialization.IDesignerSerializationProvider" /> to remove.</param>
void IDesignerSerializationManager.RemoveSerializationProvider(IDesignerSerializationProvider provider)
/// <param name="serializationProvider">The <see cref="T:System.ComponentModel.Design.Serialization.IDesignerSerializationProvider" /> to remove.</param>
void IDesignerSerializationManager.RemoveSerializationProvider(IDesignerSerializationProvider serializationProvider)
{
this.designerSerializationProviders?.Remove(provider);
this.designerSerializationProviders?.Remove(serializationProvider);
}

/// <summary>Used to report a recoverable error in serialization.</summary>
Expand Down Expand Up @@ -984,23 +954,23 @@ void IDesignerSerializationManager.SetName(object instance, string name)
}
if (this.instancesByName == null)
{
this.instancesByName = new Hashtable();
this.instancesByName = [];
this.namesByInstance = new Hashtable(new DesignerSerializationManager.ReferenceComparer());
}
if (this.instancesByName[name] != null)
{
throw new ArgumentException(SR.GetString("SerializationManagerNameInUse", new object[]
{
throw new ArgumentException(SR.GetString("SerializationManagerNameInUse",
[
name
}));
]));
}
if (this.namesByInstance[instance] != null)
{
throw new ArgumentException(SR.GetString("SerializationManagerObjectHasName", new object[]
{
throw new ArgumentException(SR.GetString("SerializationManagerObjectHasName",
[
name,
(string)this.namesByInstance[instance]
}));
]));
}
this.instancesByName[name] = instance;
this.namesByInstance[instance] = name;
Expand Down
18 changes: 9 additions & 9 deletions LogicBuilder.ComponentModel.Design.Serialization/SR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1827,32 +1827,32 @@ private static LogicBuilder.ComponentModel.Design.Serialization.SR GetLoader()

public static object GetObject(string name)
{
LogicBuilder.ComponentModel.Design.Serialization.SR loader = GetLoader();
if (loader == null)
LogicBuilder.ComponentModel.Design.Serialization.SR loaderLocal = GetLoader();
if (loaderLocal == null)
{
return null;
}
return loader.resources.GetObject(name, Culture);
return loaderLocal.resources.GetObject(name, Culture);
}

public static string GetString(string name)
{
LogicBuilder.ComponentModel.Design.Serialization.SR loader = GetLoader();
if (loader == null)
LogicBuilder.ComponentModel.Design.Serialization.SR loaderLocal = GetLoader();
if (loaderLocal == null)
{
return null;
}
return loader.resources.GetString(name, Culture);
return loaderLocal.resources.GetString(name, Culture);
}

public static string GetString(string name, params object[] args)
{
LogicBuilder.ComponentModel.Design.Serialization.SR loader = GetLoader();
if (loader == null)
LogicBuilder.ComponentModel.Design.Serialization.SR loaderLocal = GetLoader();
if (loaderLocal == null)
{
return null;
}
string format = loader.resources.GetString(name, Culture);
string format = loaderLocal.resources.GetString(name, Culture);
if ((args == null) || (args.Length <= 0))
{
return format;
Expand Down