internal ScalarTypeModel( TypeModelContainer container, Type type, int size) : base(type, container) { this.size = size; }
/// <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); }
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); }
public FloatTypeModel(TypeModelContainer container) : base(container, typeof(float), sizeof(float)) { }
internal StringTypeModel(TypeModelContainer container) : base(typeof(string), container) { }
internal RuntimeTypeModel(Type clrType, TypeModelContainer typeModelContainer) { this.ClrType = clrType; this.typeModelContainer = typeModelContainer; }
internal EnumTypeModel(Type type, TypeModelContainer typeModelContainer) : base(type, typeModelContainer) { }
internal EnumTypeModel(Type type, TypeModelContainer typeModelContainer) : base(type, typeModelContainer) { this.underlyingTypeModel = null !; }
internal NullableEnumTypeModel(Type type, TypeModelContainer typeModelProvider) : base(type, typeModelProvider) { }
internal IndexedVectorTypeModel(Type vectorType, TypeModelContainer provider) : base(vectorType, provider) { }
public SByteTypeModel(TypeModelContainer container) : base(container, typeof(sbyte), sizeof(sbyte)) { }
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); }
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); }
public DoubleTypeModel(TypeModelContainer container) : base(container, typeof(double), sizeof(double)) { }
public BoolTypeModel(TypeModelContainer container) : base(container, typeof(bool), sizeof(bool)) { }
internal DictionaryVectorTypeModel(Type vectorType, TypeModelContainer provider) : base(vectorType, provider) { }
internal TableTypeModel(Type clrType, TypeModelContainer typeModelProvider) : base(clrType, typeModelProvider) { this.DefaultConstructor = null !; }
internal UnionTypeModel(Type unionType, TypeModelContainer provider) : base(unionType, provider) { }
internal StructTypeModel(Type clrType, TypeModelContainer container) : base(clrType, container) { }
internal TableTypeModel(Type clrType, TypeModelContainer typeModelProvider) : base(clrType, typeModelProvider) { }
/// <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)); }
/// <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]."); }
internal MemoryVectorTypeModel(Type vectorType, TypeModelContainer provider) : base(vectorType, provider) { this.itemTypeModel = null !; }
internal IndexedVectorTypeModel(Type vectorType, TypeModelContainer provider) : base(vectorType, provider) { this.keyTypeModel = null !; this.valueTypeModel = null !; this.keyMemberModel = null !; }
internal MemoryVectorTypeModel(Type vectorType, TypeModelContainer provider) : base(vectorType, provider) { }
public UIntTypeModel(TypeModelContainer container) : base(container, typeof(uint), sizeof(uint)) { }
public bool TryResolveFbsAlias(TypeModelContainer container, string alias, [NotNullWhen(true)] out ITypeModel?typeModel) { typeModel = null; return(false); }
public ULongTypeModel(TypeModelContainer container) : base(container, typeof(ulong), sizeof(ulong)) { }