// Create a new Code type for a particular heading public static DataTypeCode Create(string name, DataHeading heading, TypeFlags flags, ConvertDelegate converter = null, DefaultDelegate defaulter = null) { var dt = new DataTypeCode { Name = name, Heading = heading, Flags = flags, }; dt.NativeType = TypeMaker.CreateType(dt); return(dt); }
// Get type from dictionary, or create and add public static DataTypeTuple Get(DataHeading heading) { if (_headings.ContainsKey(heading)) { return(_headings[heading]); } var dt = DataTypeTuple.Create("tuple", heading, TypeFlags.Variable | TypeFlags.Generated | TypeFlags.HasHeading); dt.Ordinal = _headings.Count + 1; dt.NativeType = TypeMaker.CreateType(dt); _headings[heading] = dt; return(dt); }
// Use this type maker to create a structured type, recursively public static Type CreateType(DataType datatype) { // For relation wrap tuple type in a generic List<> if (datatype is DataTypeRelation) { var listtype = typeof(List <>); return(listtype.MakeGenericType((datatype as DataTypeRelation).ChildTupleType.NativeType)); } var typemaker = new TypeMaker { _typebuilder = _modulebuilder.DefineType(datatype.GetNiceName, TypeAttributes.Public), }; typemaker.DefineMembers(datatype.Heading.Columns); return(typemaker._typebuilder.CreateType()); }
// Get type from dictionary, or create and add // Every relation needs a row type, so make sure they use the same heading public static DataTypeRelation Get(DataHeading heading) { if (_headings.ContainsKey(heading)) { return(_headings[heading]); } var tupletype = DataTypeTuple.Get(heading); var dt = DataTypeRelation.Create("relation", tupletype.Heading, TypeFlags.Variable | TypeFlags.Generated | TypeFlags.HasHeading); dt.Ordinal = _headings.Count + 1; dt.ChildTupleType = tupletype; dt.NativeType = TypeMaker.CreateType(dt); _headings[heading] = dt; var x = Activator.CreateInstance(dt.NativeType); return(dt); }
// Common code for setting a value public void Set(TypedValue value) { Value = value; #if false // FIX:code if (!(value.DataType is DataTypeCode)) { //if (value.DataType != DataTypes.Code) { Logger.Assert(value.DataType == DataType); // TEMP: following code is just so it gets exercised NativeValue = TypeMaker.ToNativeValue(value); if (NativeValue != null) // TODO: CodeValue { Value = TypeMaker.FromNativeValue(NativeValue, DataType); } TypedValueBuilderTest.Test(value); } #endif }