From 99788dd10b26a946dc69665cb9a37886057419d8 Mon Sep 17 00:00:00 2001 From: Eideren Date: Sun, 1 Oct 2023 18:34:34 +0200 Subject: [PATCH 01/11] [Serialization] Fix diverging rules for editor and runtime serialization of fields and properties --- .../assets/Stride.Core.Assets/AssetItem.cs | 5 ++ .../ComplexSerializerRegistry.cs | 29 +++++++- .../Settings/SettingsFile.cs | 1 + .../MemberDescriptors/FieldDescriptor.cs | 2 +- .../MemberDescriptors/PropertyDescriptor.cs | 8 +- .../TypeDescriptors/ObjectDescriptor.cs | 74 +++++++++++++++---- .../Engine/TransformComponent.cs | 6 +- sources/engine/Stride.Graphics/Sprite.cs | 2 + sources/engine/Stride.Graphics/SpriteFont.cs | 1 + .../Stride.Rendering/Rendering/Model.cs | 24 ++---- .../Rendering/Shadows/ShadowMapRenderer.cs | 8 +- 11 files changed, 109 insertions(+), 51 deletions(-) diff --git a/sources/assets/Stride.Core.Assets/AssetItem.cs b/sources/assets/Stride.Core.Assets/AssetItem.cs index 768187da88..f349db022c 100644 --- a/sources/assets/Stride.Core.Assets/AssetItem.cs +++ b/sources/assets/Stride.Core.Assets/AssetItem.cs @@ -59,6 +59,7 @@ internal AssetItem([NotNull] UFile location, [NotNull] Asset asset, Package pack /// /// The location. [NotNull] + [DataMember] public UFile Location { get => location; internal set => location = value ?? throw new ArgumentNullException(nameof(value)); } /// @@ -84,6 +85,7 @@ internal AssetItem([NotNull] UFile location, [NotNull] Asset asset, Package pack /// Gets the package where this asset is stored. /// /// The package. + [DataMember] public Package Package { get; internal set; } /// @@ -187,6 +189,7 @@ public UFile FullPath /// /// The asset. [NotNull] + [DataMember] public Asset Asset { get => asset; internal set => asset = value ?? throw new ArgumentNullException(nameof(value)); } /// @@ -197,6 +200,7 @@ public UFile FullPath /// By default, contains the last modified time of the asset from the disk. If IsDirty is also updated from false to true /// , this time will get current time of modification. /// + [DataMember] public DateTime ModifiedTime { get; internal set; } private long version; @@ -204,6 +208,7 @@ public UFile FullPath /// /// Gets the asset version incremental counter, increased everytime the asset is edited. /// + [DataMember] public long Version { get => Interlocked.Read(ref version); internal set => Interlocked.Exchange(ref version, value); } /// diff --git a/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs b/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs index 99f0baf0bf..ba3a89137e 100644 --- a/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs +++ b/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs @@ -10,7 +10,6 @@ using System.Runtime.CompilerServices; using System.Text; using Mono.Cecil; -using Stride.Core; namespace Stride.Core.AssemblyProcessor { @@ -296,11 +295,14 @@ public static IEnumerable GetSerializableItems(TypeDefinition foreach (var property in type.Properties) { // Need a non-static public get method - if (property.GetMethod == null || !property.GetMethod.IsPublic || property.GetMethod.IsStatic) + if (property.GetMethod.IsStatic) continue; - // If it's a struct (!IsValueType), we need a public set method as well - if (property.PropertyType.IsValueType && (property.SetMethod == null || !(property.SetMethod.IsAssembly || property.SetMethod.IsPublic))) + if (IsAccessibleThroughAccessModifiers(property) == false) + continue; + + // If it's a struct (!IsValueType), we need a set method as well + if (property.PropertyType.IsValueType && property.SetMethod == null) continue; // Only take virtual properties (override ones will be handled by parent serializers) @@ -382,6 +384,25 @@ public static IEnumerable GetSerializableItems(TypeDefinition } } + static bool IsAccessibleThroughAccessModifiers(PropertyDefinition property) + { + var get = property.GetMethod; + var set = property.SetMethod; + + if (get == null) + return false; + + bool forced = property.CustomAttributes.Any(a => a.AttributeType.FullName == "Stride.Core.DataMemberAttribute"); + + if (forced && (get.IsPublic || get.IsAssembly)) + return true; + + if (get.IsPublic) + return set?.IsPublic == true || set == null && property.DeclaringType.Fields.Any(x => x.Name == $"<{property.Name}>k__BackingField"); + + return false; + } + internal static bool IsMemberIgnored(ICollection customAttributes, ComplexTypeSerializerFlags flags, DataMemberMode dataMemberMode) { // Check for DataMemberIgnore diff --git a/sources/core/Stride.Core.Design/Settings/SettingsFile.cs b/sources/core/Stride.Core.Design/Settings/SettingsFile.cs index a0946fcb1e..b6899944b9 100644 --- a/sources/core/Stride.Core.Design/Settings/SettingsFile.cs +++ b/sources/core/Stride.Core.Design/Settings/SettingsFile.cs @@ -22,6 +22,7 @@ public SettingsFile(SettingsProfile profile) /// /// Gets the settings profile to serialize. /// + [DataMember] [DataMemberCustomSerializer] public SettingsProfile Settings { get; private set; } } diff --git a/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs b/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs index 90a85e6917..1d313b900e 100644 --- a/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs @@ -30,7 +30,7 @@ public FieldDescriptor(ITypeDescriptor typeDescriptor, FieldInfo fieldInfo, Stri public override bool IsPublic => FieldInfo.IsPublic; - public override bool HasSet => true; + public override bool HasSet => !FieldInfo.IsInitOnly; public override object Get(object thisObject) { diff --git a/sources/core/Stride.Core.Reflection/MemberDescriptors/PropertyDescriptor.cs b/sources/core/Stride.Core.Reflection/MemberDescriptors/PropertyDescriptor.cs index a60fd6e517..061fe581e2 100644 --- a/sources/core/Stride.Core.Reflection/MemberDescriptors/PropertyDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/MemberDescriptors/PropertyDescriptor.cs @@ -21,11 +21,9 @@ public PropertyDescriptor(ITypeDescriptor typeDescriptor, PropertyInfo propertyI PropertyInfo = propertyInfo; - getMethod = propertyInfo.GetGetMethod(false) ?? propertyInfo.GetGetMethod(true); - if (propertyInfo.CanWrite && propertyInfo.GetSetMethod(!IsPublic) != null) - { - setMethod = propertyInfo.GetSetMethod(!IsPublic); - } + getMethod = propertyInfo.GetMethod; + setMethod = propertyInfo.SetMethod; + TypeDescriptor = typeDescriptor; } diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs index 65bcab1003..de4a17ad6f 100644 --- a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs @@ -190,7 +190,31 @@ public bool Contains(string memberName) protected virtual List PrepareMembers() { - if (Type == typeof(Type)) + if (Type == typeof(Type) || Type.IsAbstract || Type.IsInterface) + { + return EmptyMembers; + } + + if (Type.IsClass) + { + bool hasAnyContract = false; + for (var type = Type; type != typeof(object); type = type.BaseType) + { + if (type!.GetCustomAttribute(false) is {} dataContract) + { + hasAnyContract = dataContract.Inherited || Type == type; + break; + } + } + + if (hasAnyContract == false) + return EmptyMembers; + } + else if (Type.IsValueType && Type.GetCustomAttribute(false) is null) + { + return EmptyMembers; + } + else if (Type.IsEnum || Type.IsPrimitive) { return EmptyMembers; } @@ -213,10 +237,11 @@ protected virtual List PrepareMembers() } // TODO: we might want an option to disable non-public. - if (Category == DescriptorCategory.Object || Category == DescriptorCategory.NotSupportedObject) + if (Category is DescriptorCategory.Object or DescriptorCategory.NotSupportedObject) bindingFlags |= BindingFlags.NonPublic; var memberList = (from propertyInfo in Type.GetProperties(bindingFlags) + where IsAccessibleThroughAccessModifiers(propertyInfo) where propertyInfo.CanRead && propertyInfo.GetIndexParameters().Length == 0 && IsMemberToVisit(propertyInfo) select new PropertyDescriptor(factory.Find(propertyInfo.PropertyType), propertyInfo, NamingConvention.Comparer) into member @@ -225,7 +250,8 @@ where PrepareMember(member, metadataClassMemberInfos?.FirstOrDefault(x => x.Memb // Add all public fields memberList.AddRange(from fieldInfo in Type.GetFields(bindingFlags) - where fieldInfo.IsPublic && IsMemberToVisit(fieldInfo) + where (fieldInfo.IsPublic || (fieldInfo.IsAssembly && fieldInfo.GetCustomAttribute() != null)) + where IsMemberToVisit(fieldInfo) select new FieldDescriptor(factory.Find(fieldInfo.FieldType), fieldInfo, NamingConvention.Comparer) into member where PrepareMember(member, metadataClassMemberInfos?.FirstOrDefault(x => x.MemberInfo.Name == member.OriginalName && x.MemberType == member.Type).MemberInfo) @@ -237,6 +263,31 @@ where PrepareMember(member, metadataClassMemberInfos?.FirstOrDefault(x => x.Memb return memberList; } + static bool IsAccessibleThroughAccessModifiers(PropertyInfo property) + { + var get = property.GetMethod; + var set = property.SetMethod; + + if (get == null) + return false; + + bool forced = property.GetCustomAttribute() is not null; + + if (forced && (get.IsPublic || get.IsAssembly)) + return true; + + if (get.IsPublic) + return set?.IsPublic == true || set == null && TryGetBackingField(property, out _); + + return false; + } + + static bool TryGetBackingField(PropertyInfo property, out FieldInfo backingField) + { + backingField = property.DeclaringType.GetField($"<{property.Name}>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic); + return backingField != null; + } + protected virtual bool PrepareMember(MemberDescriptorBase member, MemberInfo metadataClassMemberInfo) { var memberType = member.Type; @@ -253,8 +304,7 @@ protected virtual bool PrepareMember(MemberDescriptorBase member, MemberInfo met } // Gets the style - var styleAttribute = attributes.FirstOrDefault(x => x is DataStyleAttribute) as DataStyleAttribute; - if (styleAttribute != null) + if (attributes.FirstOrDefault(x => x is DataStyleAttribute) is DataStyleAttribute styleAttribute) { member.Style = styleAttribute.Style; member.ScalarStyle = styleAttribute.ScalarStyle; @@ -265,14 +315,12 @@ protected virtual bool PrepareMember(MemberDescriptorBase member, MemberInfo met if (memberAttribute != null) { ((IMemberDescriptor)member).Mask = memberAttribute.Mask; + member.Mode = memberAttribute.Mode; if (!member.HasSet) { - if (memberAttribute.Mode == DataMemberMode.Assign || - (memberType.IsValueType && member.Mode == DataMemberMode.Content)) - throw new ArgumentException($"{memberType.FullName} {member.OriginalName} is not writeable by {memberAttribute.Mode.ToString()}."); + if (memberAttribute.Mode == DataMemberMode.Assign || memberType.IsValueType || memberType == typeof(string)) + member.Mode = DataMemberMode.Never; } - - member.Mode = memberAttribute.Mode; member.Order = memberAttribute.Order; } @@ -292,16 +340,14 @@ protected virtual bool PrepareMember(MemberDescriptorBase member, MemberInfo met DefaultValueAttribute defaultValueAttribute = null; foreach (var attribute in attributes) { - var valueAttribute = attribute as DefaultValueAttribute; - if (valueAttribute != null) + if (attribute is DefaultValueAttribute valueAttribute) { // If we've already found one, don't overwrite it defaultValueAttribute = defaultValueAttribute ?? valueAttribute; continue; } - var yamlRemap = attribute as DataAliasAttribute; - if (yamlRemap != null) + if (attribute is DataAliasAttribute yamlRemap) { if (member.AlternativeNames == null) { diff --git a/sources/engine/Stride.Engine/Engine/TransformComponent.cs b/sources/engine/Stride.Engine/Engine/TransformComponent.cs index 815b257811..2f2f584a44 100644 --- a/sources/engine/Stride.Engine/Engine/TransformComponent.cs +++ b/sources/engine/Stride.Engine/Engine/TransformComponent.cs @@ -32,8 +32,6 @@ public sealed class TransformComponent : EntityComponent //, IEnumerable @@ -89,7 +87,7 @@ public sealed class TransformComponent : EntityComponent //, IEnumerable public TransformComponent() { - children = new TransformChildrenCollection(this); + Children = new TransformChildrenCollection(this); UseTRS = true; Scale = Vector3.One; @@ -112,7 +110,7 @@ public bool UseTRS /// /// Gets the children of this . /// - public FastCollection Children => children; + public FastCollection Children { get; } /// /// Gets or sets the euler rotation, with XYZ order. diff --git a/sources/engine/Stride.Graphics/Sprite.cs b/sources/engine/Stride.Graphics/Sprite.cs index 963b7697ae..45ffcc151d 100644 --- a/sources/engine/Stride.Graphics/Sprite.cs +++ b/sources/engine/Stride.Graphics/Sprite.cs @@ -149,6 +149,7 @@ public Vector4 Borders /// /// Gets the value indicating if the image has unstretchable borders. /// + [DataMember] public bool HasBorders { get; private set; } /// @@ -164,6 +165,7 @@ public Vector2 Size /// Gets the size of the sprite in pixels. /// Note that the orientation of the image is taken into account in this calculation. /// + [DataMember] public Vector2 SizeInPixels { get { return sizeInPixels; } diff --git a/sources/engine/Stride.Graphics/SpriteFont.cs b/sources/engine/Stride.Graphics/SpriteFont.cs index 013e56db3c..319f6de04b 100644 --- a/sources/engine/Stride.Graphics/SpriteFont.cs +++ b/sources/engine/Stride.Graphics/SpriteFont.cs @@ -80,6 +80,7 @@ protected internal SpriteFont() /// /// Gets the font size (resp. the default font size) for static fonts (resp. for dynamic fonts) in pixels. /// + [DataMember] public float Size { get; internal set; } /// diff --git a/sources/engine/Stride.Rendering/Rendering/Model.cs b/sources/engine/Stride.Rendering/Rendering/Model.cs index 972e4d69ad..9e5cc455d8 100644 --- a/sources/engine/Stride.Rendering/Rendering/Model.cs +++ b/sources/engine/Stride.Rendering/Rendering/Model.cs @@ -28,9 +28,6 @@ namespace Stride.Rendering [DataContract] public class Model : IEnumerable { - private List meshes = new List(); - private readonly List materials = new List(); - private IList children; private Model parent; /// @@ -40,11 +37,7 @@ public class Model : IEnumerable /// The views. /// [MemberCollection(NotNullItems = true)] - public IList Children - { - get { return children; } - set { children = value; } - } + public IList Children { get; set; } /// /// Gets the materials. @@ -53,10 +46,7 @@ public IList Children /// The materials. /// [MemberCollection(NotNullItems = true)] - public List Materials - { - get { return materials; } - } + public List Materials { get; } = new(); /// /// Gets the meshes. @@ -65,11 +55,7 @@ public List Materials /// The meshes. /// [MemberCollection(NotNullItems = true)] - public List Meshes - { - get { return meshes; } - set { meshes = value; } - } + public List Meshes { get; set; } = new(); /// /// Gets or sets the hierarchy definition, which describes nodes name, default transformation and hierarchical parent. @@ -106,7 +92,7 @@ public List Meshes /// The model view. public void Add(Model model) { - children.Add(model); + Children.Add(model); } /// @@ -129,7 +115,7 @@ public void Add(MaterialInstance material) IEnumerator IEnumerable.GetEnumerator() { - return meshes.Cast().Concat(materials).GetEnumerator(); + return Meshes.Cast().Concat(Materials).GetEnumerator(); } /// diff --git a/sources/engine/Stride.Rendering/Rendering/Shadows/ShadowMapRenderer.cs b/sources/engine/Stride.Rendering/Rendering/Shadows/ShadowMapRenderer.cs index 261f100f5a..2143a68887 100644 --- a/sources/engine/Stride.Rendering/Rendering/Shadows/ShadowMapRenderer.cs +++ b/sources/engine/Stride.Rendering/Rendering/Shadows/ShadowMapRenderer.cs @@ -26,8 +26,6 @@ public class ShadowMapRenderer : IShadowMapRenderer private readonly int maximumTextureSize = (int)(ReferenceShadowSize * ComputeSizeFactor(LightShadowMapSize.XLarge) * 2.0f); private const float ReferenceShadowSize = 1024; - private readonly List shadowMapRenderStages; - private FastListStruct atlases; private readonly List shadowMaps = new List(); @@ -44,8 +42,10 @@ public ShadowMapRenderer() public HashSet RenderViewsWithShadows { get; } = new HashSet(); - // TODO - public IReadOnlyList ShadowMapRenderStages => shadowMapRenderStages; + /// + /// TODO + /// + public IReadOnlyList ShadowMapRenderStages { get; } public ILightShadowMapRenderer FindRenderer(IDirectLight light) { From 2f43d44eda38a4421bd3ba32594d13798ce0dec7 Mon Sep 17 00:00:00 2001 From: Eideren Date: Mon, 2 Oct 2023 00:44:25 +0200 Subject: [PATCH 02/11] Address review --- .../Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs | 2 ++ .../Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs | 2 ++ sources/engine/Stride.Graphics/Sprite.cs | 2 -- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs b/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs index ba3a89137e..75aa8f1051 100644 --- a/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs +++ b/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs @@ -397,6 +397,8 @@ static bool IsAccessibleThroughAccessModifiers(PropertyDefinition property) if (forced && (get.IsPublic || get.IsAssembly)) return true; + // By default, allow access for get-only auto-property, i.e.: { get; } but not { get => } + // as the later may create side effects, and without a setter, we can't 'set' as a fallback for those exceptional cases. if (get.IsPublic) return set?.IsPublic == true || set == null && property.DeclaringType.Fields.Any(x => x.Name == $"<{property.Name}>k__BackingField"); diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs index de4a17ad6f..e06b6c6425 100644 --- a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs @@ -276,6 +276,8 @@ static bool IsAccessibleThroughAccessModifiers(PropertyInfo property) if (forced && (get.IsPublic || get.IsAssembly)) return true; + // By default, allow access for get-only auto-property, i.e.: { get; } but not { get => } + // as the later may create side effects, and without a setter, we can't 'set' as a fallback for those exceptional cases. if (get.IsPublic) return set?.IsPublic == true || set == null && TryGetBackingField(property, out _); diff --git a/sources/engine/Stride.Graphics/Sprite.cs b/sources/engine/Stride.Graphics/Sprite.cs index 45ffcc151d..963b7697ae 100644 --- a/sources/engine/Stride.Graphics/Sprite.cs +++ b/sources/engine/Stride.Graphics/Sprite.cs @@ -149,7 +149,6 @@ public Vector4 Borders /// /// Gets the value indicating if the image has unstretchable borders. /// - [DataMember] public bool HasBorders { get; private set; } /// @@ -165,7 +164,6 @@ public Vector2 Size /// Gets the size of the sprite in pixels. /// Note that the orientation of the image is taken into account in this calculation. /// - [DataMember] public Vector2 SizeInPixels { get { return sizeInPixels; } From e2dce132360e4ed9ef74f890fa1368974fe2b430 Mon Sep 17 00:00:00 2001 From: Eideren Date: Mon, 2 Oct 2023 00:45:07 +0200 Subject: [PATCH 03/11] Throw instead of ignore and clarify exception --- .../TypeDescriptors/ObjectDescriptor.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs index e06b6c6425..36d358aeaf 100644 --- a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs @@ -320,8 +320,10 @@ protected virtual bool PrepareMember(MemberDescriptorBase member, MemberInfo met member.Mode = memberAttribute.Mode; if (!member.HasSet) { - if (memberAttribute.Mode == DataMemberMode.Assign || memberType.IsValueType || memberType == typeof(string)) - member.Mode = DataMemberMode.Never; + if (memberAttribute.Mode == DataMemberMode.Assign) + throw new ArgumentException($"{memberType.FullName} {member.OriginalName} is not writeable by {memberAttribute.Mode.ToString()}, its {nameof(DataMemberMode)} must not be {memberAttribute.Mode}."); + if (memberType.IsValueType || memberType == typeof(string)) + throw new ArgumentException($"{memberType.FullName} {member.OriginalName} is not writeable by {memberAttribute.Mode.ToString()}, {member.OriginalName} must have a setter."); } member.Order = memberAttribute.Order; } From 6d54e1a8d7aac7f13a26c16a62c77da3e7b73309 Mon Sep 17 00:00:00 2001 From: Eideren Date: Mon, 2 Oct 2023 13:30:24 +0200 Subject: [PATCH 04/11] Rollback previous commit, misread the conclusion in PR #1868 --- .../TypeDescriptors/ObjectDescriptor.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs index 36d358aeaf..e06b6c6425 100644 --- a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs @@ -320,10 +320,8 @@ protected virtual bool PrepareMember(MemberDescriptorBase member, MemberInfo met member.Mode = memberAttribute.Mode; if (!member.HasSet) { - if (memberAttribute.Mode == DataMemberMode.Assign) - throw new ArgumentException($"{memberType.FullName} {member.OriginalName} is not writeable by {memberAttribute.Mode.ToString()}, its {nameof(DataMemberMode)} must not be {memberAttribute.Mode}."); - if (memberType.IsValueType || memberType == typeof(string)) - throw new ArgumentException($"{memberType.FullName} {member.OriginalName} is not writeable by {memberAttribute.Mode.ToString()}, {member.OriginalName} must have a setter."); + if (memberAttribute.Mode == DataMemberMode.Assign || memberType.IsValueType || memberType == typeof(string)) + member.Mode = DataMemberMode.Never; } member.Order = memberAttribute.Order; } From 0cac54cb91f1c219773ddaa5af251812a5d3e3b4 Mon Sep 17 00:00:00 2001 From: Eideren Date: Mon, 2 Oct 2023 21:48:57 +0200 Subject: [PATCH 05/11] Fix tests and anonymous type serialization --- .../TestSerializing.TestMyAssetObject.cs | 3 +- .../Selectors/TagSelector.cs | 1 + .../Stride.Core.Assets/SolutionPlatform.cs | 2 + .../Stride.Core.Assets/Yaml/YamlAssetPath.cs | 1 + .../TypeDescriptors/ObjectDescriptor.cs | 30 ++--------- .../Stride.Core.Yaml.Tests/DescriptorTests.cs | 2 +- .../Serialization/SerializationTests2.cs | 22 +++----- sources/core/Stride.Core/DataMemberMode.cs | 6 +-- .../TestMemberRequiredComponentChecks.cs | 23 ++++++--- .../Stride.Graphics/VertexDeclaration.cs | 6 +-- .../Rendering/SkeletonUpdater.cs | 51 ++++++++----------- .../Analysis/StrideParsingInfo.cs | 13 +++++ .../Mixins/ReferencesPool.cs | 2 + 13 files changed, 73 insertions(+), 89 deletions(-) diff --git a/sources/assets/Stride.Core.Assets.Tests/TestSerializing.TestMyAssetObject.cs b/sources/assets/Stride.Core.Assets.Tests/TestSerializing.TestMyAssetObject.cs index 1a547731c0..bda26eb62c 100644 --- a/sources/assets/Stride.Core.Assets.Tests/TestSerializing.TestMyAssetObject.cs +++ b/sources/assets/Stride.Core.Assets.Tests/TestSerializing.TestMyAssetObject.cs @@ -65,7 +65,8 @@ public MyAsset() public MyDictionaryPure MapItems3 { get; set; } - public object CustomObjectWithProtectedSet { get; protected set; } + [DataMember] + public CustomObject CustomObjectWithProtectedSet { get; protected set; } } [DataContract("CustomObject")] diff --git a/sources/assets/Stride.Core.Assets/Selectors/TagSelector.cs b/sources/assets/Stride.Core.Assets/Selectors/TagSelector.cs index ac2d4c0c90..71abe4a41a 100644 --- a/sources/assets/Stride.Core.Assets/Selectors/TagSelector.cs +++ b/sources/assets/Stride.Core.Assets/Selectors/TagSelector.cs @@ -25,6 +25,7 @@ public TagSelector() /// Gets the tags that will be used to select an asset. /// /// The tags. + [DataMember] public TagCollection Tags { get; private set; } public override IEnumerable Select(PackageSession packageSession, IContentIndexMap contentIndexMap) diff --git a/sources/assets/Stride.Core.Assets/SolutionPlatform.cs b/sources/assets/Stride.Core.Assets/SolutionPlatform.cs index 41b67705ee..06a58baa55 100644 --- a/sources/assets/Stride.Core.Assets/SolutionPlatform.cs +++ b/sources/assets/Stride.Core.Assets/SolutionPlatform.cs @@ -283,6 +283,7 @@ public SolutionConfiguration(string name) /// Gets or sets the configuration name (e.g. Debug, Release) /// /// The name. + [DataMember] public string Name { get; private set; } /// @@ -295,6 +296,7 @@ public SolutionConfiguration(string name) /// Gets the additional msbuild properties for a specific configuration (Debug or Release) /// /// The msbuild configuration properties. + [DataMember] public List Properties { get; private set; } } } diff --git a/sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs b/sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs index 736ffb24b5..8969f7d6f9 100644 --- a/sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs +++ b/sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs @@ -127,6 +127,7 @@ public YamlAssetPath([NotNull] IEnumerable elements) /// /// The elements constituting this path. /// + [DataMember] public IReadOnlyList Elements => elements; /// diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs index e06b6c6425..b6dce14074 100644 --- a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs @@ -190,31 +190,7 @@ public bool Contains(string memberName) protected virtual List PrepareMembers() { - if (Type == typeof(Type) || Type.IsAbstract || Type.IsInterface) - { - return EmptyMembers; - } - - if (Type.IsClass) - { - bool hasAnyContract = false; - for (var type = Type; type != typeof(object); type = type.BaseType) - { - if (type!.GetCustomAttribute(false) is {} dataContract) - { - hasAnyContract = dataContract.Inherited || Type == type; - break; - } - } - - if (hasAnyContract == false) - return EmptyMembers; - } - else if (Type.IsValueType && Type.GetCustomAttribute(false) is null) - { - return EmptyMembers; - } - else if (Type.IsEnum || Type.IsPrimitive) + if (Type == typeof(Type)) { return EmptyMembers; } @@ -241,8 +217,8 @@ protected virtual List PrepareMembers() bindingFlags |= BindingFlags.NonPublic; var memberList = (from propertyInfo in Type.GetProperties(bindingFlags) - where IsAccessibleThroughAccessModifiers(propertyInfo) - where propertyInfo.CanRead && propertyInfo.GetIndexParameters().Length == 0 && IsMemberToVisit(propertyInfo) + where Type.IsAnonymous() || IsAccessibleThroughAccessModifiers(propertyInfo) + where propertyInfo.GetIndexParameters().Length == 0 && IsMemberToVisit(propertyInfo) select new PropertyDescriptor(factory.Find(propertyInfo.PropertyType), propertyInfo, NamingConvention.Comparer) into member where PrepareMember(member, metadataClassMemberInfos?.FirstOrDefault(x => x.MemberInfo.Name == member.OriginalName && x.MemberType == member.Type).MemberInfo) diff --git a/sources/core/Stride.Core.Yaml.Tests/DescriptorTests.cs b/sources/core/Stride.Core.Yaml.Tests/DescriptorTests.cs index 898f5d68bd..f807c03d2d 100644 --- a/sources/core/Stride.Core.Yaml.Tests/DescriptorTests.cs +++ b/sources/core/Stride.Core.Yaml.Tests/DescriptorTests.cs @@ -77,7 +77,7 @@ public TestObject() public ICollection Collection { get; set; } - public ICollection CollectionReadOnly { get; private set; } + public ICollection CollectionReadOnly { get; } [DataMemberIgnore] public string DontSerialize { get; set; } diff --git a/sources/core/Stride.Core.Yaml.Tests/Serialization/SerializationTests2.cs b/sources/core/Stride.Core.Yaml.Tests/Serialization/SerializationTests2.cs index 9b343677bc..cddc1e1351 100644 --- a/sources/core/Stride.Core.Yaml.Tests/Serialization/SerializationTests2.cs +++ b/sources/core/Stride.Core.Yaml.Tests/Serialization/SerializationTests2.cs @@ -221,6 +221,7 @@ public MyObject() public int[] Array { get; set; } + [DataMember] public int[] ArrayContent { get; private set; } } @@ -576,6 +577,7 @@ public MyCustomClassWithSpecialMembers() /// value of the list stored in this instance instead of /// creating a new List<T>l instance. /// + [DataMember] public List StringListByContent { get; private set; } /// @@ -595,6 +597,7 @@ public MyCustomClassWithSpecialMembers() /// Idem as for but for dictionary. /// /// The content of the string mapby. + [DataMember] public Dictionary StringMapbyContent { get; private set; } /// @@ -603,7 +606,8 @@ public MyCustomClassWithSpecialMembers() /// creating a new List<T>l instance. /// /// The content of the list by. - public IList ListByContent { get; private set; } + [DataMember] + public List ListByContent { get; private set; } } /// @@ -1506,21 +1510,6 @@ public class ObjectWithMask internal int Int3 { get; set; } } - [Fact] - public void TestImplicitMemberType() - { - var settings = new SerializerSettings() {LimitPrimitiveFlowSequence = 0}; - - var text = @"!ClassWithImplicitMemberType -Test: - String: test -"; - - settings.RegisterTagMapping("ClassWithImplicitMemberType", typeof(ClassWithImplicitMemberType)); - settings.RegisterTagMapping("ClassWithImplicitMemberTypeInner", typeof(ClassWithImplicitMemberTypeInner)); - SerialRoundTrip(settings, text); - } - [Fact] public void TestNonImplicitMemberType() { @@ -1567,6 +1556,7 @@ public ClassWithImplicitMemberType() Test = new ClassWithImplicitMemberTypeInner {String = "test"}; } + [DataMember] public object Test { get; protected set; } } diff --git a/sources/core/Stride.Core/DataMemberMode.cs b/sources/core/Stride.Core/DataMemberMode.cs index a95e26c81b..272df06038 100644 --- a/sources/core/Stride.Core/DataMemberMode.cs +++ b/sources/core/Stride.Core/DataMemberMode.cs @@ -20,15 +20,15 @@ public enum DataMemberMode Assign, /// - /// Only valid for a property / field that has a class or struct type. - /// When restored, instead of recreating the whole class or struct, + /// Only valid for a property / field that return a class, no strings, primitives or value types. + /// When restored, instead of recreating the whole class, /// the members are independently restored. When the property / field /// is not writeable this is the default. /// Content, /// - /// Only valid for a property / field that has an array type of a + /// Only valid for a property / field that has an array type of /// some value type. The content of the array is stored in a binary /// format encoded in base64 style. /// diff --git a/sources/engine/Stride.Assets.Tests/TestMemberRequiredComponentChecks.cs b/sources/engine/Stride.Assets.Tests/TestMemberRequiredComponentChecks.cs index e24c949ed2..8fa3b50c05 100644 --- a/sources/engine/Stride.Assets.Tests/TestMemberRequiredComponentChecks.cs +++ b/sources/engine/Stride.Assets.Tests/TestMemberRequiredComponentChecks.cs @@ -28,16 +28,17 @@ public class MemberRequiredComponent : VirtualBaseComponent // it would duplicate tests and it's more important to assert // that presence of the attribute gives a warning [MemberRequired] public object PublicField; + [DataMember][MemberRequired] internal object InternalField; [MemberRequired] public object PublicProp { get; set; } [MemberRequired] - [DataMember] private object PrivateProp { get; set; } + [DataMember] public object PrivateProp { get; private set; } [MemberRequired] - [DataMember] protected object ProtectedProp { get; set; } + [DataMember] internal object InternalProp { get; set; } public override object VirtualProp { get; set; } = new object(); - public MemberRequiredComponent(object privateData, object protectedData) + public MemberRequiredComponent(object privateData, object internalData) { PrivateProp = privateData; - ProtectedProp = protectedData; + InternalProp = internalData; } } @@ -46,6 +47,7 @@ void EntityIsNotMissingRequiredMembers() { var memberRequiredComponent = new MemberRequiredComponent(new object(), new object()) { + InternalField = new object(), PublicProp = new object(), PublicField = new object(), }; @@ -65,6 +67,7 @@ void EntityIsMissingRequiredMember_PublicField() { var memberRequiredComponent = new MemberRequiredComponent(new object(), new object()) { + InternalField = new object(), PublicProp = new object(), PublicField = null, }; @@ -77,6 +80,7 @@ void EntityIsMissingRequiredMember_PublicProp() { var memberRequiredComponent = new MemberRequiredComponent(new object(), new object()) { + InternalField = new object(), PublicProp = null, PublicField = new object(), }; @@ -89,22 +93,24 @@ void EntityIsMissingRequiredMember_PrivateProp() { var memberRequiredComponent = new MemberRequiredComponent(null, new object()) { + InternalField = new object(), PublicProp = new object(), PublicField = new object(), }; - var memberName = "PrivateProp"; + var memberName = nameof(MemberRequiredComponent.PrivateProp); TestSingle(memberRequiredComponent, memberName); } [Fact] - void EntityIsMissingRequiredMember_ProtectedProp() + void EntityIsMissingRequiredMember_InternalProp() { var memberRequiredComponent = new MemberRequiredComponent(new object(), null) { + InternalField = new object(), PublicProp = new object(), PublicField = new object(), }; - var memberName = "ProtectedProp"; + var memberName = nameof(MemberRequiredComponent.InternalProp); TestSingle(memberRequiredComponent, memberName); } @@ -124,7 +130,7 @@ void EntityIsMissingAllRequiredMembers() Assert.True(check.AppliesTo(memberRequiredComponent.GetType())); check.Check(memberRequiredComponent, entity, null, "", result); - Assert.Equal(4, result.Messages.Count); + Assert.Equal(5, result.Messages.Count); } [Fact] @@ -132,6 +138,7 @@ void EntityIsMissingRequiredMember_VirtualProp() { var memberRequiredComponent = new MemberRequiredComponent(new object(), new object()) { + InternalField = new object(), PublicProp = new object(), PublicField = new object(), VirtualProp = null, diff --git a/sources/engine/Stride.Graphics/VertexDeclaration.cs b/sources/engine/Stride.Graphics/VertexDeclaration.cs index ee42aea819..df6eb323c5 100644 --- a/sources/engine/Stride.Graphics/VertexDeclaration.cs +++ b/sources/engine/Stride.Graphics/VertexDeclaration.cs @@ -64,10 +64,8 @@ public VertexDeclaration(VertexElement[] elements, int instanceCount, int vertex /// Gets the vertex elements. /// /// The vertex elements. - public VertexElement[] VertexElements - { - get { return elements; } - } + [DataMember] + public VertexElement[] VertexElements => elements; /// /// Gets the instance count. diff --git a/sources/engine/Stride.Rendering/Rendering/SkeletonUpdater.cs b/sources/engine/Stride.Rendering/Rendering/SkeletonUpdater.cs index 0b5183f20a..38a20dc7f2 100644 --- a/sources/engine/Stride.Rendering/Rendering/SkeletonUpdater.cs +++ b/sources/engine/Stride.Rendering/Rendering/SkeletonUpdater.cs @@ -16,20 +16,13 @@ namespace Stride.Rendering [DataContract] // Here for update engine; TODO: better separation and different attribute? public class SkeletonUpdater { - private ModelNodeDefinition[] nodes; - private ModelNodeTransformation[] nodeTransformations; - private int matrixCounter; - public ModelNodeDefinition[] Nodes - { - get { return nodes; } - } + [DataMember] + public ModelNodeDefinition[] Nodes { get; private set; } - public ModelNodeTransformation[] NodeTransformations - { - get { return nodeTransformations; } - } + [DataMember] + public ModelNodeTransformation[] NodeTransformations { get; private set; } private static ModelNodeDefinition[] GetDefaultNodeDefinitions() { @@ -49,26 +42,26 @@ public void Initialize(Skeleton skeleton) { var newNodes = skeleton?.Nodes; - if (this.nodes == newNodes && this.nodes != null) + if (this.Nodes == newNodes && this.Nodes != null) { return; } - this.nodes = newNodes ?? GetDefaultNodeDefinitions(); + this.Nodes = newNodes ?? GetDefaultNodeDefinitions(); - if (nodeTransformations == null || nodeTransformations.Length < this.nodes.Length) - nodeTransformations = new ModelNodeTransformation[this.nodes.Length]; + if (NodeTransformations == null || NodeTransformations.Length < this.Nodes.Length) + NodeTransformations = new ModelNodeTransformation[this.Nodes.Length]; - for (int index = 0; index < nodes.Length; index++) + for (int index = 0; index < Nodes.Length; index++) { - nodeTransformations[index].ParentIndex = nodes[index].ParentIndex; - nodeTransformations[index].Transform = nodes[index].Transform; - nodeTransformations[index].Flags = nodes[index].Flags; - nodeTransformations[index].RenderingEnabledRecursive = true; - UpdateLocalMatrix(ref nodeTransformations[index]); + NodeTransformations[index].ParentIndex = Nodes[index].ParentIndex; + NodeTransformations[index].Transform = Nodes[index].Transform; + NodeTransformations[index].Flags = Nodes[index].Flags; + NodeTransformations[index].RenderingEnabledRecursive = true; + UpdateLocalMatrix(ref NodeTransformations[index]); } - nodeTransformations[0].Flags &= ~ModelNodeFlags.EnableTransform; + NodeTransformations[0].Flags &= ~ModelNodeFlags.EnableTransform; } /// @@ -76,10 +69,10 @@ public void Initialize(Skeleton skeleton) /// public void ResetInitialValues() { - var nodesLocal = nodes; + var nodesLocal = Nodes; for (int index = 0; index < nodesLocal.Length; index++) { - nodeTransformations[index].Transform = nodesLocal[index].Transform; + NodeTransformations[index].Transform = nodesLocal[index].Transform; } } @@ -89,22 +82,22 @@ public void ResetInitialValues() public void UpdateMatrices() { // Compute transformations - var nodesLength = nodes.Length; + var nodesLength = Nodes.Length; for (int index = 0; index < nodesLength; index++) { - UpdateNode(ref nodeTransformations[index]); + UpdateNode(ref NodeTransformations[index]); } matrixCounter++; } public void GetWorldMatrix(int index, out Matrix matrix) { - matrix = nodeTransformations[index].WorldMatrix; + matrix = NodeTransformations[index].WorldMatrix; } public void GetLocalMatrix(int index, out Matrix matrix) { - matrix = nodeTransformations[index].LocalMatrix; + matrix = NodeTransformations[index].LocalMatrix; } private void UpdateNode(ref ModelNodeTransformation node) @@ -115,7 +108,7 @@ private void UpdateNode(ref ModelNodeTransformation node) UpdateLocalMatrix(ref node); } - var nodeTransformationsLocal = this.nodeTransformations; + var nodeTransformationsLocal = this.NodeTransformations; var parentIndex = node.ParentIndex; diff --git a/sources/engine/Stride.Shaders.Parser/Analysis/StrideParsingInfo.cs b/sources/engine/Stride.Shaders.Parser/Analysis/StrideParsingInfo.cs index 8c176923f5..b9f1764509 100644 --- a/sources/engine/Stride.Shaders.Parser/Analysis/StrideParsingInfo.cs +++ b/sources/engine/Stride.Shaders.Parser/Analysis/StrideParsingInfo.cs @@ -17,67 +17,80 @@ internal class StrideParsingInfo /// /// Variables that referenced the stage class ( "= stage" ) /// + [DataMember] public HashSet StageInitializedVariables { get; private set; } /// /// All typedefs /// + [DataMember] public List Typedefs { get; private set; } /// /// All structure definitions /// + [DataMember] public List StructureDefinitions { get; private set; } /// /// All the base method calls (base.xxx) /// + [DataMember] public HashSet BaseMethodCalls { get; private set; } /// /// All the method calls that are not base /// + [DataMember] public HashSet ThisMethodCalls { get; private set; } /// /// All the method calls to stage methods /// + [DataMember] public HashSet StageMethodCalls { get; private set; } /// /// All foreach statements /// + [DataMember] public HashSet ForEachStatements { get; private set; } /// /// References to members of the current shader /// + [DataMember] public ReferencesPool ClassReferences { get; private set; } /// /// Static references to class members /// + [DataMember] public ReferencesPool StaticReferences { get; private set; } /// /// References to extern members /// + [DataMember] public ReferencesPool ExternReferences { get; private set; } /// /// References to stage initialized variables and methods /// + [DataMember] public ReferencesPool StageInitReferences { get; private set; } /// /// Gets navigable nodes (local variables, base class...etc.) /// /// The navigable nodes. + [DataMember] public List NavigableNodes { get; private set; } /// /// List of the static classes /// + [DataMember] public HashSet StaticClasses { get; private set; } #endregion diff --git a/sources/engine/Stride.Shaders.Parser/Mixins/ReferencesPool.cs b/sources/engine/Stride.Shaders.Parser/Mixins/ReferencesPool.cs index 4ca152375f..8684452c88 100644 --- a/sources/engine/Stride.Shaders.Parser/Mixins/ReferencesPool.cs +++ b/sources/engine/Stride.Shaders.Parser/Mixins/ReferencesPool.cs @@ -18,11 +18,13 @@ internal class ReferencesPool /// /// List of all the variable references /// + [DataMember] public Dictionary> VariablesReferences { get; private set; } /// /// List of all the variable references /// + [DataMember] public Dictionary> MethodsReferences { get; private set; } public ReferencesPool() From 02384894fc73b8e905086ad2f9098474ac383a15 Mon Sep 17 00:00:00 2001 From: Eideren Date: Mon, 2 Oct 2023 21:52:22 +0200 Subject: [PATCH 06/11] Finish API coverage from serialization changes --- sources/assets/Stride.Core.Assets/Bundle.cs | 2 ++ sources/core/Stride.Core/PropertyKey.cs | 1 + sources/core/Stride.Core/Settings/AppSettings.cs | 12 +++++++----- .../Stride.Engine/Engine/AnimationComponent.cs | 9 +++------ sources/engine/Stride.Navigation/NavigationMesh.cs | 1 + .../Materials/ComputeColors/ComputeColorParameter.cs | 1 + sources/engine/Stride.Rendering/Rendering/Mesh.cs | 8 ++++---- .../Mixins/MixinVirtualTable.cs | 6 +++++- .../Stride.Core.ProjectTemplating/ProjectTemplate.cs | 2 ++ 9 files changed, 26 insertions(+), 16 deletions(-) diff --git a/sources/assets/Stride.Core.Assets/Bundle.cs b/sources/assets/Stride.Core.Assets/Bundle.cs index f049026f4c..8d589b4f42 100644 --- a/sources/assets/Stride.Core.Assets/Bundle.cs +++ b/sources/assets/Stride.Core.Assets/Bundle.cs @@ -33,12 +33,14 @@ public Bundle() /// Gets the selectors used by this bundle. /// /// The selectors. + [DataMember] public List Selectors { get; private set; } /// /// Gets the bundle dependencies. /// /// The dependencies. + [DataMember] public List Dependencies { get; private set; } /// diff --git a/sources/core/Stride.Core/PropertyKey.cs b/sources/core/Stride.Core/PropertyKey.cs index 4cd9f9a393..5dafab6d5d 100644 --- a/sources/core/Stride.Core/PropertyKey.cs +++ b/sources/core/Stride.Core/PropertyKey.cs @@ -42,6 +42,7 @@ protected PropertyKey([NotNull] string name, Type propertyType, Type ownerType, /// /// Gets the name of this key. /// + [DataMember] public string Name { get; protected set; } /// diff --git a/sources/core/Stride.Core/Settings/AppSettings.cs b/sources/core/Stride.Core/Settings/AppSettings.cs index 1ab62c21b6..629ea87b45 100644 --- a/sources/core/Stride.Core/Settings/AppSettings.cs +++ b/sources/core/Stride.Core/Settings/AppSettings.cs @@ -10,11 +10,13 @@ namespace Stride.Core.Settings [DataContract("AppSettings")] public sealed class AppSettings : IEnumerable { + private FastCollection settings = new(); + /// /// Application specific settings. /// [DataMember] - private FastCollection Settings { get; set; } + public IReadOnlyCollection Settings { get => settings; } /// /// Default constructor, used for deserialization. @@ -25,7 +27,7 @@ public sealed class AppSettings : IEnumerable /// Creates a new instance with a settings collection. /// /// Settings collection. - public AppSettings(IEnumerable settings) => Settings = new FastCollection(settings); + public AppSettings(IEnumerable settings) => this.settings = new FastCollection(settings); /// /// Finds a settings object of the specified type in the settings collection. @@ -47,10 +49,10 @@ public sealed class AppSettings : IEnumerable /// Inline Enumerator used by foreach. /// /// Enumerator of the underlying settings collection. - public FastCollection.Enumerator GetEnumerator() => Settings.GetEnumerator(); + public FastCollection.Enumerator GetEnumerator() => settings.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)Settings).GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)settings).GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)Settings).GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)settings).GetEnumerator(); } } diff --git a/sources/engine/Stride.Engine/Engine/AnimationComponent.cs b/sources/engine/Stride.Engine/Engine/AnimationComponent.cs index e64d235f0e..7549b21f27 100644 --- a/sources/engine/Stride.Engine/Engine/AnimationComponent.cs +++ b/sources/engine/Stride.Engine/Engine/AnimationComponent.cs @@ -26,7 +26,6 @@ namespace Stride.Engine [ComponentCategory("Animation")] public sealed class AnimationComponent : EntityComponent { - private readonly Dictionary animations; private readonly TrackingCollection playingAnimations; [DataMemberIgnore] @@ -34,7 +33,7 @@ public sealed class AnimationComponent : EntityComponent public AnimationComponent() { - animations = new Dictionary(); + Animations = new Dictionary(); playingAnimations = new TrackingCollection(); playingAnimations.CollectionChanged += PlayingAnimations_CollectionChanged; } @@ -67,10 +66,8 @@ private void PlayingAnimations_CollectionChanged(object sender, TrackingCollecti /// Gets the animations associated to the component. /// /// The list of the animation associated to the entity. - public Dictionary Animations - { - get { return animations; } - } + [DataMember] + public Dictionary Animations { get; private set; } /// /// Plays right away the animation with the specified name, instantly removing all other blended animations. diff --git a/sources/engine/Stride.Navigation/NavigationMesh.cs b/sources/engine/Stride.Navigation/NavigationMesh.cs index cc24c61830..86a31d009b 100644 --- a/sources/engine/Stride.Navigation/NavigationMesh.cs +++ b/sources/engine/Stride.Navigation/NavigationMesh.cs @@ -31,6 +31,7 @@ public class NavigationMesh /// /// The layers of this navigation mesh, there will be one layer for each enabled group that a navigation mesh is selected to build for /// + [DataMember] public IReadOnlyDictionary Layers => LayersInternal; internal class NavigationMeshSerializer : DataSerializer diff --git a/sources/engine/Stride.Rendering/Rendering/Materials/ComputeColors/ComputeColorParameter.cs b/sources/engine/Stride.Rendering/Rendering/Materials/ComputeColors/ComputeColorParameter.cs index cac17e8d7e..c6ed6c3698 100644 --- a/sources/engine/Stride.Rendering/Rendering/Materials/ComputeColors/ComputeColorParameter.cs +++ b/sources/engine/Stride.Rendering/Rendering/Materials/ComputeColors/ComputeColorParameter.cs @@ -26,6 +26,7 @@ public ComputeColorParameterTexture() Texture = new ComputeTextureColor(); } + [DataMember] public ComputeTextureColor Texture { get; private set; } } diff --git a/sources/engine/Stride.Rendering/Rendering/Mesh.cs b/sources/engine/Stride.Rendering/Rendering/Mesh.cs index 1d885078a5..1de8a823af 100644 --- a/sources/engine/Stride.Rendering/Rendering/Mesh.cs +++ b/sources/engine/Stride.Rendering/Rendering/Mesh.cs @@ -45,8 +45,8 @@ public Mesh(Mesh mesh) /// parameters public Mesh(MeshDraw meshDraw, ParameterCollection parameters) { - if (meshDraw == null) throw new ArgumentNullException("meshDraw"); - if (parameters == null) throw new ArgumentNullException("parameters"); + if (meshDraw == null) throw new ArgumentNullException(nameof(meshDraw)); + if (parameters == null) throw new ArgumentNullException(nameof(parameters)); Draw = meshDraw; Parameters = parameters; } @@ -54,8 +54,8 @@ public Mesh(MeshDraw meshDraw, ParameterCollection parameters) public MeshDraw Draw { get; set; } public int MaterialIndex { get; set; } - - public ParameterCollection Parameters { get; private set; } + + public ParameterCollection Parameters { get; } /// /// Index of the transformation node in . diff --git a/sources/engine/Stride.Shaders.Parser/Mixins/MixinVirtualTable.cs b/sources/engine/Stride.Shaders.Parser/Mixins/MixinVirtualTable.cs index edea9f6aed..5ba44579d7 100644 --- a/sources/engine/Stride.Shaders.Parser/Mixins/MixinVirtualTable.cs +++ b/sources/engine/Stride.Shaders.Parser/Mixins/MixinVirtualTable.cs @@ -2,7 +2,7 @@ // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. using System.Collections.Generic; using System.Linq; - +using Stride.Core; using Stride.Core.Shaders.Ast.Stride; using Stride.Shaders.Parser.Utility; using Stride.Core.Shaders.Ast; @@ -18,21 +18,25 @@ internal class MixinVirtualTable : ShaderVirtualTable /// /// List of all declared methods /// + [DataMember] public HashSet Methods { get; private set; } /// /// List of all declared Variables /// + [DataMember] public HashSet Variables { get; private set; } /// /// List of all the structure definitions /// + [DataMember] public List StructureTypes { get; private set; } // list instead of hashset because order can be important /// /// List of all the Typedefs /// + [DataMember] public List Typedefs { get; private set; } // list instead of hashset because order can be important #endregion diff --git a/sources/tools/Stride.Core.ProjectTemplating/ProjectTemplate.cs b/sources/tools/Stride.Core.ProjectTemplating/ProjectTemplate.cs index 430b5de27a..64e2463e85 100644 --- a/sources/tools/Stride.Core.ProjectTemplating/ProjectTemplate.cs +++ b/sources/tools/Stride.Core.ProjectTemplating/ProjectTemplate.cs @@ -36,6 +36,7 @@ public ProjectTemplate() /// Gets or sets the template file path. /// /// The template path. + [DataMember] public string FilePath { get; private set; } /// @@ -43,6 +44,7 @@ public ProjectTemplate() /// generating content files) /// /// true if this instance is a dynamic template; otherwise, false. + [DataMember] public bool IsDynamicTemplate { get; private set; } /// From dd8cbb9f926132f6a72a7966285fe627df937f78 Mon Sep 17 00:00:00 2001 From: Eideren Date: Wed, 4 Oct 2023 18:01:24 +0200 Subject: [PATCH 07/11] Change some of the accessor to conform with binary/runtime serializer --- .../Stride.Core.AssemblyProcessor.Packed.dll | 4 +- ...ide.Core.AssemblyProcessor.Packed.dll.hash | 2 +- .../Stride.Core.AssemblyProcessor.Packed.pdb | 3 + .../net6.0/Stride.Core.AssemblyProcessor.dll | 4 +- .../net6.0/Stride.Core.AssemblyProcessor.pdb | 4 +- .../Stride.Core.AssemblyProcessor.Packed.dll | 4 +- ...ide.Core.AssemblyProcessor.Packed.dll.hash | 2 +- .../Stride.Core.AssemblyProcessor.Packed.pdb | 4 +- .../Stride.Core.AssemblyProcessor.dll | 4 +- .../Stride.Core.AssemblyProcessor.pdb | 4 +- .../TestSerializing.TestMyAssetObject.cs | 4 +- ...ializing_TestMyAssetObject_Reference.sdobj | 2 +- sources/assets/Stride.Core.Assets/Bundle.cs | 15 +---- .../Selectors/TagSelector.cs | 11 +--- .../Stride.Core.Assets/SolutionPlatform.cs | 20 ++----- .../ComplexSerializerRegistry.cs | 25 ++++---- .../Settings/SettingsFile.cs | 3 +- .../MemberDescriptors/FieldDescriptor.cs | 2 +- .../Serialization/SerializationTests2.cs | 14 ++--- sources/core/Stride.Core/PropertyKey.cs | 4 +- .../TestMemberRequiredComponentChecks.cs | 10 ++-- .../Engine/AnimationComponent.cs | 51 +++++++--------- .../ComputeColors/ComputeColorParameter.cs | 8 +-- .../Rendering/SkeletonUpdater.cs | 43 ++++++------- .../Analysis/StrideParsingInfo.cs | 60 ++++--------------- .../Mixins/MixinVirtualTable.cs | 25 ++------ .../Mixins/ReferencesPool.cs | 19 +++--- sources/engine/Stride/Effects/ParameterKey.cs | 6 +- .../ProjectTemplate.cs | 22 ++----- 29 files changed, 139 insertions(+), 240 deletions(-) create mode 100644 deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.pdb diff --git a/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.dll b/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.dll index 38bc03d9f9..02d9981c0f 100644 --- a/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.dll +++ b/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:52f819550e98d126a685c556595cb25a66bfc7cd97352fa5d127b4a759b52fdb -size 724992 +oid sha256:f5307f2607fe9e761088e06baccdcb5ece8739b25418a6b19421004d872c343d +size 713728 diff --git a/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.dll.hash b/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.dll.hash index 5533fa4ba9..f4a8390aaa 100644 --- a/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.dll.hash +++ b/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.dll.hash @@ -1 +1 @@ -52F819550E98D126A685C556595CB25A66BFC7CD97352FA5D127B4A759B52FDB \ No newline at end of file +F5307F2607FE9E761088E06BACCDCB5ECE8739B25418A6B19421004D872C343D \ No newline at end of file diff --git a/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.pdb b/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.pdb new file mode 100644 index 0000000000..64fbd87e8f --- /dev/null +++ b/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.Packed.pdb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68184c5e9ef77e2275e9e8e5f44fb61228b1f7bc8bae9adf461f18d7a10f734a +size 304640 diff --git a/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.dll b/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.dll index 3037adc46a..6d1592834c 100644 --- a/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.dll +++ b/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f0b8df74ce667e960698b4dbc8d7a61b2cda58c897befa42cf8943e1577b0e4d -size 170496 +oid sha256:9f49d4387554f62bc004132b83981db7361dca126d1785470d33aa6a7def835a +size 159744 diff --git a/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.pdb b/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.pdb index 51f595e506..1d231ddcbc 100644 --- a/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.pdb +++ b/deps/AssemblyProcessor/net6.0/Stride.Core.AssemblyProcessor.pdb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:312b5beecf5fbed6e51e9cf3202586035bf14fa0d4d5017c095ce0a0a5a09960 -size 89456 +oid sha256:f01d69f07a88527792dafe98e67f2129b477a5af868972bf4d7726d74d44590c +size 441856 diff --git a/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.dll b/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.dll index de7cd2f13c..4fdf03c1db 100644 --- a/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.dll +++ b/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e17ab0cb8bc5f55ca985c21612e1da0af77ec6ea6cdd6faf9f76252b0217d226 -size 720896 +oid sha256:f47741092523ec3bf4c9c1b87bec8e1faecc919e1f8319ce64a696f876e186cb +size 710144 diff --git a/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.dll.hash b/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.dll.hash index 2b5cb8d208..570a817d79 100644 --- a/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.dll.hash +++ b/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.dll.hash @@ -1 +1 @@ -E17AB0CB8BC5F55CA985C21612E1DA0AF77EC6EA6CDD6FAF9F76252B0217D226 \ No newline at end of file +F47741092523EC3BF4C9C1B87BEC8E1FAECC919E1F8319CE64A696F876E186CB \ No newline at end of file diff --git a/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.pdb b/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.pdb index 9c95aedc33..8937565118 100644 --- a/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.pdb +++ b/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.Packed.pdb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:813198b4a220539954fb7e19f109ba8f8bcbfbcdbad5139d93b02d74f0a99162 -size 302592 +oid sha256:d717d03c4691b4773958d1aa2cbe91d467d6f6765ba081044ed059f8bcda1e5e +size 304640 diff --git a/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.dll b/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.dll index 334a387986..7e1fdce484 100644 --- a/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.dll +++ b/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:65f2e1d02ba26e7a7817d94821bdc07a382afe77c9f6a3350a036f46efffb84e -size 169472 +oid sha256:94be07b9174da333cc863cff8ba50ff484280b28dee0b657b9a9dc0877355860 +size 158720 diff --git a/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.pdb b/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.pdb index 3536f2a1ea..25f862638f 100644 --- a/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.pdb +++ b/deps/AssemblyProcessor/netstandard2.0/Stride.Core.AssemblyProcessor.pdb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6e5c0460d7f76555500ab34a5f2c2301d1233de50f6b70dc82c907dc0c8a0e70 -size 87032 +oid sha256:6aebc1244c93dd5afee900815020971fbaa96ac7ef17b82325adc7303e4271f6 +size 441856 diff --git a/sources/assets/Stride.Core.Assets.Tests/TestSerializing.TestMyAssetObject.cs b/sources/assets/Stride.Core.Assets.Tests/TestSerializing.TestMyAssetObject.cs index bda26eb62c..b240a502c4 100644 --- a/sources/assets/Stride.Core.Assets.Tests/TestSerializing.TestMyAssetObject.cs +++ b/sources/assets/Stride.Core.Assets.Tests/TestSerializing.TestMyAssetObject.cs @@ -28,7 +28,7 @@ public MyAsset() // TODO: Re-enable non-pure collections here once we support them for serialization! //MapItems2 = new MyDictionary(); MapItems3 = new MyDictionaryPure(); - CustomObjectWithProtectedSet = new CustomObject { Name = "customObject" }; + CustomObjectWithInternalSet = new CustomObject { Name = "customObject" }; } [DataMember(0)] @@ -66,7 +66,7 @@ public MyAsset() public MyDictionaryPure MapItems3 { get; set; } [DataMember] - public CustomObject CustomObjectWithProtectedSet { get; protected set; } + public CustomObject CustomObjectWithInternalSet { get; internal set; } } [DataContract("CustomObject")] diff --git a/sources/assets/Stride.Core.Assets.Tests/data/TestSerializing/TestSerializing_TestMyAssetObject_Reference.sdobj b/sources/assets/Stride.Core.Assets.Tests/data/TestSerializing/TestSerializing_TestMyAssetObject_Reference.sdobj index 3f61d7e27c..704551dd3a 100644 --- a/sources/assets/Stride.Core.Assets.Tests/data/TestSerializing/TestSerializing_TestMyAssetObject_Reference.sdobj +++ b/sources/assets/Stride.Core.Assets.Tests/data/TestSerializing/TestSerializing_TestMyAssetObject_Reference.sdobj @@ -27,5 +27,5 @@ MapItems3: 11000000110000001100000011000000~key2: 2 12000000120000001200000012000000~key3: 3 13000000130000001300000013000000~key4: 3 -CustomObjectWithProtectedSet: +CustomObjectWithInternalSet: Name: customObject diff --git a/sources/assets/Stride.Core.Assets/Bundle.cs b/sources/assets/Stride.Core.Assets/Bundle.cs index 8d589b4f42..b457902de7 100644 --- a/sources/assets/Stride.Core.Assets/Bundle.cs +++ b/sources/assets/Stride.Core.Assets/Bundle.cs @@ -14,15 +14,6 @@ namespace Stride.Core.Assets [DebuggerDisplay("Bundle [{Name}] Selectors[{Selectors.Count}] Dependencies[{Dependencies.Count}]")] public sealed class Bundle { - /// - /// Initializes a new instance of the class. - /// - public Bundle() - { - Selectors = new List(); - Dependencies = new List(); - } - /// /// Gets or sets the name of this bundle. /// @@ -33,15 +24,13 @@ public Bundle() /// Gets the selectors used by this bundle. /// /// The selectors. - [DataMember] - public List Selectors { get; private set; } + public List Selectors { get; } = new List(); /// /// Gets the bundle dependencies. /// /// The dependencies. - [DataMember] - public List Dependencies { get; private set; } + public List Dependencies { get; } = new List(); /// /// Gets the output group (used in conjonction with to control where file will be put). diff --git a/sources/assets/Stride.Core.Assets/Selectors/TagSelector.cs b/sources/assets/Stride.Core.Assets/Selectors/TagSelector.cs index 71abe4a41a..385d963389 100644 --- a/sources/assets/Stride.Core.Assets/Selectors/TagSelector.cs +++ b/sources/assets/Stride.Core.Assets/Selectors/TagSelector.cs @@ -13,20 +13,11 @@ namespace Stride.Core.Assets.Selectors [DataContract("TagSelector")] public class TagSelector : AssetSelector { - /// - /// Initializes a new instance of the class. - /// - public TagSelector() - { - Tags = new TagCollection(); - } - /// /// Gets the tags that will be used to select an asset. /// /// The tags. - [DataMember] - public TagCollection Tags { get; private set; } + public TagCollection Tags { get; } = new TagCollection(); public override IEnumerable Select(PackageSession packageSession, IContentIndexMap contentIndexMap) { diff --git a/sources/assets/Stride.Core.Assets/SolutionPlatform.cs b/sources/assets/Stride.Core.Assets/SolutionPlatform.cs index 06a58baa55..9ad38b6612 100644 --- a/sources/assets/Stride.Core.Assets/SolutionPlatform.cs +++ b/sources/assets/Stride.Core.Assets/SolutionPlatform.cs @@ -16,21 +16,12 @@ namespace Stride.Core.Assets [DataContract("SolutionPlatform")] public class SolutionPlatform : SolutionPlatformPart { - /// - /// Initializes a new instance of the class. - /// - public SolutionPlatform() - { - PlatformsPart = new SolutionPlatformPartCollection(); - DefineConstants = new List(); - } - /// /// Gets the alternative names that will appear in the .sln file equivalent to this platform. /// /// The alternative names. [DataMember(20)] - public SolutionPlatformPartCollection PlatformsPart { get; private set; } + public SolutionPlatformPartCollection PlatformsPart { get; } = new SolutionPlatformPartCollection(); /// /// Gets or sets the type of the platform. @@ -58,7 +49,7 @@ public SolutionPlatform() /// /// The define constants. [DataMember(40)] - public List DefineConstants { get; private set; } + public List DefineConstants { get; } = new List(); /// /// Gets or sets a value indicating whether this is available on this machine. @@ -276,15 +267,13 @@ public SolutionConfiguration(string name) { if (name == null) throw new ArgumentNullException("name"); Name = name; - Properties = new List(); } /// /// Gets or sets the configuration name (e.g. Debug, Release) /// /// The name. - [DataMember] - public string Name { get; private set; } + public string Name { get; init; } /// /// Gets or sets a value indicating whether this instance is a debug configuration. @@ -296,7 +285,6 @@ public SolutionConfiguration(string name) /// Gets the additional msbuild properties for a specific configuration (Debug or Release) /// /// The msbuild configuration properties. - [DataMember] - public List Properties { get; private set; } + public List Properties { get; } = new List(); } } diff --git a/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs b/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs index 75aa8f1051..834a54b83e 100644 --- a/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs +++ b/sources/core/Stride.Core.AssemblyProcessor/ComplexSerializerRegistry.cs @@ -281,24 +281,29 @@ public static IEnumerable GetSerializableItems(TypeDefinition var fields = new List(); var properties = new List(); - var fieldEnum = type.Fields.Where(x => (x.IsPublic || (x.IsAssembly && x.CustomAttributes.Any(a => a.AttributeType.FullName == "Stride.Core.DataMemberAttribute"))) && !x.IsStatic && !ignoredMembers.Contains(x)); + foreach (var field in type.Fields) + { + if (field.IsStatic) + continue; - // If there is a explicit or sequential layout, sort by offset - if (type.IsSequentialLayout || type.IsExplicitLayout) - fieldEnum = fieldEnum.OrderBy(x => x.Offset); + if (ignoredMembers.Contains(field)) + continue; - foreach (var field in fieldEnum) - { - fields.Add(field); + if (field.IsPublic || (field.IsAssembly && field.CustomAttributes.Any(a => a.AttributeType.FullName == "Stride.Core.DataMemberAttribute"))) + fields.Add(field); } + // If there is a explicit or sequential layout, sort by offset + if (type.IsSequentialLayout || type.IsExplicitLayout) + fields.Sort((x,y) => x.Offset.CompareTo(y.Offset)); + foreach (var property in type.Properties) { - // Need a non-static public get method - if (property.GetMethod.IsStatic) + if (IsAccessibleThroughAccessModifiers(property) == false) continue; - if (IsAccessibleThroughAccessModifiers(property) == false) + // Need a non-static public get method + if (property.GetMethod.IsStatic) continue; // If it's a struct (!IsValueType), we need a set method as well diff --git a/sources/core/Stride.Core.Design/Settings/SettingsFile.cs b/sources/core/Stride.Core.Design/Settings/SettingsFile.cs index b6899944b9..803d245dae 100644 --- a/sources/core/Stride.Core.Design/Settings/SettingsFile.cs +++ b/sources/core/Stride.Core.Design/Settings/SettingsFile.cs @@ -22,8 +22,7 @@ public SettingsFile(SettingsProfile profile) /// /// Gets the settings profile to serialize. /// - [DataMember] [DataMemberCustomSerializer] - public SettingsProfile Settings { get; private set; } + public SettingsProfile Settings { get; init; } } } diff --git a/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs b/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs index 1d313b900e..90a85e6917 100644 --- a/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs @@ -30,7 +30,7 @@ public FieldDescriptor(ITypeDescriptor typeDescriptor, FieldInfo fieldInfo, Stri public override bool IsPublic => FieldInfo.IsPublic; - public override bool HasSet => !FieldInfo.IsInitOnly; + public override bool HasSet => true; public override object Get(object thisObject) { diff --git a/sources/core/Stride.Core.Yaml.Tests/Serialization/SerializationTests2.cs b/sources/core/Stride.Core.Yaml.Tests/Serialization/SerializationTests2.cs index cddc1e1351..1bf345acd7 100644 --- a/sources/core/Stride.Core.Yaml.Tests/Serialization/SerializationTests2.cs +++ b/sources/core/Stride.Core.Yaml.Tests/Serialization/SerializationTests2.cs @@ -221,8 +221,7 @@ public MyObject() public int[] Array { get; set; } - [DataMember] - public int[] ArrayContent { get; private set; } + public int[] ArrayContent { get; } } [Fact] @@ -577,8 +576,7 @@ public MyCustomClassWithSpecialMembers() /// value of the list stored in this instance instead of /// creating a new List<T>l instance. /// - [DataMember] - public List StringListByContent { get; private set; } + public List StringListByContent { get; } /// /// Gets or sets the basic map. @@ -597,8 +595,7 @@ public MyCustomClassWithSpecialMembers() /// Idem as for but for dictionary. /// /// The content of the string mapby. - [DataMember] - public Dictionary StringMapbyContent { get; private set; } + public Dictionary StringMapbyContent { get; } /// /// For this property, the deserializer is using the actual @@ -606,8 +603,7 @@ public MyCustomClassWithSpecialMembers() /// creating a new List<T>l instance. /// /// The content of the list by. - [DataMember] - public List ListByContent { get; private set; } + public List ListByContent { get; } } /// @@ -1557,7 +1553,7 @@ public ClassWithImplicitMemberType() } [DataMember] - public object Test { get; protected set; } + public object Test { get; init; } } public class ClassWithNonImplicitMemberType diff --git a/sources/core/Stride.Core/PropertyKey.cs b/sources/core/Stride.Core/PropertyKey.cs index 5dafab6d5d..b5fa7a0620 100644 --- a/sources/core/Stride.Core/PropertyKey.cs +++ b/sources/core/Stride.Core/PropertyKey.cs @@ -19,6 +19,7 @@ namespace Stride.Core [DebuggerDisplay("{" + nameof(Name) + "}")] public abstract class PropertyKey : IComparable { + protected string name; private DefaultValueMetadata defaultValueMetadata; /// @@ -42,8 +43,7 @@ protected PropertyKey([NotNull] string name, Type propertyType, Type ownerType, /// /// Gets the name of this key. /// - [DataMember] - public string Name { get; protected set; } + public string Name { get => name; init => name = value; } /// /// Gets the default value metadata. diff --git a/sources/engine/Stride.Assets.Tests/TestMemberRequiredComponentChecks.cs b/sources/engine/Stride.Assets.Tests/TestMemberRequiredComponentChecks.cs index 8fa3b50c05..e92986078f 100644 --- a/sources/engine/Stride.Assets.Tests/TestMemberRequiredComponentChecks.cs +++ b/sources/engine/Stride.Assets.Tests/TestMemberRequiredComponentChecks.cs @@ -31,13 +31,13 @@ public class MemberRequiredComponent : VirtualBaseComponent [DataMember][MemberRequired] internal object InternalField; [MemberRequired] public object PublicProp { get; set; } [MemberRequired] - [DataMember] public object PrivateProp { get; private set; } + [DataMember] public object InitProp { get; init; } [MemberRequired] [DataMember] internal object InternalProp { get; set; } public override object VirtualProp { get; set; } = new object(); - public MemberRequiredComponent(object privateData, object internalData) + public MemberRequiredComponent(object initData, object internalData) { - PrivateProp = privateData; + InitProp = initData; InternalProp = internalData; } } @@ -89,7 +89,7 @@ void EntityIsMissingRequiredMember_PublicProp() } [Fact] - void EntityIsMissingRequiredMember_PrivateProp() + void EntityIsMissingRequiredMember_InitProp() { var memberRequiredComponent = new MemberRequiredComponent(null, new object()) { @@ -97,7 +97,7 @@ void EntityIsMissingRequiredMember_PrivateProp() PublicProp = new object(), PublicField = new object(), }; - var memberName = nameof(MemberRequiredComponent.PrivateProp); + var memberName = nameof(MemberRequiredComponent.InitProp); TestSingle(memberRequiredComponent, memberName); } diff --git a/sources/engine/Stride.Engine/Engine/AnimationComponent.cs b/sources/engine/Stride.Engine/Engine/AnimationComponent.cs index 7549b21f27..ba34f75b5b 100644 --- a/sources/engine/Stride.Engine/Engine/AnimationComponent.cs +++ b/sources/engine/Stride.Engine/Engine/AnimationComponent.cs @@ -26,16 +26,27 @@ namespace Stride.Engine [ComponentCategory("Animation")] public sealed class AnimationComponent : EntityComponent { - private readonly TrackingCollection playingAnimations; + /// + /// Gets the animations associated to the component. + /// + /// The list of the animation associated to the entity. + public Dictionary Animations { get; } = new(); + /// + /// Gets list of active animations. Use this to customize startup animations. + /// [DataMemberIgnore] - public AnimationBlender Blender { get; internal set; } = new AnimationBlender(); + public TrackingCollection PlayingAnimations { get; } = new(); + + [DataMemberIgnore] + public AnimationBlender Blender { get; internal set; } = new(); + + [DataMemberIgnore] + public IBlendTreeBuilder BlendTreeBuilder { get; set; } public AnimationComponent() { - Animations = new Dictionary(); - playingAnimations = new TrackingCollection(); - playingAnimations.CollectionChanged += PlayingAnimations_CollectionChanged; + PlayingAnimations.CollectionChanged += PlayingAnimations_CollectionChanged; } private void PlayingAnimations_CollectionChanged(object sender, TrackingCollectionChangedEventArgs e) @@ -62,22 +73,15 @@ private void PlayingAnimations_CollectionChanged(object sender, TrackingCollecti } } - /// - /// Gets the animations associated to the component. - /// - /// The list of the animation associated to the entity. - [DataMember] - public Dictionary Animations { get; private set; } - /// /// Plays right away the animation with the specified name, instantly removing all other blended animations. /// /// The animation name. public PlayingAnimation Play(string name) { - playingAnimations.Clear(); + PlayingAnimations.Clear(); var playingAnimation = new PlayingAnimation(name, Animations[name]) { CurrentTime = TimeSpan.Zero, Weight = 1.0f }; - playingAnimations.Add(playingAnimation); + PlayingAnimations.Add(playingAnimation); return playingAnimation; } @@ -88,7 +92,7 @@ public PlayingAnimation Play(string name) /// true if the animation is playing, false otherwise public bool IsPlaying(string name) { - foreach (var playingAnimation in playingAnimations) + foreach (var playingAnimation in PlayingAnimations) { if (playingAnimation.Name.Equals(name)) return true; @@ -119,7 +123,7 @@ public bool IsPlaying(string name) RepeatMode = repeatMode ?? clip.RepeatMode, }; - playingAnimations.Add(playingAnimation); + PlayingAnimations.Add(playingAnimation); return playingAnimation; } @@ -136,7 +140,7 @@ public PlayingAnimation Crossfade(string name, TimeSpan fadeTimeSpan) throw new ArgumentException(nameof(name)); // Fade all animations - foreach (var otherPlayingAnimation in playingAnimations) + foreach (var otherPlayingAnimation in PlayingAnimations) { otherPlayingAnimation.WeightTarget = 0.0f; otherPlayingAnimation.CrossfadeRemainingTime = fadeTimeSpan; @@ -159,7 +163,7 @@ public PlayingAnimation Blend(string name, float desiredWeight, TimeSpan fadeTim throw new ArgumentException("name"); var playingAnimation = new PlayingAnimation(name, Animations[name]) { CurrentTime = TimeSpan.Zero, Weight = 0.0f }; - playingAnimations.Add(playingAnimation); + PlayingAnimations.Add(playingAnimation); if (fadeTimeSpan > TimeSpan.Zero) { @@ -179,15 +183,6 @@ public PlayingAnimation NewPlayingAnimation(string name) return new PlayingAnimation(name, Animations[name]); } - /// - /// Gets list of active animations. Use this to customize startup animations. - /// - [DataMemberIgnore] - public TrackingCollection PlayingAnimations => playingAnimations; - - [DataMemberIgnore] - public IBlendTreeBuilder BlendTreeBuilder { get; set; } - /// /// Returns an awaitable object that will be completed when the animation is removed from the PlayingAnimation list. /// This happens when: @@ -198,7 +193,7 @@ public PlayingAnimation NewPlayingAnimation(string name) /// public Task Ended(PlayingAnimation animation) { - if (!playingAnimations.Contains(animation)) + if (!PlayingAnimations.Contains(animation)) throw new InvalidOperationException("Trying to await end of an animation which is not playing"); if (animation.EndedTCS == null) diff --git a/sources/engine/Stride.Rendering/Rendering/Materials/ComputeColors/ComputeColorParameter.cs b/sources/engine/Stride.Rendering/Rendering/Materials/ComputeColors/ComputeColorParameter.cs index c6ed6c3698..e0fddcd3a0 100644 --- a/sources/engine/Stride.Rendering/Rendering/Materials/ComputeColors/ComputeColorParameter.cs +++ b/sources/engine/Stride.Rendering/Rendering/Materials/ComputeColors/ComputeColorParameter.cs @@ -21,13 +21,7 @@ public abstract class ComputeColorParameter : IComputeColorParameter [DataContract("ComputeColorParameterTexture")] public class ComputeColorParameterTexture : ComputeColorParameter { - public ComputeColorParameterTexture() - { - Texture = new ComputeTextureColor(); - } - - [DataMember] - public ComputeTextureColor Texture { get; private set; } + public ComputeTextureColor Texture { get; } = new ComputeTextureColor(); } [DataContract] diff --git a/sources/engine/Stride.Rendering/Rendering/SkeletonUpdater.cs b/sources/engine/Stride.Rendering/Rendering/SkeletonUpdater.cs index 38a20dc7f2..c9245649d2 100644 --- a/sources/engine/Stride.Rendering/Rendering/SkeletonUpdater.cs +++ b/sources/engine/Stride.Rendering/Rendering/SkeletonUpdater.cs @@ -16,13 +16,16 @@ namespace Stride.Rendering [DataContract] // Here for update engine; TODO: better separation and different attribute? public class SkeletonUpdater { + private ModelNodeDefinition[] nodes; + private ModelNodeTransformation[] nodeTransformations; + private int matrixCounter; [DataMember] - public ModelNodeDefinition[] Nodes { get; private set; } + public ModelNodeDefinition[] Nodes => nodes; [DataMember] - public ModelNodeTransformation[] NodeTransformations { get; private set; } + public ModelNodeTransformation[] NodeTransformations => nodeTransformations; private static ModelNodeDefinition[] GetDefaultNodeDefinitions() { @@ -42,26 +45,26 @@ public void Initialize(Skeleton skeleton) { var newNodes = skeleton?.Nodes; - if (this.Nodes == newNodes && this.Nodes != null) + if (this.nodes == newNodes && this.nodes != null) { return; } - this.Nodes = newNodes ?? GetDefaultNodeDefinitions(); + this.nodes = newNodes ?? GetDefaultNodeDefinitions(); - if (NodeTransformations == null || NodeTransformations.Length < this.Nodes.Length) - NodeTransformations = new ModelNodeTransformation[this.Nodes.Length]; + if (nodeTransformations == null || nodeTransformations.Length < this.nodes.Length) + nodeTransformations = new ModelNodeTransformation[this.nodes.Length]; - for (int index = 0; index < Nodes.Length; index++) + for (int index = 0; index < nodes.Length; index++) { - NodeTransformations[index].ParentIndex = Nodes[index].ParentIndex; - NodeTransformations[index].Transform = Nodes[index].Transform; - NodeTransformations[index].Flags = Nodes[index].Flags; - NodeTransformations[index].RenderingEnabledRecursive = true; - UpdateLocalMatrix(ref NodeTransformations[index]); + nodeTransformations[index].ParentIndex = nodes[index].ParentIndex; + nodeTransformations[index].Transform = nodes[index].Transform; + nodeTransformations[index].Flags = nodes[index].Flags; + nodeTransformations[index].RenderingEnabledRecursive = true; + UpdateLocalMatrix(ref nodeTransformations[index]); } - NodeTransformations[0].Flags &= ~ModelNodeFlags.EnableTransform; + nodeTransformations[0].Flags &= ~ModelNodeFlags.EnableTransform; } /// @@ -69,10 +72,10 @@ public void Initialize(Skeleton skeleton) /// public void ResetInitialValues() { - var nodesLocal = Nodes; + var nodesLocal = nodes; for (int index = 0; index < nodesLocal.Length; index++) { - NodeTransformations[index].Transform = nodesLocal[index].Transform; + nodeTransformations[index].Transform = nodesLocal[index].Transform; } } @@ -82,22 +85,22 @@ public void ResetInitialValues() public void UpdateMatrices() { // Compute transformations - var nodesLength = Nodes.Length; + var nodesLength = nodes.Length; for (int index = 0; index < nodesLength; index++) { - UpdateNode(ref NodeTransformations[index]); + UpdateNode(ref nodeTransformations[index]); } matrixCounter++; } public void GetWorldMatrix(int index, out Matrix matrix) { - matrix = NodeTransformations[index].WorldMatrix; + matrix = nodeTransformations[index].WorldMatrix; } public void GetLocalMatrix(int index, out Matrix matrix) { - matrix = NodeTransformations[index].LocalMatrix; + matrix = nodeTransformations[index].LocalMatrix; } private void UpdateNode(ref ModelNodeTransformation node) @@ -108,7 +111,7 @@ private void UpdateNode(ref ModelNodeTransformation node) UpdateLocalMatrix(ref node); } - var nodeTransformationsLocal = this.NodeTransformations; + var nodeTransformationsLocal = this.nodeTransformations; var parentIndex = node.ParentIndex; diff --git a/sources/engine/Stride.Shaders.Parser/Analysis/StrideParsingInfo.cs b/sources/engine/Stride.Shaders.Parser/Analysis/StrideParsingInfo.cs index b9f1764509..6078960d56 100644 --- a/sources/engine/Stride.Shaders.Parser/Analysis/StrideParsingInfo.cs +++ b/sources/engine/Stride.Shaders.Parser/Analysis/StrideParsingInfo.cs @@ -17,81 +17,68 @@ internal class StrideParsingInfo /// /// Variables that referenced the stage class ( "= stage" ) /// - [DataMember] - public HashSet StageInitializedVariables { get; private set; } + public HashSet StageInitializedVariables { get; } = new(); /// /// All typedefs /// - [DataMember] - public List Typedefs { get; private set; } + public List Typedefs { get; } = new(); /// /// All structure definitions /// - [DataMember] - public List StructureDefinitions { get; private set; } + public List StructureDefinitions { get; } = new(); /// /// All the base method calls (base.xxx) /// - [DataMember] - public HashSet BaseMethodCalls { get; private set; } + public HashSet BaseMethodCalls { get; } = new(); /// /// All the method calls that are not base /// - [DataMember] - public HashSet ThisMethodCalls { get; private set; } + public HashSet ThisMethodCalls { get; } = new(); /// /// All the method calls to stage methods /// - [DataMember] - public HashSet StageMethodCalls { get; private set; } + public HashSet StageMethodCalls { get; } = new(); /// /// All foreach statements /// - [DataMember] - public HashSet ForEachStatements { get; private set; } + public HashSet ForEachStatements { get; } = new(); /// /// References to members of the current shader /// - [DataMember] - public ReferencesPool ClassReferences { get; private set; } + public ReferencesPool ClassReferences { get; } = new(); /// /// Static references to class members /// - [DataMember] - public ReferencesPool StaticReferences { get; private set; } + public ReferencesPool StaticReferences { get; } = new(); /// /// References to extern members /// - [DataMember] - public ReferencesPool ExternReferences { get; private set; } + public ReferencesPool ExternReferences { get; } = new(); /// /// References to stage initialized variables and methods /// - [DataMember] - public ReferencesPool StageInitReferences { get; private set; } + public ReferencesPool StageInitReferences { get; } = new(); /// /// Gets navigable nodes (local variables, base class...etc.) /// /// The navigable nodes. - [DataMember] - public List NavigableNodes { get; private set; } + public List NavigableNodes { get; } = new(); /// /// List of the static classes /// - [DataMember] - public HashSet StaticClasses { get; private set; } + public HashSet StaticClasses { get; } = new(); #endregion @@ -103,26 +90,5 @@ internal class StrideParsingInfo public ParsingResult ErrorsWarnings = null; #endregion - - #region Constructor - - public StrideParsingInfo() - { - StageInitializedVariables = new HashSet(); - Typedefs = new List(); - StructureDefinitions = new List(); - BaseMethodCalls = new HashSet(); - ThisMethodCalls = new HashSet(); - StageMethodCalls = new HashSet(); - ForEachStatements = new HashSet(); - ClassReferences = new ReferencesPool(); - StaticReferences = new ReferencesPool(); - ExternReferences = new ReferencesPool(); - StageInitReferences = new ReferencesPool(); - StaticClasses = new HashSet(); - NavigableNodes = new List(); - } - - #endregion } } diff --git a/sources/engine/Stride.Shaders.Parser/Mixins/MixinVirtualTable.cs b/sources/engine/Stride.Shaders.Parser/Mixins/MixinVirtualTable.cs index 5ba44579d7..7f3400e708 100644 --- a/sources/engine/Stride.Shaders.Parser/Mixins/MixinVirtualTable.cs +++ b/sources/engine/Stride.Shaders.Parser/Mixins/MixinVirtualTable.cs @@ -2,7 +2,6 @@ // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. using System.Collections.Generic; using System.Linq; -using Stride.Core; using Stride.Core.Shaders.Ast.Stride; using Stride.Shaders.Parser.Utility; using Stride.Core.Shaders.Ast; @@ -18,38 +17,22 @@ internal class MixinVirtualTable : ShaderVirtualTable /// /// List of all declared methods /// - [DataMember] - public HashSet Methods { get; private set; } + public HashSet Methods { get; } = new(); /// /// List of all declared Variables /// - [DataMember] - public HashSet Variables { get; private set; } + public HashSet Variables { get; } = new(); /// /// List of all the structure definitions /// - [DataMember] - public List StructureTypes { get; private set; } // list instead of hashset because order can be important + public List StructureTypes { get; } = new(); // list instead of hashset because order can be important /// /// List of all the Typedefs /// - [DataMember] - public List Typedefs { get; private set; } // list instead of hashset because order can be important - - #endregion - - #region Constructor - - public MixinVirtualTable() - { - Methods = new HashSet(); - Variables = new HashSet(); - StructureTypes = new List(); - Typedefs = new List(); - } + public List Typedefs { get; } = new(); // list instead of hashset because order can be important #endregion diff --git a/sources/engine/Stride.Shaders.Parser/Mixins/ReferencesPool.cs b/sources/engine/Stride.Shaders.Parser/Mixins/ReferencesPool.cs index 8684452c88..d5136d6d55 100644 --- a/sources/engine/Stride.Shaders.Parser/Mixins/ReferencesPool.cs +++ b/sources/engine/Stride.Shaders.Parser/Mixins/ReferencesPool.cs @@ -15,23 +15,20 @@ namespace Stride.Shaders.Parser.Mixins [DataContract] internal class ReferencesPool { + private Dictionary> variablesReferences = new(); + private Dictionary> methodsReferences = new(); + /// /// List of all the variable references /// [DataMember] - public Dictionary> VariablesReferences { get; private set; } + public Dictionary> VariablesReferences => variablesReferences; /// /// List of all the variable references /// [DataMember] - public Dictionary> MethodsReferences { get; private set; } - - public ReferencesPool() - { - VariablesReferences = new Dictionary>(); - MethodsReferences = new Dictionary>(); - } + public Dictionary> MethodsReferences => methodsReferences; /// /// Merge the argument references into this one @@ -58,12 +55,12 @@ public void Merge(ReferencesPool pool) } /// - /// Regen the keys bacause they could have been modified + /// Regen the keys because they could have been modified /// public void RegenKeys() { - VariablesReferences = VariablesReferences.ToDictionary(variable => variable.Key, variable => variable.Value); - MethodsReferences = MethodsReferences.ToDictionary(method => method.Key, variable => variable.Value); + variablesReferences = VariablesReferences.ToDictionary(variable => variable.Key, variable => variable.Value); + methodsReferences = MethodsReferences.ToDictionary(method => method.Key, variable => variable.Value); } /// diff --git a/sources/engine/Stride/Effects/ParameterKey.cs b/sources/engine/Stride/Effects/ParameterKey.cs index 1c7ac609f0..1852f13aef 100644 --- a/sources/engine/Stride/Effects/ParameterKey.cs +++ b/sources/engine/Stride/Effects/ParameterKey.cs @@ -45,11 +45,11 @@ protected ParameterKey(Type propertyType, string name, int length, params Proper public abstract int Size { get; } - internal void SetName(string name) + internal void SetName(string nameParam) { - if (name == null) throw new ArgumentNullException("name"); + if (nameParam == null) throw new ArgumentNullException(nameof(nameParam)); - Name = string.Intern(name); + name = string.Intern(nameParam); UpdateName(); } diff --git a/sources/tools/Stride.Core.ProjectTemplating/ProjectTemplate.cs b/sources/tools/Stride.Core.ProjectTemplating/ProjectTemplate.cs index 64e2463e85..f78ace272a 100644 --- a/sources/tools/Stride.Core.ProjectTemplating/ProjectTemplate.cs +++ b/sources/tools/Stride.Core.ProjectTemplating/ProjectTemplate.cs @@ -23,41 +23,31 @@ namespace Stride.Core.ProjectTemplating [NonIdentifiableCollectionItems] public class ProjectTemplate { - /// - /// Initializes a new instance of the class. - /// - public ProjectTemplate() - { - Files = new List(); - Assemblies = new List(); - } - + private string filePath; /// /// Gets or sets the template file path. /// /// The template path. - [DataMember] - public string FilePath { get; private set; } + public string FilePath { get => filePath; init => filePath = value; } /// /// Gets a value indicating whether this template description is dynamic (itself requiring T4 parsing before /// generating content files) /// /// true if this instance is a dynamic template; otherwise, false. - [DataMember] - public bool IsDynamicTemplate { get; private set; } + public bool IsDynamicTemplate { get; init; } /// /// Gets or sets the files part of the template. /// /// The files. - public List Files { get; } + public List Files { get; } = new(); /// /// Gets or sets the assemblies. /// /// The assemblies. - public List Assemblies { get; } + public List Assemblies { get; } = new(); /// /// Generates this project template to the specified output directory. @@ -313,7 +303,7 @@ public static ProjectTemplate Load(string filePath) } } - template.FilePath = fullFilePath; + template.filePath = fullFilePath; return template; } } From 63185eb3d7a6d07b1be22b36e03d241870e38d7a Mon Sep 17 00:00:00 2001 From: Eideren Date: Wed, 4 Oct 2023 18:37:15 +0200 Subject: [PATCH 08/11] Ignore setter for readonly fields --- .../Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs b/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs index 90a85e6917..1d313b900e 100644 --- a/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/MemberDescriptors/FieldDescriptor.cs @@ -30,7 +30,7 @@ public FieldDescriptor(ITypeDescriptor typeDescriptor, FieldInfo fieldInfo, Stri public override bool IsPublic => FieldInfo.IsPublic; - public override bool HasSet => true; + public override bool HasSet => !FieldInfo.IsInitOnly; public override object Get(object thisObject) { From 3f025a1b89443432a964f4ecb7cc57e373dad652 Mon Sep 17 00:00:00 2001 From: Eideren Date: Thu, 5 Oct 2023 08:57:29 +0200 Subject: [PATCH 09/11] Fix the last few access modifiers --- sources/assets/Stride.Core.Assets/AssetReference.cs | 4 ++-- sources/assets/Stride.Core.Assets/BasePart.cs | 4 ++-- sources/core/Stride.Core/Settings/AppSettings.cs | 13 +++++-------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/sources/assets/Stride.Core.Assets/AssetReference.cs b/sources/assets/Stride.Core.Assets/AssetReference.cs index d9dba6e6aa..ab08fac29c 100644 --- a/sources/assets/Stride.Core.Assets/AssetReference.cs +++ b/sources/assets/Stride.Core.Assets/AssetReference.cs @@ -33,14 +33,14 @@ public AssetReference(AssetId id, UFile location) /// /// The unique identifier of the reference asset.. [DataMember(10)] - public AssetId Id { get; } + public AssetId Id { get; init; } /// /// Gets or sets the location of the asset. /// /// The location. [DataMember(20)] - public string Location { get; } + public string Location { get; init; } public bool Equals(AssetReference other) { diff --git a/sources/assets/Stride.Core.Assets/BasePart.cs b/sources/assets/Stride.Core.Assets/BasePart.cs index b88c3dd51e..3996eadf25 100644 --- a/sources/assets/Stride.Core.Assets/BasePart.cs +++ b/sources/assets/Stride.Core.Assets/BasePart.cs @@ -72,10 +72,10 @@ public BasePart([NotNull] AssetReference basePartAsset, Guid basePartId, Guid in public AssetReference BasePartAsset { get; set; } [DataMember(20)] - public Guid BasePartId { get; } + public Guid BasePartId { get; init; } [DataMember(30)] - public Guid InstanceId { get; } + public Guid InstanceId { get; init; } [CanBeNull] public IIdentifiable ResolvePart(PackageSession session) diff --git a/sources/core/Stride.Core/Settings/AppSettings.cs b/sources/core/Stride.Core/Settings/AppSettings.cs index 629ea87b45..9a03bbded8 100644 --- a/sources/core/Stride.Core/Settings/AppSettings.cs +++ b/sources/core/Stride.Core/Settings/AppSettings.cs @@ -10,13 +10,10 @@ namespace Stride.Core.Settings [DataContract("AppSettings")] public sealed class AppSettings : IEnumerable { - private FastCollection settings = new(); - /// /// Application specific settings. /// - [DataMember] - public IReadOnlyCollection Settings { get => settings; } + public FastCollection Settings { get; } = new(); /// /// Default constructor, used for deserialization. @@ -27,7 +24,7 @@ public sealed class AppSettings : IEnumerable /// Creates a new instance with a settings collection. /// /// Settings collection. - public AppSettings(IEnumerable settings) => this.settings = new FastCollection(settings); + public AppSettings(IEnumerable settings) => Settings = new FastCollection(settings); /// /// Finds a settings object of the specified type in the settings collection. @@ -49,10 +46,10 @@ public sealed class AppSettings : IEnumerable /// Inline Enumerator used by foreach. /// /// Enumerator of the underlying settings collection. - public FastCollection.Enumerator GetEnumerator() => settings.GetEnumerator(); + public FastCollection.Enumerator GetEnumerator() => Settings.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)settings).GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)Settings).GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)settings).GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)Settings).GetEnumerator(); } } From 794cf275abc8c030a4ba769aae0c765a4ac48de5 Mon Sep 17 00:00:00 2001 From: Eideren Date: Fri, 6 Oct 2023 07:58:25 +0200 Subject: [PATCH 10/11] Address review --- sources/assets/Stride.Core.Assets/SolutionPlatform.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/assets/Stride.Core.Assets/SolutionPlatform.cs b/sources/assets/Stride.Core.Assets/SolutionPlatform.cs index 9ad38b6612..87d4504444 100644 --- a/sources/assets/Stride.Core.Assets/SolutionPlatform.cs +++ b/sources/assets/Stride.Core.Assets/SolutionPlatform.cs @@ -265,7 +265,7 @@ public class SolutionConfiguration /// public SolutionConfiguration(string name) { - if (name == null) throw new ArgumentNullException("name"); + if (name == null) throw new ArgumentNullException(nameof(name)); Name = name; } From c3641366146383a48de5b143a0dd32e204dae5fe Mon Sep 17 00:00:00 2001 From: Eideren Date: Tue, 10 Oct 2023 12:42:12 +0200 Subject: [PATCH 11/11] Fix outdated comment --- .../TypeDescriptors/ObjectDescriptor.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs index b6dce14074..6ff5dc7c9b 100644 --- a/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs +++ b/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs @@ -438,12 +438,7 @@ protected bool IsMemberToVisit(MemberInfo memberInfo) } } - - // Member is not displayed if there is a YamlIgnore attribute on it - if (AttributeRegistry.GetAttribute(memberInfo) != null) - return false; - - return true; + return AttributeRegistry.GetAttribute(memberInfo) is null; } } }