Changed attribute builder to derive from correct class, also added method to pass base class parameters using string refs. Regenerated the files
This commit is contained in:
@@ -13,7 +13,7 @@ using System;
|
|||||||
namespace BlendFile {
|
namespace BlendFile {
|
||||||
|
|
||||||
[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Struct)]
|
[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Struct)]
|
||||||
public class DNAClassAttribute : System.Attribute {
|
public class DNAClassAttribute : BlendFile.DNAAttribute {
|
||||||
private int _OriginalIndex;
|
private int _OriginalIndex;
|
||||||
public virtual int OriginalIndex {
|
public virtual int OriginalIndex {
|
||||||
get {
|
get {
|
||||||
@@ -41,7 +41,8 @@ namespace BlendFile {
|
|||||||
this._Size = value;
|
this._Size = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public DNAClassAttribute(int OriginalIndex, string OriginalName, int Size) {
|
public DNAClassAttribute(int OriginalIndex, string OriginalName, int Size) :
|
||||||
|
base(OriginalIndex, OriginalName) {
|
||||||
this._OriginalIndex = OriginalIndex;
|
this._OriginalIndex = OriginalIndex;
|
||||||
this._OriginalName = OriginalName;
|
this._OriginalName = OriginalName;
|
||||||
this._Size = Size;
|
this._Size = Size;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System;
|
|||||||
namespace BlendFile {
|
namespace BlendFile {
|
||||||
|
|
||||||
[AttributeUsageAttribute(AttributeTargets.Field)]
|
[AttributeUsageAttribute(AttributeTargets.Field)]
|
||||||
public class DNAFieldAttribute : System.Attribute {
|
public class DNAFieldAttribute : BlendFile.DNAAttribute {
|
||||||
private int _Size;
|
private int _Size;
|
||||||
public virtual int Size {
|
public virtual int Size {
|
||||||
get {
|
get {
|
||||||
@@ -77,7 +77,8 @@ namespace BlendFile {
|
|||||||
this._MemoryOffset = value;
|
this._MemoryOffset = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public DNAFieldAttribute(int Size, string OriginalType, int OriginalIndex, string OriginalName, string UnderlyingType, bool IsPointer, int MemoryOffset) {
|
public DNAFieldAttribute(int Size, string OriginalType, int OriginalIndex, string OriginalName, string UnderlyingType, bool IsPointer, int MemoryOffset) :
|
||||||
|
base(OriginalIndex, OriginalName) {
|
||||||
this._Size = Size;
|
this._Size = Size;
|
||||||
this._OriginalType = OriginalType;
|
this._OriginalType = OriginalType;
|
||||||
this._OriginalIndex = OriginalIndex;
|
this._OriginalIndex = OriginalIndex;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System;
|
|||||||
namespace BlendFile {
|
namespace BlendFile {
|
||||||
|
|
||||||
[AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field)]
|
[AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field)]
|
||||||
public class DNAListAttribute : System.Attribute {
|
public class DNAListAttribute : BlendFile.DNAAttribute {
|
||||||
private int _Size;
|
private int _Size;
|
||||||
public virtual int Size {
|
public virtual int Size {
|
||||||
get {
|
get {
|
||||||
@@ -86,7 +86,8 @@ namespace BlendFile {
|
|||||||
this._MemoryOffset = value;
|
this._MemoryOffset = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public DNAListAttribute(int Size, string OriginalType, string OriginalName, int OriginalIndex, string UnderlyingType, string CountFieldName, int CountFieldIndex, int MemoryOffset) {
|
public DNAListAttribute(int Size, string OriginalType, string OriginalName, int OriginalIndex, string UnderlyingType, string CountFieldName, int CountFieldIndex, int MemoryOffset) :
|
||||||
|
base(OriginalIndex, OriginalName) {
|
||||||
this._Size = Size;
|
this._Size = Size;
|
||||||
this._OriginalType = OriginalType;
|
this._OriginalType = OriginalType;
|
||||||
this._OriginalName = OriginalName;
|
this._OriginalName = OriginalName;
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArgumentOutOfRangeException_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F72e5853ed6f2c1967eff9d6f0cf6ba12744c8978c516cbc5e74d992944ab_003FArgumentOutOfRangeException_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArgumentOutOfRangeException_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F72e5853ed6f2c1967eff9d6f0cf6ba12744c8978c516cbc5e74d992944ab_003FArgumentOutOfRangeException_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArray_002ECoreCLR_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fee3c9d264411441f56a12bac52a58ad25b495ef52e59b4a86f8478158f7d_003FArray_002ECoreCLR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArray_002ECoreCLR_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fee3c9d264411441f56a12bac52a58ad25b495ef52e59b4a86f8478158f7d_003FArray_002ECoreCLR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArray_002ECoreCLR_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F51b332f64116ca1bf68931ca13adc3cd38b6dd2da04af6aef46bd08d218e58b5_003FArray_002ECoreCLR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArray_002ECoreCLR_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F51b332f64116ca1bf68931ca13adc3cd38b6dd2da04af6aef46bd08d218e58b5_003FArray_002ECoreCLR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACodeConstructor_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fbe433ced0c0d9b3aa171b7fbcd7df89ef13497cab9fb55640c7d49c891f_003FCodeConstructor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACodeDomProvider_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F4333c036d67eaa64623a27221cb821b663bc08410ac68797b1c10376d8379fe_003FCodeDomProvider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACodeDomProvider_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F4333c036d67eaa64623a27221cb821b663bc08410ac68797b1c10376d8379fe_003FCodeDomProvider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACodeExpression_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F3127868066451f65e848b2ed6b9f84913de3cfb771a33c5f1bf5f1ba22c12e_003FCodeExpression_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACollectionBase_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fa6227be3686afd1e7a497da15c9371b4dc2c39126852fbc263d51ab206739b_003FCollectionBase_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACollectionBase_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fa6227be3686afd1e7a497da15c9371b4dc2c39126852fbc263d51ab206739b_003FCollectionBase_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACSharpCodeGenerator_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F4aa9136c27fa69d6c91e9d8679c1a1d4b7aabee06e20d4405ee3d91ee05048f0_003FCSharpCodeGenerator_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACSharpCodeGenerator_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F4aa9136c27fa69d6c91e9d8679c1a1d4b7aabee06e20d4405ee3d91ee05048f0_003FCSharpCodeGenerator_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACSharpCodeGenerator_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F4aa9136c27fa69d6c91e9d8679c1a1d4b7aabee06e20d4405ee3d91ee05048f0_003FCSharpCodeGenerator_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACSharpCodeGenerator_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F4aa9136c27fa69d6c91e9d8679c1a1d4b7aabee06e20d4405ee3d91ee05048f0_003FCSharpCodeGenerator_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.CodeDom;
|
using System.CodeDom;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
|
||||||
namespace CodeGenerator {
|
namespace CodeGenerator {
|
||||||
// ReSharper disable always BitwiseOperatorOnEnumWithoutFlags
|
// ReSharper disable always BitwiseOperatorOnEnumWithoutFlags
|
||||||
public class AttributeBuilder {
|
public class AttributeBuilder {
|
||||||
|
|
||||||
private CodeTypeDeclaration _attrDecl = new();
|
private CodeTypeDeclaration _attrDecl;
|
||||||
|
|
||||||
private List<(Type, string)> _fields = new();
|
private List<(Type, string)> _fields = new();
|
||||||
|
|
||||||
@@ -28,9 +30,11 @@ namespace CodeGenerator {
|
|||||||
/// Creates a new instance of the <see cref="AttributeBuilder"/> class.
|
/// Creates a new instance of the <see cref="AttributeBuilder"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AttributeBuilder() {
|
public AttributeBuilder() {
|
||||||
_attrDecl.IsClass = true;
|
_attrDecl = new() {
|
||||||
_attrDecl.Attributes = MemberAttributes.Public;
|
IsClass = true,
|
||||||
_attrDecl.BaseTypes.Add(typeof(Attribute));
|
Attributes = MemberAttributes.Public,
|
||||||
|
BaseTypes = { typeof(Attribute) }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -47,7 +51,11 @@ namespace CodeGenerator {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>clears the internal metadata for fields and properties, also reinstantiates the <see cref="CodeTypeDeclaration"/> internal instance</remarks>
|
/// <remarks>clears the internal metadata for fields and properties, also reinstantiates the <see cref="CodeTypeDeclaration"/> internal instance</remarks>
|
||||||
public AttributeBuilder New() {
|
public AttributeBuilder New() {
|
||||||
_attrDecl = new CodeTypeDeclaration();
|
_attrDecl = new() {
|
||||||
|
IsClass = true,
|
||||||
|
Attributes = MemberAttributes.Public,
|
||||||
|
BaseTypes = { typeof(Attribute) }
|
||||||
|
};
|
||||||
_fields.Clear();
|
_fields.Clear();
|
||||||
_properties.Clear();
|
_properties.Clear();
|
||||||
return this;
|
return this;
|
||||||
@@ -57,10 +65,7 @@ namespace CodeGenerator {
|
|||||||
/// Sets the base type of the attribute.
|
/// Sets the base type of the attribute.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="baseType">Fully qualified name from which this is going to be derived</param>
|
/// <param name="baseType">Fully qualified name from which this is going to be derived</param>
|
||||||
public AttributeBuilder DeriveFromClass(string baseType) {
|
public AttributeBuilder DeriveFromClass(string baseType = "System.Attribute") {
|
||||||
if (_attrDecl.BaseTypes.Count == 0)
|
|
||||||
_attrDecl.BaseTypes.Add(typeof(Attribute));
|
|
||||||
else
|
|
||||||
_attrDecl.BaseTypes[0] = new(baseType);
|
_attrDecl.BaseTypes[0] = new(baseType);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -200,6 +205,21 @@ namespace CodeGenerator {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: tyhis should use something more robust and less error prone than just strings
|
||||||
|
/// <summary>
|
||||||
|
/// Adds parameters to be passed to the base class
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parameters">Array of strings which reference the params</param>
|
||||||
|
/// <exception cref="InvalidOperationException"> thrown when no constructor is defined yet.</exception>
|
||||||
|
public AttributeBuilder AddBaseConstructorParams(string[] parameters) {
|
||||||
|
var ctor = _attrDecl.Members.OfType<CodeConstructor>().FirstOrDefault();
|
||||||
|
if (ctor == null) throw new InvalidOperationException("There is no constructor defined yet.");
|
||||||
|
foreach (var param in parameters) {
|
||||||
|
ctor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(param));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Builds the <see cref="CodeTypeDeclaration"/> instance.
|
/// Builds the <see cref="CodeTypeDeclaration"/> instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -300,10 +300,10 @@ namespace CodeGenerator {
|
|||||||
private static CodeTypeDeclaration[] GenerateTypeDeclarations() {
|
private static CodeTypeDeclaration[] GenerateTypeDeclarations() {
|
||||||
var attributeBuilder = new AttributeBuilder();
|
var attributeBuilder = new AttributeBuilder();
|
||||||
|
|
||||||
var typeDeclarations = new CodeTypeDeclaration[] {
|
var typeDeclarations = new[] {
|
||||||
attributeBuilder.New().SetName("DNAAttribute")
|
attributeBuilder.New().SetName("DNAAttribute")
|
||||||
.SetAttributeUsage(new (new CodeSnippetExpression("AttributeTargets.All")))
|
.SetAttributeUsage(new (new CodeSnippetExpression("AttributeTargets.All")))
|
||||||
.DeriveFromClass("System.Attribute")
|
.DeriveFromClass()
|
||||||
.AddAutoProperty(typeof(int), "OriginalIndex")
|
.AddAutoProperty(typeof(int), "OriginalIndex")
|
||||||
.AddAutoProperty(typeof(string), "OriginalName")
|
.AddAutoProperty(typeof(string), "OriginalName")
|
||||||
.AddPropertiesConstructor()
|
.AddPropertiesConstructor()
|
||||||
@@ -319,6 +319,7 @@ namespace CodeGenerator {
|
|||||||
.AddAutoProperty(typeof(bool), "IsPointer")
|
.AddAutoProperty(typeof(bool), "IsPointer")
|
||||||
.AddAutoProperty(typeof(int), "MemoryOffset")
|
.AddAutoProperty(typeof(int), "MemoryOffset")
|
||||||
.AddPropertiesConstructor()
|
.AddPropertiesConstructor()
|
||||||
|
.AddBaseConstructorParams(["OriginalIndex", "OriginalName"])
|
||||||
.Build(),
|
.Build(),
|
||||||
attributeBuilder.New().SetName("DNAClassAttribute")
|
attributeBuilder.New().SetName("DNAClassAttribute")
|
||||||
.SetAttributeUsage(new (new CodeSnippetExpression("AttributeTargets.Class | AttributeTargets.Struct")))
|
.SetAttributeUsage(new (new CodeSnippetExpression("AttributeTargets.Class | AttributeTargets.Struct")))
|
||||||
@@ -327,6 +328,7 @@ namespace CodeGenerator {
|
|||||||
.AddAutoProperty(typeof(string), "OriginalName")
|
.AddAutoProperty(typeof(string), "OriginalName")
|
||||||
.AddAutoProperty(typeof(int), "Size")
|
.AddAutoProperty(typeof(int), "Size")
|
||||||
.AddPropertiesConstructor()
|
.AddPropertiesConstructor()
|
||||||
|
.AddBaseConstructorParams(["OriginalIndex", "OriginalName"])
|
||||||
.Build(),
|
.Build(),
|
||||||
attributeBuilder.New().SetName("DNAListAttribute")
|
attributeBuilder.New().SetName("DNAListAttribute")
|
||||||
.SetAttributeUsage(new (new CodeSnippetExpression("AttributeTargets.Property | AttributeTargets.Field")))
|
.SetAttributeUsage(new (new CodeSnippetExpression("AttributeTargets.Property | AttributeTargets.Field")))
|
||||||
@@ -340,6 +342,7 @@ namespace CodeGenerator {
|
|||||||
.AddAutoProperty(typeof(int), "CountFieldIndex")
|
.AddAutoProperty(typeof(int), "CountFieldIndex")
|
||||||
.AddAutoProperty(typeof(int), "MemoryOffset")
|
.AddAutoProperty(typeof(int), "MemoryOffset")
|
||||||
.AddPropertiesConstructor()
|
.AddPropertiesConstructor()
|
||||||
|
.AddBaseConstructorParams(["OriginalIndex", "OriginalName"])
|
||||||
.Build()
|
.Build()
|
||||||
};
|
};
|
||||||
return typeDeclarations;
|
return typeDeclarations;
|
||||||
|
|||||||
Reference in New Issue
Block a user