12,884,771 members (31,999 online)

#### Stats

49.9K views
110 bookmarked
Posted 5 Jul 2010

# Plug-in Framework

, 14 Sep 2010 CPOL
Basic framework for building desktop plug-in applications.
 PluginFramework Demo bin Debug Plugins Release Plugins Forms Properties DemoFormPlugin Properties DemoUserControlPlugin Properties MBG.Extensions Collections Controls Core Data Math Properties Xml MBG.IO Properties PluginFramework.Attributes Properties PluginFramework.Controls Properties Resources Icons SettingsIcon.ico TreeIcon.ico Images SettingsImage.png TreeImage.png PluginFramework.Interface Properties PluginFramework.Utilities Properties ```﻿using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; namespace MBG.Extensions.Math { //TODO: Test public static class DoubleExtensions { /// /// Divide by given divisor and round UP to the next whole number. /// For example, 10001 / 9000 = 1.111222 and will be rounded UP to 2 /// /// The dividend /// The divisor /// Quotient public static int DivideRoundUp(double dividend, double divisor) { if (divisor == 0) { throw new DivideByZeroException(); } if (divisor == -1 && dividend == int.MinValue) { throw new ArithmeticException(string.Concat("divisor = -1 and dividend = ", int.MinValue)); } int roundedTowardsZeroQuotient = (int)(dividend / divisor); bool dividedEvenly = (dividend % divisor) == 0; if (dividedEvenly) { return roundedTowardsZeroQuotient; } // At this point we know that divisor was not zero // (because we would have thrown) and we know that // dividend was not zero (because there would have been no remainder) // Therefore both are non-zero. Either they are of the same sign, // or opposite signs. If they're of opposite sign then we rounded // UP towards zero so we're done. If they're of the same sign then // we rounded DOWN towards zero, so we need to add one. bool wasRoundedDown = ((divisor > 0) == (dividend > 0)); if (wasRoundedDown) { return roundedTowardsZeroQuotient + 1; } else { return roundedTowardsZeroQuotient; } } //TODO: Finish public static string ToFraction(this double d) { string s = d.ToString(CultureInfo.InvariantCulture); int length = s.Substring(s.IndexOf('.') + 1).Count(); int numerator = int.Parse(s.Substring(s.IndexOf('.') + 1)); int denominator = (int)System.Math.Pow((double)10.0, (double)(length)); int gcd = Int32Extensions.GreatestCommonDivisor(numerator, denominator); return string.Concat(numerator / gcd, '/', denominator / gcd); } } }```

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.