/// <summary>Generates a feature.</summary> /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception> /// <param name="type">The type.</param> /// <param name="name">The name.</param> /// <returns>The feature.</returns> public static Property GenerateFeature(Type type, string name) { Property p; if (type == typeof(string)) p = new StringProperty(); else if (type == typeof(DateTime)) p = new DateTimeProperty(); else if (type.GetInterfaces().Contains(typeof(IEnumerable))) throw new InvalidOperationException( string.Format("Property {0} needs to be labeled as an EnumerableFeature", name)); else p = new Property(); p.Discrete = type.BaseType == typeof(Enum) || type == typeof(bool) || type == typeof(string) || type == typeof(char) || type == typeof(DateTime); p.Type = type; p.Name = name; return p; }
public override void Write(JsonWriter writer, object value) { base.Write(writer, value); var p = (DateTimeProperty)value; writer.WriteFirstArrayProperty("Features", DateTimeProperty.GetColumns(p.Features)); }
public override object Read(JsonReader reader) { var p = (DateTimeProperty)base.Read(reader); var features = reader.ReadArrayProperty().Value .Select(o => (string)o) .ToArray(); p.Features = DateTimeProperty.GetFeatures(features); return(p); }
public void DateTime_Property_Save_And_Load() { DateTimeProperty p = new DateTimeProperty(DateTimeFeature.DayOfWeek | DateTimeFeature.Second | DateTimeFeature.Minute); p.Name = "MyProp"; p.Discrete = false; p.Start = 5; Serialize(p); var property = Deserialize<DateTimeProperty>(); Assert.Equal(p, property); }
/// <summary>Adds DateTime property to descriptor with previously chained name.</summary> /// <exception cref="DescriptorException">Thrown when a Descriptor error condition occurs.</exception> /// <param name="features"> /// Which date features to use (can pipe: DateTimeFeature.Year | /// DateTimeFeature.DayOfWeek) /// </param> /// <returns>descriptor with added property.</returns> public Descriptor AsDateTime(DateTimeFeature features) { if (this._label) { throw new DescriptorException("Cannot use a DateTime property as a label"); } var p = new DateTimeProperty(features) { Discrete = true, Name = this._name }; this.AddProperty(p); return(this._descriptor); }
/// <summary>Adds DateTime property to descriptor with previously chained name.</summary> /// <exception cref="DescriptorException">Thrown when a Descriptor error condition occurs.</exception> /// <param name="portion">Which date portions to use (can pipe: DateTimeFeature.Year | /// DateTimeFeature.DayOfWeek)</param> /// <returns>descriptor with added property.</returns> public Descriptor AsDateTime(DatePortion portion) { if (_label) { throw new DescriptorException("Cannot use an DateTime property as a label"); } var p = new DateTimeProperty(portion) { Discrete = true, Name = _name }; AddProperty(p); return(_descriptor); }
public void DateTime_Property_Save_And_Load() { DateTimeProperty p = new DateTimeProperty(DateTimeFeature.DayOfWeek | DateTimeFeature.Second | DateTimeFeature.Minute); p.Name = "MyProp"; p.Discrete = false; p.Start = 5; Serialize(p); var po = Deserialize<DateTimeProperty>(); Assert.AreEqual(p.Name, po.Name); Assert.AreEqual(p.Type, po.Type); Assert.AreEqual(p.Discrete, po.Discrete); Assert.AreEqual(p.Start, po.Start); Assert.AreEqual(p.Features, po.Features); Assert.AreEqual(p.Length, po.Length); }
/// <summary>Constructor.</summary> /// <param name="portion">The portion.</param> public DateFeatureAttribute(DatePortion portion) { dp = new DateTimeProperty(portion); }
/// <summary>Constructor.</summary> /// <param name="features">The features.</param> public DateFeatureAttribute(DateTimeFeature features) { dp = new DateTimeProperty(features); }
/// <summary>Adds DateTime property to descriptor with previously chained name.</summary> /// <exception cref="DescriptorException">Thrown when a Descriptor error condition occurs.</exception> /// <param name="portion">Which date portions to use (can pipe: DateTimeFeature.Year | /// DateTimeFeature.DayOfWeek)</param> /// <returns>descriptor with added property.</returns> public Descriptor AsDateTime(DatePortion portion) { if (_label) throw new DescriptorException("Cannot use an DateTime property as a label"); var p = new DateTimeProperty(portion) { Discrete = true, Name = _name }; AddProperty(p); return _descriptor; }
public DateFeatureAttribute(DatePortion portion) { dp = new DateTimeProperty(portion); }
public DateFeatureAttribute(DateTimeFeature features) { dp = new DateTimeProperty(features); }
/// <summary>Adds DateTime property to descriptor with previously chained name.</summary> /// <exception cref="DescriptorException">Thrown when a Descriptor error condition occurs.</exception> /// <param name="features"> /// Which date features to use (can pipe: DateTimeFeature.Year | /// DateTimeFeature.DayOfWeek) /// </param> /// <returns>descriptor with added property.</returns> public Descriptor AsDateTime(DateTimeFeature features) { if (this._label) { throw new DescriptorException("Cannot use a DateTime property as a label"); } var p = new DateTimeProperty(features) { Discrete = true, Name = this._name }; this.AddProperty(p); return this._descriptor; }