当前位置: 首页>>代码示例>>C#>>正文


C# HashSet.IsSubsetOf方法代码示例

本文整理汇总了C#中HashSet.IsSubsetOf方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.IsSubsetOf方法的具体用法?C# HashSet.IsSubsetOf怎么用?C# HashSet.IsSubsetOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HashSet的用法示例。


在下文中一共展示了HashSet.IsSubsetOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parsing_Of_Sc_Query_Output

		public void Parsing_Of_Sc_Query_Output()
		{
			string output = Resources.ScQueryOutput;
			HashSet<ServiceItem> expected = new HashSet<ServiceItem>
			{
				new ServiceItem
				{
					ServiceName = "TermService",
					DisplayName = "Terminal Services"
				},
				new ServiceItem
				{
					ServiceName = "Themes",
					DisplayName = "Themes"
				},
				new ServiceItem
				{
					ServiceName = "UNS",
					DisplayName = "Intel(R) Management and Security Application User Notification Service"
				}
			};

			HashSet<ServiceItem> actual = ServiceHelper_Accessor.ParseServicesOutput(output);

			Assert.IsTrue(expected.IsSubsetOf(actual));
			Assert.IsTrue(expected.IsSupersetOf(actual));
		}
开发者ID:penartur,项目名称:CCNet.Extensions,代码行数:27,代码来源:ServiceHelperTest.cs

示例2: IsScopeSatisfied

 public bool IsScopeSatisfied(HashSet<string> requiredScope, HashSet<string> grantedScope)
 {
     if (requiredScope.IsSubsetOf(grantedScope))
     {
         return true;
     }
     return false;
 }
开发者ID:usbuild,项目名称:azuren,代码行数:8,代码来源:OAuth2ServiceAttribute.cs

示例3: Compare

        protected Expression Compare(BinaryExpression bop)
        {
            var e1 = this.SkipConvert(bop.Left);
            var e2 = this.SkipConvert(bop.Right);
            EntityExpression entity1 = e1 as EntityExpression;
            EntityExpression entity2 = e2 as EntityExpression;

            if (entity1 == null && e1 is OuterJoinedExpression)
            {
                entity1 = ((OuterJoinedExpression)e1).Expression as EntityExpression;
            }

            if (entity2 == null && e2 is OuterJoinedExpression)
            {
                entity2 = ((OuterJoinedExpression)e2).Expression as EntityExpression;
            }

            bool negate = bop.NodeType == ExpressionType.NotEqual;
            if (entity1 != null)
            {
                return this.MakePredicate(e1, e2, entity1.Entity.PrimaryKeys.Select(p => p.Member), negate);
            }
            else if (entity2 != null)
            {
                return this.MakePredicate(e1, e2, entity2.Entity.PrimaryKeys.Select(p => p.Member), negate);
            }

            var dm1 = this.GetDefinedMembers(e1);
            var dm2 = this.GetDefinedMembers(e2);

            if (dm1 == null && dm2 == null)
            {
                // neither are constructed types
                return bop;
            }

            if (dm1 != null && dm2 != null)
            {
                // both are constructed types, so they'd better have the same members declared
                HashSet<string> names1 = new HashSet<string>(dm1.Select(m => m.Name), StringComparer.Ordinal);
                HashSet<string> names2 = new HashSet<string>(dm2.Select(m => m.Name), StringComparer.Ordinal);
                if (names1.IsSubsetOf(names2) && names2.IsSubsetOf(names1))
                {
                    return MakePredicate(e1, e2, dm1, negate);
                }
            }
            else if (dm1 != null)
            {
                return MakePredicate(e1, e2, dm1, negate);
            }
            else if (dm2 != null)
            {
                return MakePredicate(e1, e2, dm2, negate);
            }

            throw new InvalidOperationException(Res.InvalidOperationCompareException);
        }
开发者ID:jaykizhou,项目名称:elinq,代码行数:57,代码来源:ComparisonRewriter.cs

示例4: DispatchPreservesAllRouteValues

        public void DispatchPreservesAllRouteValues(
            DefaultRouteDispatcher sut,
            MethodCallExpression method,
            IDictionary<string, object> routeValues)
        {
            var actual = sut.Dispatch(method, routeValues);

            var expected = new HashSet<KeyValuePair<string, object>>(routeValues);
            Assert.True(expected.IsSubsetOf(actual.RouteValues));
        }
开发者ID:khaledm,项目名称:Hyprlinkr,代码行数:10,代码来源:ScalarRouteDispatcherTests.cs

示例5: IsGroupTagsUnique

 static bool IsGroupTagsUnique(List<CityPack> cities, HashSet<string> tags)
 {
     foreach (CityPack pack in cities)
     {
         if (tags.IsSubsetOf(pack.cities) && !tags.IsProperSubsetOf(pack.cities))
         {
             return false;
         }
     }
     return true;
 }
