private static void RunEnumParserDemo() { bool ignoreCase = true; // set whether case will be ignored when parsing enum var parser = new EnumParser <Seasons>(ignoreCase); var result1 = parser.Parse("winTER"); // Converts to Seasons.Winter var result2 = parser.Parse("summer"); // Converts to Seasons.Summer }
protected override void SolveInstance(IGH_DataAccess DA) { double beta = 1; string loadPosition = "top"; bool continuouslyRestrained = false; if (!DA.GetData(0, ref beta)) { // pass } if (!DA.GetData(1, ref loadPosition)) { // pass } if (!DA.GetData(2, ref continuouslyRestrained)) { // pass } if (loadPosition == null) { return; } VerticalAlignment alignment = EnumParser.Parse <VerticalAlignment>(loadPosition); DA.SetData(0, FemDesign.Bars.Buckling.BucklingLength.PressuredTopFlange(alignment, beta, continuouslyRestrained)); }
public static Either <TLeft, TEnum> ParseToEnum <TLeft, TEnum>( this Either <TLeft, string> source, bool ignoreCase, TLeft left) where TEnum : struct { return(source.FlatMap(x => EnumParser.Parse <TLeft, TEnum>(x, ignoreCase, left))); }
public static Either <TLeft, TEnum> ParseToEnum <TLeft, TEnum>( this string source, bool ignoreCase, TLeft left) where TEnum : struct { return(EnumParser.Parse <TLeft, TEnum>(source, ignoreCase, left)); }
protected override void SolveInstance(IGH_DataAccess DA) { // Get indata string countryCode = "S"; DA.GetData("CountryCode", ref countryCode); List <FemDesign.GenericClasses.IStructureElement> elements = new List <FemDesign.GenericClasses.IStructureElement>(); DA.GetDataList("Structure Elements", elements); List <FemDesign.GenericClasses.ILoadElement> loads = new List <FemDesign.GenericClasses.ILoadElement>(); DA.GetDataList("Loads", loads); List <FemDesign.Loads.LoadCase> loadCases = new List <FemDesign.Loads.LoadCase>(); DA.GetDataList("LoadCases", loadCases); List <FemDesign.Loads.LoadCombination> loadCombinations = new List <FemDesign.Loads.LoadCombination>(); DA.GetDataList("LoadCombinations", loadCombinations); List <FemDesign.Loads.ModelGeneralLoadGroup> loadGroups = new List <FemDesign.Loads.ModelGeneralLoadGroup>(); DA.GetDataList("LoadGroups", loadGroups); // Create model Model model = new Model(EnumParser.Parse <Country>(countryCode), elements, loads, loadCases, loadCombinations, loadGroups); DA.SetData("FdModel", model); }
protected override void SolveInstance(IGH_DataAccess DA) { string loadPosition = "top"; bool continuouslyRestrained = false; bool cantilever = false; if (!DA.GetData(0, ref loadPosition)) { // pass } if (!DA.GetData(1, ref continuouslyRestrained)) { // pass } if (!DA.GetData(2, ref cantilever)) { // pass } if (loadPosition == null) { return; } VerticalAlignment alignment = EnumParser.Parse <VerticalAlignment>(loadPosition); DA.SetData(0, FemDesign.Bars.Buckling.BucklingLength.LateralTorsional(alignment, continuouslyRestrained, cantilever)); }
private NumberStyles GetAsNumberStyle(ITagAttribute styles, TagModel model, NumberStyles style) { if (Styles == null) { return(style); } string stylesAsString = GetAsString(Styles, model); if (stylesAsString != null) { bool first = true; string[] stylesStr = stylesAsString.Split(','); foreach (string styleStr in stylesStr) { if (first) { style = EnumParser <NumberStyles> .Parse(styleStr); } else { style = style | EnumParser <NumberStyles> .Parse(styleStr); } first = false; } } return(style); }
/// <summary> /// Deserializes the property data. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">reader</exception> /// <exception cref="System.NotSupportedException"></exception> internal static Property Deserialize(XmlReader reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } var name = reader.GetAttribute("Name"); var dataType = EnumParser <DataTypeId> .Parse(reader.GetAttribute("Type")); var description = reader.GetAttribute("Description"); var stringValue = reader.ReadString(); switch (dataType) { case DataTypeId.DateTime: return(Create(name, XmlConvert.ToDateTime(stringValue, XmlDateTimeSerializationMode.RoundtripKind), description)); case DataTypeId.Double: return(Create(name, XmlConvert.ToDouble(stringValue), description)); case DataTypeId.Integer: return(Create(name, XmlConvert.ToInt64(stringValue), description)); case DataTypeId.String: return(Create(name, stringValue, description)); case DataTypeId.TimeSpan: return(Create(name, XmlConvert.ToTimeSpan(stringValue), description)); default: throw new NotSupportedException($"DataTypeId \"{dataType}\" is not supported"); } }
protected override void SolveInstance(IGH_DataAccess DA) { double diameter = 0; FemDesign.Materials.Material material = null; string profile = "ribbed"; if (!DA.GetData("Diameter", ref diameter)) { return; } if (!DA.GetData("Material", ref material)) { return; } DA.GetData("Profile", ref profile); if (material == null || profile == null) { return; } WireProfileType _profile = EnumParser.Parse <WireProfileType>(profile); FemDesign.Reinforcement.Wire obj = new FemDesign.Reinforcement.Wire(diameter, material, _profile); DA.SetData(0, obj); }
/// <summary> /// Define straight reinforcement layout for surface reinforcement. /// </summary> /// <remarks>Create</remarks> /// <param name="direction">"x"/"y"</param> /// <param name="space">Spacing between bars.</param> /// <param name="face">"top"/"bottom"</param> /// <param name="cover">Reinforcement concrete cover.</param> public Straight(string direction, double space, string face, double cover) { this.Direction = EnumParser.Parse <ReinforcementDirection>(direction); this.Space = space; this.Face = EnumParser.Parse <Face>(face); this.Cover = cover; }
public static Model CreateNewModel([DefaultArgument("\"S\"")] string countryCode, [DefaultArgument("[]")] List <object> elements, [DefaultArgument("[]")] List <object> loads, [DefaultArgument("[]")] List <Loads.LoadCase> loadCases, [DefaultArgument("[]")] List <Loads.LoadCombination> loadCombinations) { var _elements = elements.Cast <IStructureElement>().ToList(); var _loads = loads.Cast <ILoadElement>().ToList(); Model fdModel = new Model(EnumParser.Parse <Country>(countryCode), _elements, _loads, loadCases, loadCombinations); return(fdModel); }
public void ParsePlain() { foo f = EnumParser.Parse <foo>("bar"); Assert.AreEqual(foo.bar, f); f = EnumParser.Parse <foo>("blah"); Assert.AreEqual(foo.NONE, f); }
public void ParseAttr() { bar b = EnumParser.Parse <bar>("moo"); Assert.AreEqual(bar.bloo, b); b = EnumParser.Parse <bar>("bloo"); Assert.AreEqual(bar.bloo, b); }
public void Test_Parse(string name, TestEnum expectedEnumValue) { // act var enumValue = EnumParser <TestEnum> .Parse(name); // assert Assert.That(enumValue, Is.EqualTo(expectedEnumValue)); }
public static Model CreateNewModel([DefaultArgument("\"S\"")] string countryCode, [DefaultArgument("[]")] List <Bars.Bar> bars, [DefaultArgument("[]")] List <ModellingTools.FictitiousBar> fictitiousBars, [DefaultArgument("[]")] List <Shells.Slab> shells, [DefaultArgument("[]")] List <ModellingTools.FictitiousShell> fictitiousShells, [DefaultArgument("[]")] List <Shells.Panel> panels, [DefaultArgument("[]")] List <Cover> covers, [DefaultArgument("[]")] List <object> loads, [DefaultArgument("[]")] List <Loads.LoadCase> loadCases, [DefaultArgument("[]")] List <Loads.LoadCombination> loadCombinations, [DefaultArgument("[]")] List <object> supports, [DefaultArgument("[]")] List <StructureGrid.Storey> storeys, [DefaultArgument("[]")] List <StructureGrid.Axis> axes) { // Create model Model model = new Model(EnumParser.Parse <Country>(countryCode)); var _supports = supports.Cast <GenericClasses.ISupportElement>().ToList(); model.AddEntities(bars, fictitiousBars, shells, fictitiousShells, panels, covers, loads, loadCases, loadCombinations, _supports, storeys, axes, null, false); return(model); }
public void Dashes() { doo d = doo.moo_vie; string s = EnumParser.ToString(d); Assert.AreEqual("moo-vie", s); d = EnumParser.Parse <doo>(s); Assert.AreEqual(doo.moo_vie, d); }
public void BruteForceTest() { var names = Enum.GetNames(typeof(IceCreamFlavour)); foreach (var name in names) { var parsed = EnumParser.Parse <IceCreamFlavour>(name); Assert.AreEqual(Enum.Parse(typeof(IceCreamFlavour), name), parsed); } }
public static T?GetAs <T>(ITagAttribute expressions, TagModel model, T?fallBack) where T : struct { string result = GetAsString(expressions, model); if (!String.IsNullOrEmpty(result)) { return(EnumParser <T> .Parse(result)); } return(fallBack); }
public void Null() { string s = EnumParser.ToString(foo.NONE); Assert.IsNull(s); foo f = EnumParser.Parse <foo>(""); Assert.AreEqual(foo.NONE, f); bar b = EnumParser.Parse <bar>(""); Assert.AreEqual(bar.goo, b); }
public Response <Page <Persistence.Models.Task> > List(int count = 50, string sortDirection = null, int start = 0) { var filter = new ListFilter { Count = count, SortDirection = sortDirection == null ? SortDirection.Descending : EnumParser.Parse <SortDirection>(sortDirection), Start = start, }; var cache = new InMemoryRepositoryModelCache(); var result = _taskRepository.List(_user, filter, cache) .Transform(GetSerializableVersion); return(Response.Create(result)); }
/// <inheritdoc /> protected override bool DeserializeItem(XmlReader reader, Version version) { if (base.DeserializeItem(reader, version)) { return(true); } switch (reader.Name) { case "DeviationType": DeviationType = EnumParser <DeviationTypes> .Parse(reader.ReadString()); return(true); } return(false); }
public void ParseCountryTest() { Assert.IsTrue(EnumParser.Parse <Country>("S") == Country.S, "Should be able to parse country successfully."); Assert.IsTrue(EnumParser.Parse <Country>("s") == Country.S, "Should be able to parse country for lower case letters."); Assert.IsTrue(EnumParser.Parse <Country>("Sweden") == Country.S, "Should be able to parse country from full country name."); Assert.IsTrue(EnumParser.Parse <Country>("sweden") == Country.S, "Should be able to parse country from full country name."); Assert.ThrowsException <ArgumentException>(() => EnumParser.Parse <Country>("X"), "Should throw exception on invalid country code."); foreach (string countryCode in new string[] { "D", "DK", "EST", "FIN", "GB", "H", "LT", "N", "NL", "PL", "RO", "S", "TR" }) { try { EnumParser.Parse <Country>(countryCode); } catch (Exception) { Assert.Fail($"Should be able to parse country \"{countryCode}\" successfully"); } } }
public void BadValuesFail() { try { var value = EnumParser.Parse <IceCreamFlavour>("MuchoPicante"); Assert.Fail("Exception not thrown"); } catch (EnumParseException e) { Assert.IsNotNull(e); Assert.IsNotNull(e.ValidNames); Assert.IsNotNull(e.InvalidName); Assert.AreEqual("MuchoPicante", e.InvalidName); Assert.AreEqual(4, e.ValidNames.Count); Assert.IsTrue(e.ValidNames.ToList().Contains("Sherbert")); } catch { Assert.Fail("Wrong exception type"); } }
protected override void SolveInstance(IGH_DataAccess DA) { // get data string direction = null; double space = 0; string face = null; double cover = 0; if (!DA.GetData(0, ref direction)) { return; } if (!DA.GetData(1, ref space)) { return; } if (!DA.GetData(2, ref face)) { return; } if (!DA.GetData(3, ref cover)) { return; } if (direction == null || face == null) { return; } Face _face = EnumParser.Parse <Face>(face); ReinforcementDirection _direction = EnumParser.Parse <ReinforcementDirection>(direction); FemDesign.Reinforcement.Straight obj = new FemDesign.Reinforcement.Straight(_direction, space, _face, cover); // return DA.SetData(0, obj); }
protected override void SolveInstance(IGH_DataAccess DA) { // string alignment = "center"; double ecc = 0; bool eccCalc = false; bool eccByCracking = false; if (!DA.GetData(0, ref alignment)) { // pass } if (!DA.GetData(1, ref ecc)) { // pass } if (!DA.GetData(2, ref eccCalc)) { // pass } if (!DA.GetData(3, ref eccByCracking)) { // pass } if (alignment == null) { return; } VerticalAlignment _alignment = EnumParser.Parse <VerticalAlignment>(alignment); FemDesign.Shells.ShellEccentricity shellEcc = new FemDesign.Shells.ShellEccentricity(_alignment, ecc, eccCalc, eccByCracking); // return DA.SetData(0, shellEcc); }
protected override void SolveInstance(IGH_DataAccess DA) { // Get indata string countryCode = "S"; if (!DA.GetData(0, ref countryCode)) { // pass } List <FemDesign.Bars.Bar> bars = new List <FemDesign.Bars.Bar>(); if (!DA.GetDataList(1, bars)) { // pass } List <FemDesign.ModellingTools.FictitiousBar> fictBars = new List <FemDesign.ModellingTools.FictitiousBar>(); if (!DA.GetDataList(2, fictBars)) { // pass } List <FemDesign.Shells.Slab> slabs = new List <FemDesign.Shells.Slab>(); if (!DA.GetDataList(3, slabs)) { // pass } List <FemDesign.ModellingTools.FictitiousShell> fictShells = new List <FemDesign.ModellingTools.FictitiousShell>(); if (!DA.GetDataList(4, fictShells)) { // pass } List <FemDesign.Shells.Panel> panels = new List <Shells.Panel>(); { if (!DA.GetDataList(5, panels)) { // pass } } List <FemDesign.Cover> covers = new List <FemDesign.Cover>(); if (!DA.GetDataList(6, covers)) { // pass } List <FemDesign.GenericClasses.ILoadElement> loads = new List <FemDesign.GenericClasses.ILoadElement>(); if (!DA.GetDataList(7, loads)) { // pass } List <FemDesign.Loads.LoadCase> loadCases = new List <FemDesign.Loads.LoadCase>(); if (!DA.GetDataList(8, loadCases)) { // pass } List <FemDesign.Loads.LoadCombination> loadCombinations = new List <FemDesign.Loads.LoadCombination>(); if (!DA.GetDataList(9, loadCombinations)) { // pass } List <FemDesign.GenericClasses.ISupportElement> supports = new List <FemDesign.GenericClasses.ISupportElement>(); if (!DA.GetDataList(10, supports)) { // pass } List <FemDesign.StructureGrid.Axis> axes = new List <StructureGrid.Axis>(); if (!DA.GetDataList(11, axes)) { // pass } List <FemDesign.StructureGrid.Storey> storeys = new List <StructureGrid.Storey>(); if (!DA.GetDataList(12, storeys)) { // pass } // Create model List <object> _loads = loads.Cast <object>().ToList(); Model model = new Model(EnumParser.Parse <Country>(countryCode)); model.AddEntities(bars, fictBars, slabs, fictShells, panels, covers, _loads, loadCases, loadCombinations, supports, storeys, axes, null, false); DA.SetData(0, model); }
public static BinarySensorType Parse(string input) { return(EnumParser.Parse <BinarySensorType>(input)); }
public void SloppySpacingWorks() { Assert.AreEqual(IceCreamFlavour.Picante, EnumParser.Parse <IceCreamFlavour>(" Picante ")); }
public void BasicParseWorks() { Assert.AreEqual(IceCreamFlavour.Picante, EnumParser.Parse <IceCreamFlavour>("Picante")); }
/// <summary> /// Convenience method to parse a string as an enum type /// </summary> public static T ParseEnum <T>(this string enumValue) where T : struct, IConvertible { return(EnumParser <T> .Parse(enumValue)); }