tag:blogger.com,1999:blog-7519834318544959083.post3335164926597043183..comments2024-03-24T16:15:13.462+01:00Comments on Outcome Counts: Units of Measure in C#: IntroductionAnonymoushttp://www.blogger.com/profile/10522059195857961758noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-7519834318544959083.post-8946411904215897502013-06-26T13:32:38.203+02:002013-06-26T13:32:38.203+02:00Nice post very helpful
DBAKingsNice post very helpful<br /><a href="http://www.dbakings.com/CSharp/Introductiontocsharp.aspx" rel="nofollow">DBAKings</a>Anonymoushttps://www.blogger.com/profile/14178155909391788234noreply@blogger.comtag:blogger.com,1999:blog-7519834318544959083.post-68931661219492346502013-01-16T10:54:19.524+01:002013-01-16T10:54:19.524+01:00Dear Young,
I am not sure I understand your quest...Dear Young,<br /><br />I am not sure I understand your question? Could you please elaborate?<br /><br />Best regards,<br />AndersAnonymoushttps://www.blogger.com/profile/10522059195857961758noreply@blogger.comtag:blogger.com,1999:blog-7519834318544959083.post-61158596857329719212013-01-14T12:38:31.657+01:002013-01-14T12:38:31.657+01:00That's stunning I didn't know about all th...That's stunning I didn't know about all this until the moment I saw this blog post of yours over here. I also wanted to ask you something that is connected with your blog. Do you own any valuable data about how to defend your entries from being used without your awareness about it?Younghttp://sweetestidleness.wordpress.com/noreply@blogger.comtag:blogger.com,1999:blog-7519834318544959083.post-81802613788046752412011-10-02T20:43:16.275+02:002011-10-02T20:43:16.275+02:00Dear Darnell,
many thanks for prodviding the exam...Dear Darnell,<br /><br />many thanks for prodviding the examples from your Units of Measurement API. It is the library that is described in this blog post, right? http://splotter.wordpress.com/2009/09/03/csharp-unit-of-measurement/<br />Have you been doing any more work on your library lately?<br /><br />When starting the work on csunits, I initially Googled for alternatives, and at that time I came across your solution as well. Yet some other approaches were described on Stackoverflow, as also discussed with Julius above.<br /><br />In my opinion, all available solutions were too heavy-weight, and therefore I designed my own library. Please try it out, and if you find issues, do not hesitate to report them.<br /><br />Best regards,<br />AndersAnonymoushttps://www.blogger.com/profile/10522059195857961758noreply@blogger.comtag:blogger.com,1999:blog-7519834318544959083.post-57279656334626294192011-10-01T06:03:21.058+02:002011-10-01T06:03:21.058+02:00oops.. looks like the generics tags were scraped o...oops.. looks like the generics tags were scraped out by blogger.<br /><br />Duration hr = Measure.Duration<Hours>(24);<br />Area Area = Measure.Area<SquareMeters>(1000);<br />Weight kg = Measure.Weight<Kilograms>(10);<br /><br />Length length1 = Measure.Length<Meters>(10);<br />Length length2 = Measure.Length<Centimeters>(100);<br />Length length3 = Measure.Length<Kilometers>(1);<br />//Do some operation<br />Length newLength = length1 + length2 + length3;<br />//Check result in meters<br />Assert.Equal(1011, newLength.In<Meters>());splotterhttps://www.blogger.com/profile/04197933451584864038noreply@blogger.comtag:blogger.com,1999:blog-7519834318544959083.post-53150348224873670302011-10-01T05:54:25.511+02:002011-10-01T05:54:25.511+02:00Interesting! I've done similar library in C#:
...Interesting! I've done similar library in C#:<br /><br />Here's how the API looks like:<br /><br />Duration hr = Measure.Duration(24);<br />Area Area = Measure.Area(1000);<br />Weight kg = Measure.Weight(10);<br /><br />Basic arithmetic:<br /><br />Length length1 = Measure.Length(10);<br />Length length2 = Measure.Length(100);<br />Length length3 = Measure.Length(1);<br />//Do some operation<br />Length newLength = length1 + length2 + length3;<br />//Check result in meters<br />Assert.Equal(1011, newLength.In());Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7519834318544959083.post-45304412420014405142011-05-06T09:36:11.781+02:002011-05-06T09:36:11.781+02:00Hi Anders,
Yes, that is where I got the extension...Hi Anders,<br /><br />Yes, that is where I got the extension method idea from. <br /><br />I do see your concern about overload in the Measure class since you are publishing this as a library. We do not have this concern since we are a small business with more control over the usage. You could restrict the inheritance of the Measure class by making it sealed, but I guess that is not a preferred solution.<br /><br />I will keep you posted on changes we do!<br /><br />-JuliusJuliusenhttps://www.blogger.com/profile/05148867162423704066noreply@blogger.comtag:blogger.com,1999:blog-7519834318544959083.post-67371960555703800492011-05-05T20:27:59.926+02:002011-05-05T20:27:59.926+02:00Hi again Julius,
and how very interesting that yo...Hi again Julius,<br /><br />and how very interesting that you implemented extension methods on AmountType. I have seen a similar suggestion on StackOverflow, http://stackoverflow.com/questions/348853/units-of-measure-in-c-almost/2949803#2949803, is that where you got the idea from as well?<br /><br />Also interesting that you have added Times and Divide methods. I made a similar implementation earlier, but ended up having concerns about overloaded methods, and decided to implement Times and Divide in a separate static class. But it is good to see the compactness you have been able to achieve.<br /><br />Thanks for sharing!<br />AndersAnonymoushttps://www.blogger.com/profile/10522059195857961758noreply@blogger.comtag:blogger.com,1999:blog-7519834318544959083.post-36330321016204785782011-05-05T17:00:38.044+02:002011-05-05T17:00:38.044+02:00Hi Anders,
Just wanted to let you know that we ha...Hi Anders,<br /><br />Just wanted to let you know that we have done some extensions to the library to make it more fluent;<br /><br />Added extension methods for AmountType so you can write;<br /><br />75.0.kg()<br />compared to<br />new StandardMeasure< Mass>(75.0).<br /><br />Also added Times and Divide to Measure class in the form of<br />public Measure< Q2> Times< Q1, Q2>(Measure< Q1> factor, IUnit< Q2> iUnit)...<br /><br />This enable you to write;<br /><br />var vol = 30.0.cm().Times(0.02.m2(), Volume.Liter);<br /><br />compared to<br /> Measure height = new Measure (30.0, Length.CentiMeter);<br />StandardMeasure< Area> area = (StandardMeasure< Area>)0.02;<br /><br />StandardMeasure< Volume> stdVol;<br />ArithmeticOperations.Times(height, area, out stdVol);<br /><br />var vol = stdVol[Volume.Liter]<br /><br />-JuliusJuliusenhttps://www.blogger.com/profile/05148867162423704066noreply@blogger.comtag:blogger.com,1999:blog-7519834318544959083.post-31368189325997889982011-04-29T16:49:14.941+02:002011-04-29T16:49:14.941+02:00Hi Julius,
and many thanks for pointing out the e...Hi Julius,<br /><br />and many thanks for pointing out the error in QuantityDimension.cs. Length dimension should indeed be zero for electric current :-) I will fix this right away.<br /><br />Please feel free to make any changes and extensions you like (as long as you do not remove the copyright notices), and if you would like to use the library in a commercial product, you are more than welcome. <br /><br />I would of course appreciate it if you would forward the extensions you make; maybe it could save me some work. Also, if you use the library in a commercial product it would be great if you notify me when it is available.<br /><br />Best regards,<br />AndersAnonymoushttps://www.blogger.com/profile/10522059195857961758noreply@blogger.comtag:blogger.com,1999:blog-7519834318544959083.post-45780570585372341012011-04-29T16:30:02.174+02:002011-04-29T16:30:02.174+02:00Hey, I had a look at your library and I think it l...Hey, I had a look at your library and I think it looks very good. <br /><br />It is a shame that c# does not have the f# ability to include unit handling in the compiler.<br /><br />We will probably try to use it in an upcoming project, but we will have to extend the units and quantities to facilitate our domain.<br /><br />I hate reading licenses (and have trouble understanding them), but am I right when I am allowed to extend the library with more units and quantities by altering the code, and use the library in a commercial product? <br /><br />Note: I think there is a bug in QuantityDimesion line 37, the Length dimension should be 0, not 10.<br /><br />Cheers<br />JuliusJuliusenhttps://www.blogger.com/profile/05148867162423704066noreply@blogger.com