示例#1
0
        // Create a new User type for a particular heading
        public static DataTypeUser Create(string name, DataHeading heading, TypeFlags flags, ConvertDelegate converter = null, DefaultDelegate defaulter = null)
        {
            var dt = new DataTypeUser {
                Name    = name,
                Heading = heading,
                Flags   = flags,
            };

            dt.NativeType = TypeMaker.CreateType(dt);
            return(dt);
        }
示例#2
0
        static public UserValue Create(TypedValue[] value, DataTypeUser datatype)
        {
            if (datatype.Name == "date")
            {
                return(Builtin.DateValue.Create(value[0] as TimeValue));
            }
            var ret = new UserValue {
                Value = value, _datatype = datatype
            };

            ret._hashcode = ret.CalcHashCode();
            return(ret);
        }
示例#3
0
        // Create and add, return new type (must not exist)
        // Note: heading must have IsTuple=false to preserve order
        public static DataTypeUser Get(string name, DataColumn[] columns)
        {
            var old = Find(name);

            if (old != null && columns.SequenceEqual(old.Heading.Columns))
            {
                return(old);
            }
            Logger.Assert(!_usertypes.ContainsKey(name), name);
            var flags = columns.Any(c => c.DataType.IsOrdered) ? TypeFlags.Ordered : TypeFlags.None;
            var dt    = DataTypeUser.Create(name, DataHeading.Create(columns, false), // preserve column order
                                            flags | TypeFlags.Variable | TypeFlags.Generated | TypeFlags.HasName | TypeFlags.HasHeading);

            _usertypes[name] = dt;
            return(dt);
        }
示例#4
0
 // construct a type from a base name, optional heading and optional user type name
 public static DataType Derive(DataType basetype, DataHeading heading, string username)
 {
     if (basetype == DataTypes.Table)
     {
         return(DataTypeRelation.Get(heading));
     }
     if (basetype == DataTypes.Row)
     {
         return(DataTypeTuple.Get(heading));
     }
     if (basetype == DataTypes.User)
     {
         return(DataTypeUser.Get(username, heading.Columns));
     }
     return(basetype);
 }
示例#5
0
        public UserValue UserSelector(TextValue typename, TypedValue[] valargs)
        {
            var usertype = DataTypeUser.Find(typename.Value);

            return(usertype.CreateValue(valargs));
        }
示例#6
0
 static DateValue()
 {
     // FIX: better to have a lookup for this
     StaticDatatype = DataTypeUser.Get("date", new DataColumn[] { DataColumn.Create("super", DataTypes.Time) });
     DataTypes.TypeDict[typeof(DateValue)] = StaticDatatype;
 }
示例#7
0
 // Add a user type, just so it will get persisted
 public void AddUserType(string name, DataTypeUser datatype, EntryFlags flags)
 {
     GlobalVars.AddEntry(name, datatype, EntryKinds.Type, flags);
 }