开发者ID:mikhaelmurmur,项目名称:HackerRank.com.Tasks,代码行数:11,代码来源:Program.cs

示例6: Main

 static void Main()
 {
     var companyTeams =
         new HashSet<string>(){ "Ferrari", "McLaren", "Mersedes" };
     var traditionalTeams =
         new HashSet<string>() { "Ferrari", "McLaren" };
     var privateTeams =
         new HashSet<string>() { "Red Bull", "Lotus", "Toro Rosso", "Force India", "Sauber" };
     if (traditionalTeams.IsSubsetOf(companyTeams))
     {
         Console.WriteLine("tradTeam is subset of company Teams");
     }
 }
开发者ID:RoykoSerhiy,项目名称:visualStudio_projects,代码行数:13,代码来源:Program.cs

示例7: IsScopeSubset

		/// <summary>
		/// Determines whether one given scope is a subset of another scope.
		/// </summary>
		/// <param name="requestedScope">The requested scope, which may be a subset of <paramref name="grantedScope"/>.</param>
		/// <param name="grantedScope">The granted scope, the suspected superset.</param>
		/// <returns>
		/// 	<c>true</c> if all the elements that appear in <paramref name="requestedScope"/> also appear in <paramref name="grantedScope"/>;
		/// <c>false</c> otherwise.
		/// </returns>
		public static bool IsScopeSubset(string requestedScope, string grantedScope) {
			if (string.IsNullOrEmpty(requestedScope)) {
				return true;
			}

			if (string.IsNullOrEmpty(grantedScope)) {
				return false;
			}

			var requestedScopes = new HashSet<string>(requestedScope.Split(scopeDelimiter, StringSplitOptions.RemoveEmptyEntries));
			var grantedScopes = new HashSet<string>(grantedScope.Split(scopeDelimiter, StringSplitOptions.RemoveEmptyEntries));
			return requestedScopes.IsSubsetOf(grantedScopes);
		}
开发者ID:SachiraChin,项目名称:dotnetopenid,代码行数:22,代码来源:OAuthUtilities.cs

示例8: CreateInstance

        /// <summary>
        /// Gets the instance of the created command object.
        /// </summary>
        /// <param name="tokens">Command line arguments to initialize command with.</param>
        /// <exception cref="Exception{OptionsValidationExceptionArgs}">
        /// Indicates that at least one required option was not specified.
        /// </exception>
        internal object CreateInstance(IDictionary<string, OptionValue> tokens)
        {
            HashSet<string> availableOptions =
                new HashSet<string>(tokens.Select(t => t.Key.ToLowerInvariant()));

            OptionMetadata[] targetMetadata = null;

            // Find options set that matches our tokens collection.
            foreach (var usage in _metadata.Options)
            {
                HashSet<string> requiredOptions =
                    new HashSet<string>(usage.Where(o => o.Required).Select(o => o.Name.ToLowerInvariant()));
                HashSet<string> allOptions =
                    new HashSet<string>(usage.Select(o => o.Name.ToLowerInvariant()));

                if (requiredOptions.IsSubsetOf(availableOptions) &&
                    allOptions.IsSupersetOf(availableOptions))
                {
                    targetMetadata = usage;
                    break;
                }
            }

            if (null == targetMetadata)
            {
                var args = new OptionsValidationExceptionArgs("Invalid command arguments provided.");
                throw new Exception<OptionsValidationExceptionArgs>(args);
            }

            try
            {
                return CreateInstanceInternal(targetMetadata, tokens);
            }
            catch (TargetInvocationException ex)
            {
                var argumentError = ex.InnerException as ArgumentException;
                if (null == argumentError)
                    throw;

                string msg = string.Format("Invalid value for option '{0}'. {1}",
                                           argumentError.ParamName,
                                           argumentError.Message);
                var args = new OptionsValidationExceptionArgs(msg);
                throw new Exception<OptionsValidationExceptionArgs>(args);
            }
            catch (MissingMethodException)
            {
                var args = new OptionsValidationExceptionArgs("Invalid command arguments provided.");
                throw new Exception<OptionsValidationExceptionArgs>(args);
            }
        }
开发者ID:modulexcite,项目名称:WebSync,代码行数:58,代码来源:CommandBuilder.cs

