public double Convert(double value, TempEnum from, TempEnum to)
        {
            if (from == to)
                return value;

            if (from == TempEnum.Fahrenheit)
            {
                if (to == TempEnum.Celsius)
                    return (value - 32) * 5.0 / 9;
                if (to == TempEnum.Kelvin)
                    return Convert(value, from, TempEnum.Celsius) + 273;
            }

            if (from == TempEnum.Celsius)
            {
                if (to == TempEnum.Fahrenheit)
                    return value * 9.0 / 5 + 32;
                if (to == TempEnum.Kelvin)
                    return value + 273;
            }

            if (from == TempEnum.Kelvin)
            {
                if (to == TempEnum.Fahrenheit)
                    return Convert(value, TempEnum.Fahrenheit, TempEnum.Celsius);
                if (to == TempEnum.Celsius)
                    return value - 273;
            }

            throw new ApplicationException();
        }
Example #2
0
        static void addEnumRestriction(XmlSchemaSimpleType restrictedtype, TempEnum tempEnum)
        {
            var restriction = new XmlSchemaSimpleTypeRestriction();

            restriction.BaseTypeName = new XmlQualifiedName(NSPREFIX_XSD + ":token");
            foreach (var codeListEntry in tempEnum.codelistEntries.OrderBy(x => x.Name))
            {
                var xmlEnum = new XmlSchemaEnumerationFacet();
                xmlEnum.Value = codeListEntry.Name;
                //add facet
                restriction.Facets.Add(xmlEnum);
            }
            //add the restriction to the simple type
            restrictedtype.Content = restriction;
        }
Example #3
0
 public IAirConditioner ExecuteCreation(TempEnum action, double temp) => _factories[action].Create(temp);
Example #4
0
        private static void AddSimpleTypeDefinition(XmlSchema schema, GeneratorContext context, TempEnum tempEnum)
        {
            var restrictedtype = new XmlSchemaSimpleType();

            restrictedtype.Name = NDR.GetBasicTypeName(tempEnum.sourceEnum);

            // enumeration with actual values
            addEnumRestriction(restrictedtype, tempEnum);

            //add the restrictedType to the schema
            schema.Items.Add(restrictedtype);
        }