Created
December 5, 2012 16:02
-
-
Save DTTerastar/4216893 to your computer and use it in GitHub Desktop.
PercentComplete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PercentComplete : IDisposable | |
{ | |
private readonly float _max; | |
private readonly float _min; | |
private readonly int _total; | |
private int _current; | |
public PercentComplete(int total) | |
: this(total, 0, 100) | |
{ | |
} | |
private PercentComplete(int total, float min, float max) | |
{ | |
_total = total; | |
_min = min; | |
_max = max; | |
} | |
public int IntValue | |
{ | |
get { return (int)Math.Round(Calc(_current)); } | |
} | |
public float Value | |
{ | |
get { return Calc(_current); } | |
} | |
public void Dispose() | |
{ | |
} | |
private float Calc(int current) | |
{ | |
return _min + (current * (_max - _min)) / _total; | |
} | |
public void Next() | |
{ | |
_current++; | |
} | |
public PercentComplete Next(int subTotal) | |
{ | |
return new PercentComplete(subTotal, Calc(_current), Calc(++_current)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment