12,350,030 members (24,080 online)

44.1K views
1.4K downloads
108 bookmarked
Posted

# 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); } } }```

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

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.

## License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

## About the Author

 Software Developer (Senior) Freelancer Vietnam
No Biography provided

## You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 14 Sep 2010
Article Copyright 2010 by vnmatt
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid