Ejemplo n.º 1
0
 internal ScalarTypeModel(
     TypeModelContainer container,
     Type type,
     int size) : base(type, container)
 {
     this.size = size;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a FlatSharp type model container with default support.
        /// </summary>
        public static TypeModelContainer CreateDefault()
        {
            var container = new TypeModelContainer();

            container.RegisterProvider(new ScalarTypeModelProvider());
            container.RegisterProvider(new FlatSharpTypeModelProvider());
            return(container);
        }
Ejemplo n.º 3
0
        public bool TryCreateTypeModel(TypeModelContainer container, Type type, [NotNullWhen(true)] out ITypeModel?typeModel)
        {
            if (type == typeof(TType))
            {
                typeModel = this.model;
                return(true);
            }

            typeModel = null;
            return(false);
        }
        /// <summary>
        /// Tries to resolve an FBS alias into a type model.
        /// </summary>
        public bool TryResolveFbsAlias(TypeModelContainer container, string alias, out ITypeModel typeModel)
        {
            typeModel = null;

            if (alias == "string")
            {
                typeModel = new StringTypeModel();
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Tries to create a type model based on the given type.
        /// </summary>
        public bool TryCreateTypeModel(TypeModelContainer container, Type type, out ITypeModel typeModel)
        {
            if (type == typeof(string))
            {
                typeModel = new StringTypeModel();
                return(true);
            }

            if (type == typeof(SharedString))
            {
                typeModel = new SharedStringTypeModel();
                return(true);
            }

            if (type.IsArray)
            {
                typeModel = new ArrayVectorTypeModel(type, container);
                return(true);
            }

            if (type.IsGenericType)
            {
                var genericDef = type.GetGenericTypeDefinition();
                if (genericDef == typeof(IList <>) || genericDef == typeof(IReadOnlyList <>))
                {
                    typeModel = new ListVectorTypeModel(type, container);
                    return(true);
                }

                if (genericDef == typeof(Memory <>) || genericDef == typeof(ReadOnlyMemory <>))
                {
                    typeModel = new MemoryVectorTypeModel(type, container);
                    return(true);
                }

                if (genericDef == typeof(IIndexedVector <,>))
                {
                    typeModel = new IndexedVectorTypeModel(type, container);
                    return(true);
                }
            }

            if (typeof(IUnion).IsAssignableFrom(type))
            {
                typeModel = new UnionTypeModel(type, container);
                return(true);
            }

            if (type.IsEnum)
            {
                typeModel = new EnumTypeModel(type, container);
                return(true);
            }

            if (Nullable.GetUnderlyingType(type) != null)
            {
                var underlyingType = Nullable.GetUnderlyingType(type);
                if (underlyingType.IsEnum)
                {
                    typeModel = new NullableEnumTypeModel(type, container);
                    return(true);
                }
            }

            var tableAttribute = type.GetCustomAttribute <FlatBufferTableAttribute>();

            if (tableAttribute != null)
            {
                typeModel = new TableTypeModel(type, container);
                return(true);
            }

            var structAttribute = type.GetCustomAttribute <FlatBufferStructAttribute>();

            if (structAttribute != null)
            {
                typeModel = new StructTypeModel(type, container);
                return(true);
            }

            typeModel = null;
            return(false);
        }
Ejemplo n.º 6
0
 public FloatTypeModel(TypeModelContainer container) : base(container, typeof(float), sizeof(float))
 {
 }
Ejemplo n.º 7
0
 internal StringTypeModel(TypeModelContainer container) : base(typeof(string), container)
 {
 }
Ejemplo n.º 8
0
 internal RuntimeTypeModel(Type clrType, TypeModelContainer typeModelContainer)
 {
     this.ClrType            = clrType;
     this.typeModelContainer = typeModelContainer;
 }
Ejemplo n.º 9
0
 internal EnumTypeModel(Type type, TypeModelContainer typeModelContainer) : base(type, typeModelContainer)
 {
 }
Ejemplo n.º 10
0
 internal EnumTypeModel(Type type, TypeModelContainer typeModelContainer) : base(type, typeModelContainer)
 {
     this.underlyingTypeModel = null !;
 }
Ejemplo n.º 11
0
 internal NullableEnumTypeModel(Type type, TypeModelContainer typeModelProvider) : base(type, typeModelProvider)
 {
 }
Ejemplo n.º 12
0
 internal IndexedVectorTypeModel(Type vectorType, TypeModelContainer provider) : base(vectorType, provider)
 {
 }
Ejemplo n.º 13
0
 public SByteTypeModel(TypeModelContainer container) : base(container, typeof(sbyte), sizeof(sbyte))
 {
 }
Ejemplo n.º 14
0
        public bool TryResolveFbsAlias(
            TypeModelContainer container,
            string alias,
            [NotNullWhen(true)] out ITypeModel?typeModel)
        {
            typeModel = null;
            switch (alias)
            {
            case "bool":
                typeModel = new BoolTypeModel(container);
                break;

            case "ubyte":
            case "uint8":
                typeModel = new ByteTypeModel(container);
                break;

            case "byte":
            case "int8":
                typeModel = new SByteTypeModel(container);
                break;

            case "ushort":
            case "uint16":
                typeModel = new UShortTypeModel(container);
                break;

            case "short":
            case "int16":
                typeModel = new ShortTypeModel(container);
                break;

            case "int":
            case "int32":
                typeModel = new IntTypeModel(container);
                break;

            case "uint":
            case "uint32":
                typeModel = new UIntTypeModel(container);
                break;

            case "long":
            case "int64":
                typeModel = new LongTypeModel(container);
                break;

            case "ulong":
            case "uint64":
                typeModel = new ULongTypeModel(container);
                break;

            case "float":
            case "float32":
                typeModel = new FloatTypeModel(container);
                break;

            case "double":
            case "float64":
                typeModel = new DoubleTypeModel(container);
                break;
            }

            return(typeModel is not null);
        }
Ejemplo n.º 15
0
        public bool TryCreateTypeModel(
            TypeModelContainer container,
            Type type,
            [NotNullWhen(true)] out ITypeModel?typeModel)
        {
            typeModel = null;

            if (type == typeof(bool))
            {
                typeModel = new BoolTypeModel(container);
                return(true);
            }


            if (type == typeof(byte))
            {
                typeModel = new ByteTypeModel(container);
                return(true);
            }


            if (type == typeof(sbyte))
            {
                typeModel = new SByteTypeModel(container);
                return(true);
            }


            if (type == typeof(ushort))
            {
                typeModel = new UShortTypeModel(container);
                return(true);
            }


            if (type == typeof(short))
            {
                typeModel = new ShortTypeModel(container);
                return(true);
            }


            if (type == typeof(int))
            {
                typeModel = new IntTypeModel(container);
                return(true);
            }


            if (type == typeof(uint))
            {
                typeModel = new UIntTypeModel(container);
                return(true);
            }


            if (type == typeof(long))
            {
                typeModel = new LongTypeModel(container);
                return(true);
            }


            if (type == typeof(ulong))
            {
                typeModel = new ULongTypeModel(container);
                return(true);
            }


            if (type == typeof(float))
            {
                typeModel = new FloatTypeModel(container);
                return(true);
            }


            if (type == typeof(double))
            {
                typeModel = new DoubleTypeModel(container);
                return(true);
            }


            return(false);
        }
Ejemplo n.º 16
0
 public DoubleTypeModel(TypeModelContainer container) : base(container, typeof(double), sizeof(double))
 {
 }
Ejemplo n.º 17
0
 public BoolTypeModel(TypeModelContainer container) : base(container, typeof(bool), sizeof(bool))
 {
 }
Ejemplo n.º 18
0
 internal DictionaryVectorTypeModel(Type vectorType, TypeModelContainer provider) : base(vectorType, provider)
 {
 }
Ejemplo n.º 19
0
 internal TableTypeModel(Type clrType, TypeModelContainer typeModelProvider) : base(clrType, typeModelProvider)
 {
     this.DefaultConstructor = null !;
 }
Ejemplo n.º 20
0
 internal UnionTypeModel(Type unionType, TypeModelContainer provider) : base(unionType, provider)
 {
 }
Ejemplo n.º 21
0
 internal StructTypeModel(Type clrType, TypeModelContainer container) : base(clrType, container)
 {
 }
Ejemplo n.º 22
0
 internal TableTypeModel(Type clrType, TypeModelContainer typeModelProvider) : base(clrType, typeModelProvider)
 {
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Gets or creates a runtime type model from the given type. This is only used in test cases any more.
 /// </summary>
 internal static ITypeModel CreateFrom(Type type)
 {
     return(TypeModelContainer.CreateDefault().CreateTypeModel(type));
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Tries to create a type model based on the given type.
        /// </summary>
        public bool TryCreateTypeModel(TypeModelContainer container, Type type, [NotNullWhen(true)] out ITypeModel?typeModel)
        {
            if (type == typeof(string))
            {
                typeModel = new StringTypeModel(container);
                return(true);
            }

            if (type == typeof(SharedString))
            {
                typeModel = new SharedStringTypeModel(container);
                return(true);
            }

            if (type.IsArray)
            {
                typeModel = new ArrayVectorTypeModel(type, container);
                return(true);
            }

            if (type.IsGenericType)
            {
                var genericDef = type.GetGenericTypeDefinition();
                if (genericDef == typeof(IList <>) || genericDef == typeof(IReadOnlyList <>))
                {
                    typeModel = new ListVectorTypeModel(type, container);
                    return(true);
                }

                if (genericDef == typeof(Memory <>) || genericDef == typeof(ReadOnlyMemory <>))
                {
                    typeModel = new MemoryVectorTypeModel(type, container);
                    return(true);
                }

                if (genericDef == typeof(IIndexedVector <,>))
                {
                    typeModel = new IndexedVectorTypeModel(type, container);
                    return(true);
                }
            }

            if (typeof(IUnion).IsAssignableFrom(type))
            {
                typeModel = new UnionTypeModel(type, container);
                return(true);
            }

            if (type.IsEnum)
            {
                typeModel = new EnumTypeModel(type, container);
                return(true);
            }

            var underlyingType = Nullable.GetUnderlyingType(type);

            if (underlyingType is not null)
            {
                typeModel = new NullableTypeModel(container, type);
                return(true);
            }

            var tableAttribute  = type.GetCustomAttribute <FlatBufferTableAttribute>();
            var structAttribute = type.GetCustomAttribute <FlatBufferStructAttribute>();

            if (tableAttribute is not null && structAttribute is not null)
            {
                throw new InvalidFlatBufferDefinitionException($"Type '{CSharpHelpers.GetCompilableTypeName(type)}' is declared as both [FlatBufferTable] and [FlatBufferStruct].");
            }
Ejemplo n.º 25
0
 internal MemoryVectorTypeModel(Type vectorType, TypeModelContainer provider) : base(vectorType, provider)
 {
     this.itemTypeModel = null !;
 }
Ejemplo n.º 26
0
 internal IndexedVectorTypeModel(Type vectorType, TypeModelContainer provider) : base(vectorType, provider)
 {
     this.keyTypeModel   = null !;
     this.valueTypeModel = null !;
     this.keyMemberModel = null !;
 }
Ejemplo n.º 27
0
 internal MemoryVectorTypeModel(Type vectorType, TypeModelContainer provider) : base(vectorType, provider)
 {
 }
Ejemplo n.º 28
0
 public UIntTypeModel(TypeModelContainer container) : base(container, typeof(uint), sizeof(uint))
 {
 }
Ejemplo n.º 29
0
 public bool TryResolveFbsAlias(TypeModelContainer container, string alias, [NotNullWhen(true)] out ITypeModel?typeModel)
 {
     typeModel = null;
     return(false);
 }
Ejemplo n.º 30
0
 public ULongTypeModel(TypeModelContainer container) : base(container, typeof(ulong), sizeof(ulong))
 {
 }