UnitBlock.cs 903 Bytes
Newer Older
Eric Domke's avatar
Eric Domke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Globalization;

namespace ExCSS.Model.TextBlocks
{
    internal class UnitBlock : Block
    {
        private string _value;

        UnitBlock(GrammarSegment type)
        {
            GrammarSegment = type;
        }

        internal Single Value
        {
            get { return Single.Parse(_value, CultureInfo.InvariantCulture); }
        }

        internal string Unit { get; private set; }

        internal static UnitBlock Percentage(string value)
        {
            return new UnitBlock(GrammarSegment.Percentage) { _value = value, Unit = "%" };
        }

        internal static UnitBlock Dimension(string value, string dimension)
        {
            return new UnitBlock(GrammarSegment.Dimension) { _value = value, Unit = dimension };
        }

        public override string ToString()
        {
            return _value + Unit;
        }
    }
}