示例9: Main

        static void Main()
        {
            var companyTeams = new HashSet<string>() { "Ferrari", "McLaren", "Mercedes" };
            var traditionalTeams = new HashSet<string>() { "Ferrari", "McLaren" };
            var privateTeams = new HashSet<string>() { "Red Bull", "Lotus", "Toro Rosso", "Force India", "Sauber" };

            if (privateTeams.Add("Williams"))
                WriteLine("Williams added");
            if (!companyTeams.Add("McLaren"))
                WriteLine("McLaren was already in this set");

            if (traditionalTeams.IsSubsetOf(companyTeams))
            {
                WriteLine("traditionalTeams is subset of companyTeams");
            }

            if (companyTeams.IsSupersetOf(traditionalTeams))
            {
                WriteLine("companyTeams is a superset of traditionalTeams");
            }


            traditionalTeams.Add("Williams");
            if (privateTeams.Overlaps(traditionalTeams))
            {
                WriteLine("At least one team is the same with traditional and private teams");
            }

            var allTeams = new SortedSet<string>(companyTeams);
            allTeams.UnionWith(privateTeams);
            allTeams.UnionWith(traditionalTeams);

            WriteLine();
            WriteLine("all teams");
            foreach (var team in allTeams)
            {
                WriteLine(team);
            }

            allTeams.ExceptWith(privateTeams);
            WriteLine();
            WriteLine("no private team left");
            foreach (var team in allTeams)
            {
                WriteLine(team);
            }

        }
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:48,代码来源:Program.cs

示例10: TestSubSetSuperSet

		public void TestSubSetSuperSet ()
		{
			var aSet = new HashSet<int> { 1, 2 };  
			var bSet = new HashSet<int> { 1 };  
		
			Assert.IsTrue (aSet.IsSubsetOf (aSet));
			Assert.IsTrue (bSet.IsSubsetOf (aSet));

			Assert.IsTrue (bSet.IsProperSubsetOf (aSet));
			Assert.IsFalse (aSet.IsProperSubsetOf (aSet));

			Assert.IsTrue (aSet.IsSupersetOf (aSet));
			Assert.IsTrue (aSet.IsSupersetOf (bSet));

			Assert.IsTrue (aSet.IsProperSupersetOf (bSet));
			Assert.IsFalse (aSet.IsProperSupersetOf (aSet));
		}
开发者ID:caloggins,项目名称:DOT-NET-on-Linux,代码行数:17,代码来源:HashSetExampleTests.cs

示例11: Compare

        protected Expression Compare(BinaryExpression bop)
        {
            var e1 = this.SkipConvert(bop.Left);
            var e2 = this.SkipConvert(bop.Right);
            EntityExpression entity1 = e1 as EntityExpression;
            EntityExpression entity2 = e2 as EntityExpression;
            bool negate = bop.NodeType == ExpressionType.NotEqual;
            if (entity1 != null)
            {
                return this.MakePredicate(e1, e2, this.mapping.GetPrimaryKeyMembers(entity1.Entity), negate);
            }
            else if (entity2 != null)
            {
                return this.MakePredicate(e1, e2, this.mapping.GetPrimaryKeyMembers(entity2.Entity), negate);
            }
            var dm1 = this.GetDefinedMembers(e1);
            var dm2 = this.GetDefinedMembers(e2);

            if (dm1 == null && dm2 == null)
            {
                // neither are constructed types
                return bop;
            }

            if (dm1 != null && dm2 != null)
            {
                // both are constructed types, so they'd better have the same members declared
                HashSet<string> names1 = new HashSet<string>(dm1.Select(m => m.Name));
                HashSet<string> names2 = new HashSet<string>(dm2.Select(m => m.Name));
                if (names1.IsSubsetOf(names2) && names2.IsSubsetOf(names1))
                {
                    return MakePredicate(e1, e2, dm1, negate);
                }
            }
            else if (dm1 != null)
            {
                return MakePredicate(e1, e2, dm1, negate);
            }
            else if (dm2 != null)
            {
                return MakePredicate(e1, e2, dm2, negate);
            }

            throw new InvalidOperationException("Cannot compare two constructed types with different sets of members assigned.");
        }
开发者ID:lepigocher,项目名称:iqtoolkit-oracle,代码行数:45,代码来源:ComparisonRewriter.cs

示例12: Equals

        public bool Equals(AlternationRegExp alternationRegExp)
        {
            if (!base.Equals(alternationRegExp)) return false;

            if (alternationRegExp.ChildExpressions.Length != ChildExpressions.Length) return false;

            // The easiest way to check whether two arrays has same regular axpressions is to construct HaashSets and check
            // if the sets are equal. Remember, the order is not important!

            var hashSetForThis = new HashSet<RegExp>(ChildExpressions);
            var hashSetForOther = new HashSet<RegExp>(alternationRegExp.ChildExpressions);

            if (hashSetForOther.IsSubsetOf(hashSetForThis) && hashSetForThis.IsSubsetOf(hashSetForOther))
            {
                return true;
            }

            return false;
        }
