13,397,903 members (43,132 online)

#### Stats

56.6K views
1.6K downloads
110 bookmarked
Posted 5 Jul 2010

# Plug-in Framework

, 14 Sep 2010
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; namespace MBG.Extensions.Math { //TODO: Test public static class Int32Extensions { public static bool IsMultipleOf(this int i, int numberToCompare) { return i % numberToCompare == 0; } /// /// 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(int dividend, int 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 = 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; } } public static int LowestCommonMultiple(int lhs, int rhs) { int max = lhs > rhs ? rhs : lhs; int lcm = -1; for (int i = 2; i <= max; i++) { if (lhs.IsMultipleOf(i) && rhs.IsMultipleOf(i)) { lcm = i; break; } } return lcm; } public static int GreatestCommonDivisor(int lhs, int rhs) { int i = 0; while (true) { i = lhs % rhs; if (i == 0) { return rhs; } lhs = rhs; rhs = i; } } public static string ToFraction(this int i) { return ((double)i).ToFraction(); } } }```

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 Australia
No Biography provided

## You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180216.1 | Last Updated 14 Sep 2010
Article Copyright 2010 by vnmatt
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid