diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-11-02 22:05:41 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-11-02 22:05:41 -0800 |
commit | 8969dfec9e4e4ecc45f909137dc3a23d7af0bee8 (patch) | |
tree | c903f51425a18182463965093ac3791f98c75145 /src/DotNetOAuth/Util.cs | |
parent | 71e99449ee02155f34bb4928313c2200246b8a78 (diff) | |
download | DotNetOpenAuth-8969dfec9e4e4ecc45f909137dc3a23d7af0bee8.zip DotNetOpenAuth-8969dfec9e4e4ecc45f909137dc3a23d7af0bee8.tar.gz DotNetOpenAuth-8969dfec9e4e4ecc45f909137dc3a23d7af0bee8.tar.bz2 |
Second stab at app-specific consumer classes.
Refactored to be a static class that operates on some consumer object so that desktop and web consumer alike can use it.
Diffstat (limited to 'src/DotNetOAuth/Util.cs')
-rw-r--r-- | src/DotNetOAuth/Util.cs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/DotNetOAuth/Util.cs b/src/DotNetOAuth/Util.cs index 1bf76b1..4a1cab9 100644 --- a/src/DotNetOAuth/Util.cs +++ b/src/DotNetOAuth/Util.cs @@ -4,9 +4,10 @@ // </copyright>
//-----------------------------------------------------------------------
namespace DotNetOAuth {
+ using System;
+ using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
- using DotNetOAuth.Messaging;
/// <summary>
/// A grab-bag utility class.
@@ -25,5 +26,22 @@ namespace DotNetOAuth { return string.Format(CultureInfo.InvariantCulture, "{0} ({1})", assemblyFullName, official ? "official" : "private");
}
}
+
+ /// <summary>
+ /// Enumerates through the individual set bits in a flag enum.
+ /// </summary>
+ /// <param name="flags">The flags enum value.</param>
+ /// <returns>An enumeration of just the <i>set</i> bits in the flags enum.</returns>
+ internal static IEnumerable<long> GetIndividualFlags(Enum flags) {
+ long flagsLong = Convert.ToInt64(flags);
+ for (int i = 0; i < sizeof(long) * 8; i++) { // long is the type behind the largest enum
+ // Select an individual application from the scopes.
+ long individualFlagPosition = (long)Math.Pow(2, i);
+ long individualFlag = flagsLong & individualFlagPosition;
+ if (individualFlag == individualFlagPosition) {
+ yield return individualFlag;
+ }
+ }
+ }
}
}
|