开发者ID:onirtuen,项目名称:scopus,代码行数:19,代码来源:AlternationRegExp.cs

示例13: Cozy

        public static void Cozy()
        {
            Console.WriteLine("\n-----------------------------------------------");
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
            Console.WriteLine("-----------------------------------------------");

            //HashSet<T>和List<T>差不多的,但HashSet<T>只能包含不重复的元素
            var hashSet = new HashSet<int>();

            //Add()会返回一个bool值,添加成功返回true,集合内有相同的元素,则添加失败返回false
            Console.WriteLine(hashSet.Add(1));     //output True
            Console.WriteLine(hashSet.Add(1));     //output False

            Console.WriteLine(hashSet.Add(2));
            Console.WriteLine(hashSet.Add(3));

            var array = new[] {1, 2, 3, 4, 5};


            Console.WriteLine(hashSet.IsSubsetOf(array));       //output True
            Console.WriteLine(hashSet.IsSupersetOf(array));     //output False

            //增加array集合的元素
            hashSet.UnionWith(array);

            foreach (var i in hashSet)
            {
                Console.WriteLine(i);
            }

            //移除array集合的元素
            hashSet.ExceptWith(array);

            foreach (var i in hashSet)
            {
                Console.WriteLine(i);
            }
        }
开发者ID:xxy1991,项目名称:cozy,代码行数:38,代码来源:I8Set.cs

示例14: ShouldContain

		protected void ShouldContain(ISet<ISet<Fault>> sets, params Fault[] faults)
		{
			foreach (var set in sets)
			{
				var faultSet = new HashSet<Fault>(faults);

				if (set.IsSubsetOf(faultSet) && faultSet.IsSubsetOf(set))
					return;
			}

			throw new TestException("Fault set is not contained in set.");
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:12,代码来源:AnalysisTests.Helpers.cs

示例15: Compare

        protected Expression Compare(BinaryExpression bop)
        {
            var e1 = this.SkipConvert(bop.Left);
            var e2 = this.SkipConvert(bop.Right);

            OuterJoinedExpression oj1 = e1 as OuterJoinedExpression;
            OuterJoinedExpression oj2 = e2 as OuterJoinedExpression;

            EntityExpression entity1 = oj1 != null ? oj1.Expression as EntityExpression : e1 as EntityExpression;
            EntityExpression entity2 = oj2 != null ? oj2.Expression as EntityExpression : e2 as EntityExpression;

            bool negate = bop.NodeType == ExpressionType.NotEqual;

            // check for outer-joined entity comparing against null. These are special because outer joins have
            // a test expression specifically desgined to be tested against null to determine if the joined side exists.
            if (oj1 != null && e2.NodeType == ExpressionType.Constant && ((ConstantExpression)e2).Value == null)
            {
                return MakeIsNull(oj1.Test, negate);
            }
            else if (oj2 != null && e1.NodeType == ExpressionType.Constant && ((ConstantExpression)e1).Value == null)
            {
                return MakeIsNull(oj2.Test, negate);
            }

            // if either side is an entity construction expression then compare using its primary key members
            if (entity1 != null)
            {
                return this.MakePredicate(e1, e2, this.mapping.GetPrimaryKeyMembers(entity1.Entity), negate);
            }
            else if (entity2 != null)
            {
                return this.MakePredicate(e1, e2, this.mapping.GetPrimaryKeyMembers(entity2.Entity), negate);
            }

            // check for comparison of user constructed type projections
            var dm1 = this.GetDefinedMembers(e1);
            var dm2 = this.GetDefinedMembers(e2);

            if (dm1 == null && dm2 == null)
            {
                // neither are constructed types
                return bop;
            }

            if (dm1 != null && dm2 != null)
            {
                // both are constructed types, so they'd better have the same members declared
                HashSet<string> names1 = new HashSet<string>(dm1.Select(m => m.Name));
                HashSet<string> names2 = new HashSet<string>(dm2.Select(m => m.Name));
                if (names1.IsSubsetOf(names2) && names2.IsSubsetOf(names1))
                {
                    return MakePredicate(e1, e2, dm1, negate);
                }
            }
            else if (dm1 != null)
            {
                return MakePredicate(e1, e2, dm1, negate);
            }
            else if (dm2 != null)
            {
                return MakePredicate(e1, e2, dm2, negate);
            }

            throw new InvalidOperationException("Cannot compare two constructed types with different sets of members assigned.");
        }
开发者ID:rdrawsky,项目名称:iqtoolkit,代码行数:65,代码来源:ComparisonRewriter.cs


注:本文中的HashSet.IsSubsetOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。