Browse Source

Added Uri property type to the list of generated types.

This was intended to make the API more consistent, but unexpected microsoft "easter eggs" prevented it's use.
vpenades 2 months ago
parent
commit
d8ac60f635

+ 2 - 0
src/SharpGLTF.CodeGen.Core/CodeGen/EmitCSharp.cs

@@ -193,6 +193,8 @@ namespace SharpGLTF.CodeGen
 
 
                 case StringType strType: return strType.PersistentName;
                 case StringType strType: return strType.PersistentName;
 
 
+                case UriType uriType: return uriType.PersistentName;
+
                 case BlittableType blitType:
                 case BlittableType blitType:
                     {
                     {
                         var tname = blitType.DataType.Name;
                         var tname = blitType.DataType.Name;

+ 19 - 0
src/SharpGLTF.CodeGen.Core/MainSchemaProcessor.cs

@@ -101,6 +101,25 @@ namespace SharpGLTF
             var propertyPathEnum = ctx.FindEnum("rotation-scale-translation-weights");            
             var propertyPathEnum = ctx.FindEnum("rotation-scale-translation-weights");            
             propertyPathEnum?.SetValue("pointer", 0);
             propertyPathEnum?.SetValue("pointer", 0);
 
 
+            // we might be able to enable this in the future when we're past Net10,
+            // which is the 1st framework to remove the 65535 limit on Uri sizes.
+            // https://learn.microsoft.com/en-us/dotnet/core/compatibility/networking/10.0/uri-length-limits-removed
+            if (false) 
+            {
+                var imageClass = ctx.FindClass("Image");
+                if (imageClass != null)
+                {
+                    imageClass.GetField("uri").SetDataType(typeof(Uri), true);
+                }
+
+                var bufferClass = ctx.FindClass("Buffer");
+                if (bufferClass != null)
+                {
+                    bufferClass.GetField("uri").SetDataType(typeof(Uri), true);
+                }
+            }
+
+
             var meshClass = ctx.FindClass("Mesh");
             var meshClass = ctx.FindClass("Mesh");
             if (meshClass != null)
             if (meshClass != null)
             {
             {

+ 20 - 0
src/SharpGLTF.CodeGen.Core/SchemaReflection/SchemaTypes.cs

@@ -95,6 +95,25 @@ namespace SharpGLTF.SchemaReflection
         #endregion
         #endregion
     }
     }
 
 
+    /// <summary>
+    /// Represents a <see cref="Uri"/> type.
+    /// </summary>
+    [System.Diagnostics.DebuggerDisplay("StringType {PersistentName}")]
+    public sealed class UriType : SchemaType
+    {
+        #region constructor
+
+        internal UriType(Context ctx) : base(ctx) { }
+
+        #endregion
+
+        #region properties
+
+        public override string PersistentName => typeof(Uri).Name;
+
+        #endregion
+    }
+
     /// <summary>
     /// <summary>
     /// Represents an undefined <see cref="Object"/> type.
     /// Represents an undefined <see cref="Object"/> type.
     /// </summary>
     /// </summary>
@@ -324,6 +343,7 @@ namespace SharpGLTF.SchemaReflection
         public FieldInfo SetDataType(Type type, bool isNullable)
         public FieldInfo SetDataType(Type type, bool isNullable)
         {
         {
             if (type == typeof(string)) { _FieldType = DeclaringClass.Owner.UseString(); return this; }
             if (type == typeof(string)) { _FieldType = DeclaringClass.Owner.UseString(); return this; }
+            if (type == typeof(Uri)) { _FieldType = DeclaringClass.Owner.UseUri(); return this; }
 
 
             if (type.IsEnum)
             if (type.IsEnum)
             {
             {

+ 2 - 0
src/SharpGLTF.CodeGen.Core/SchemaReflection/SchemaTypesContext.cs

@@ -53,6 +53,8 @@ namespace SharpGLTF.SchemaReflection
 
 
             public StringType UseString() { return (StringType)_UseOrCreate( new StringType(this) ); }
             public StringType UseString() { return (StringType)_UseOrCreate( new StringType(this) ); }
 
 
+            public UriType UseUri() { return (UriType)_UseOrCreate(new UriType(this)); }
+
             public EnumType FindEnum(string persistentName) { return Enumerations.FirstOrDefault(item => item.PersistentName == persistentName); }
             public EnumType FindEnum(string persistentName) { return Enumerations.FirstOrDefault(item => item.PersistentName == persistentName); }
 
 
             public ArrayType UseArray(SchemaType elementType) { return (ArrayType)_UseOrCreate( new ArrayType(this, elementType) ); }
             public ArrayType UseArray(SchemaType elementType) { return (ArrayType)_UseOrCreate( new ArrayType(this, elementType) ); }