Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HasFlag doesn't exist in NET 3.5 #108

Merged
merged 1 commit into from
Sep 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions GongSolutions.Wpf.DragDrop/DropTargetInsertionAdorner.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Controls;
using System.Collections;
#if NET35
using GongSolutions.Wpf.DragDrop.Utilities;
#endif

namespace GongSolutions.Wpf.DragDrop
{
Expand Down
30 changes: 27 additions & 3 deletions GongSolutions.Wpf.DragDrop/Utilities/TypeUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Reflection;

namespace GongSolutions.Wpf.DragDrop.Utilities
{
public class TypeUtilities
public static class TypeUtilities
{
#if NET35
/// <summary>
/// Check to see if a flags enumeration has a specific flag set.
/// </summary>
/// <param name="variable">Flags enumeration to check</param>
/// <param name="flag"></param>
public static bool HasFlag(this Enum variable, Enum flag)
{
if (variable == null) {
return false;
}

if (flag == null) {
throw new ArgumentNullException("flag");
}

if (flag.GetType() != variable.GetType()) {
throw new ArgumentException(string.Format("Enumeration type mismatch. The flag is of type '{0}', was expecting '{1}'.", flag.GetType(), variable.GetType()));
}

var uFlag = Convert.ToUInt64(flag);
var uVar = Convert.ToUInt64(variable);
return ((uVar & uFlag) == uFlag);
}
#endif

public static IEnumerable CreateDynamicallyTypedList(IEnumerable source)
{
var type = GetCommonBaseClass(source);
Expand Down