public override bool Equals(object o) { StringEmulator a = o as StringEmulator; if (a == null) { return(false); } else { if (this.s1.Equals(a.s1) == true) { return(true); } else { string pattern = ""; //Console.WriteLine("DEBUG: {0}", a.GetString()); if (a.GetString()[0] == '*') //In the beginning { if (a.GetSize() == 1) //all { return(true); } else { pattern += a.GetString().Substring(1) + "$"; Regex rx = new Regex(@pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); MatchCollection matches = rx.Matches(s1); if (matches.Count > 0) { return(true); } } } if (a.GetString()[a.GetSize() - 1] == '*') //In the end { pattern += "^" + a.GetString().Substring(0, a.GetSize() - 2); Regex rx = new Regex(@pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); MatchCollection matches = rx.Matches(s1); if (matches.Count > 0) { return(true); } } return(false); } } }
private static List <Lock> LockedTuples = new List <Lock>(); //Locks in the Tuplespace static void Main(string[] args) { object[] tupleOBJ = new object[1]; tupleOBJ[0] = new StringEmulator("a"); MyTuple mt = new MyTuple(tupleOBJ); //LockedTuples.Add(mt); HashSet <MyTuple> TuplesLocked = new HashSet <MyTuple>(); TuplesLocked.Add(mt); Console.WriteLine(TuplesLocked.Contains(mt)); Console.ReadLine(); }