當前位置: 首頁>>代碼示例>>C#>>正文


C# Type.Contains方法代碼示例

本文整理匯總了C#中System.Type.Contains方法的典型用法代碼示例。如果您正苦於以下問題:C# Type.Contains方法的具體用法?C# Type.Contains怎麽用?C# Type.Contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Type的用法示例。


在下文中一共展示了Type.Contains方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: LoadMappingFrom

        public static HbmMapping LoadMappingFrom(params Assembly[] assemblies)
        {
            Require.NotNull(assemblies, "assemblies");

            var baseTypes = new Type[] {
                typeof(ClassMapping<>),
                typeof(JoinedSubclassMapping<>),
                typeof(UnionSubclassMapping<>),
                typeof(SubclassMapping<>)
            };

            var mapper = new ModelMapper();

            foreach (var asm in assemblies)
            {
                foreach (var type in asm.GetTypes())
                {
                    if (!type.IsClass || type.IsAbstract || type.IsInterface || !type.BaseType.IsGenericType) continue;

                    if (!baseTypes.Contains(type.BaseType.GetGenericTypeDefinition())) continue;

                    mapper.AddMapping(type);
                }
            }

            var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
            mapping.autoimport = false;

            return mapping;
        }
開發者ID:sigcms,項目名稱:Seeger,代碼行數:30,代碼來源:ByCodeMappingLoader.cs

示例2: CreateProxy

		/// <inheritdoc />
		public object CreateProxy (Type baseType, Type[] implementedInterfaces, object[] constructorArguments)
		{
			if (baseType.IsInterface) {
				// TODO: should Moq.Core do this work? It's the same for 
				// Castle and LinFu and presumably other (future?) libraries

				var fixedInterfaces = new Type[implementedInterfaces.Length + 1];
				fixedInterfaces[0] = baseType;
				implementedInterfaces.CopyTo (fixedInterfaces, 1);
				implementedInterfaces = fixedInterfaces;
				baseType = typeof (object);
			}

			if (!implementedInterfaces.Contains(typeof(IProxy))) {
				var fixedInterfaces = new Type[implementedInterfaces.Length + 1];
				fixedInterfaces[0] = typeof(IProxy);
				implementedInterfaces.CopyTo (fixedInterfaces, 1);
				implementedInterfaces = fixedInterfaces;
			}

			// TODO: the proxy factory should automatically detect requests to proxy 
			// delegates and generate an interface on the fly for them, without Moq 
			// having to know about it at all.

			return generator.CreateClassProxy (baseType, implementedInterfaces, proxyOptions, constructorArguments, new Interceptor ());
		}
開發者ID:moq,項目名稱:moq.proxy,代碼行數:27,代碼來源:ProxyFactory.cs

示例3: AllEntitiesInheritEntityBase

        public void AllEntitiesInheritEntityBase()
        {
            var failed = false;
            var exclusions = new Type[] { };
            foreach (var testType in TestTypes)
            {
                var types =
                    testType.Assembly.GetTypes().Where(t => t.Namespace.IfNullOrEmpty("").Contains(".Entities")).OrderBy(t => t.Name);
                foreach (var type in types)
                {
                    if (exclusions.Contains(type) || type.IsAbstract || type.IsSealed || type.IsEnum || type.Namespace.IfNullOrEmpty("").EndsWith("Entities.Components"))
                        continue;

                    if(typeof (EntityBase).IsAssignableFrom(type))
                    {
                        Debug.WriteLine("PASS | " + type.Name);
                        continue;
                    }

                    failed = true;
                    Debug.WriteLine("FAIL | " + type.Name);
                }
            }
            Assert.IsFalse(failed);
        }
開發者ID:GIEMedia,項目名稱:PCT,代碼行數:25,代碼來源:EntityRules.cs

示例4: OfType

        /// <summary>
        /// 
        /// </summary>
        /// <param name="attributes">The list of available attributes</param>
        /// <param name="container">This is the type of container we are searchig attributes for.</param>
        /// <returns>The attributes matching the <see cref="EdiStructureType"/></returns>
        public static IEnumerable<EdiAttribute> OfType(this IEnumerable<EdiAttribute> attributes, EdiStructureType container) {
            var typesToSearch = new Type[0];
            switch (container) {
                case EdiStructureType.None:
                case EdiStructureType.Interchange:
                    break;
                case EdiStructureType.Group:
                    typesToSearch = new [] { typeof(EdiGroupAttribute) };
                    break;
                case EdiStructureType.Message:
                    typesToSearch = new [] { typeof(EdiMessageAttribute) };
                    break;
                case EdiStructureType.SegmentGroup:
                    typesToSearch = new [] { typeof(EdiSegmentGroupAttribute) };
                    break;
                case EdiStructureType.Segment:
                    typesToSearch = new [] { typeof(EdiSegmentAttribute), typeof(EdiSegmentGroupAttribute) };
                    break;
                case EdiStructureType.Element:
                    typesToSearch = new [] { typeof(EdiElementAttribute) };
                    break;
                default:
                    break;
            }

            return null == typesToSearch ? Enumerable.Empty<EdiAttribute>() : attributes.Where(a => typesToSearch.Contains(a.GetType()));
        }
開發者ID:indice-co,項目名稱:EDI.Net,代碼行數:33,代碼來源:EdiExtensions.cs

示例5: HasSupportFor

 public bool HasSupportFor(Type[] scenarios)
 {
     if (IsTravis && scenarios.Contains(Type.Integration))
     {
         return false;
     }
     return true;
 }
開發者ID:kylelengling,項目名稱:recurly-client-net,代碼行數:8,代碼來源:TestEnvironment.cs

示例6: FindCommandTypeInMethodParameters

        private static Type FindCommandTypeInMethodParameters(Type[] commandTypes, MethodInfo handlerMethod)
        {
            var commandParam =
                handlerMethod.GetParameters().FirstOrDefault(p => commandTypes.Contains(p.ParameterType));
            if (commandParam != null)
                return commandParam.ParameterType;

            return null;
        }
開發者ID:jamie-davis,項目名稱:ConsoleTools,代碼行數:9,代碼來源:CommandHandlerLoader.cs

示例7: IsBetterChoice

        private bool IsBetterChoice(ConstructorInfo current, ConstructorInfo candidate, Type[] existingTypes)
        {
            if (current == null)
                return true;

            if (candidate.GetParameters()
                         .Where(x => !existingTypes.Contains(x.ParameterType))
                         .Any(x => x.ParameterType.IsSealed && !x.ParameterType.IsArray))
                return false;

            return current.GetParameters().Length < candidate.GetParameters().Length;
        }
開發者ID:BrainCrumbz,項目名稱:Moq.AutoMocker,代碼行數:12,代碼來源:ConstructorSelector.cs

示例8: Search

		/// <summary>
		/// Search an IQueryable's fields for the keywords (objects) - this does not iterate through levels of an object
		/// </summary>
		/// <param name="list_to_search">IQueryable to search</param>
		/// <param name="types_to_explore">array of types to search, others will be ignored</param>
		/// <param name="keywords">objects to search for</param>
		/// <returns>IQueryable of the inputed type filtered by the search specifications</returns>
		public static IQueryable Search( this IQueryable list_to_search, Type[] types_to_explore, object[] keywords )
		{
			list_to_search.NotNull();
			Dictionary<string, Type> dic = new Dictionary<string, Type>();
			foreach( var item in list_to_search.Take( 1 ) )
			{
				foreach( PropertyInfo pi in item.GetType().GetProperties() )
				{
					if( types_to_explore.Contains( pi.PropertyType ) )
					{
						dic.Add( pi.Name, pi.PropertyType );
					}
				}
			}
			return list_to_search.Search( dic, keywords );
		}
開發者ID:xiangyuan,項目名稱:Unreal4,代碼行數:23,代碼來源:iQueryableSearch.cs

示例9: Contains

        public static bool Contains(this Exception e, Type[] exceptionTypes)
        {
            bool result = false;

            while (e != null)
            {
                if (exceptionTypes.Contains(e.GetType()))
                {
                    result = true;
                    break;
                }
                e = e.InnerException;
            }

            return result;
        }
開發者ID:Ollienator,項目名稱:MPExtended,代碼行數:16,代碼來源:ExceptionExtensions.cs

示例10: AllEntitiesInitializeComponents

        public void AllEntitiesInitializeComponents()
        {
            var failed = false;
            var exclusions = new Type[] { };
            foreach (var testType in TestTypes)
            {
                var types =
                    testType.Assembly.GetTypes().Where(t => t.Namespace.IfNullOrEmpty("").Contains(".Entities")).OrderBy(t => t.Name);
                foreach (var type in types)
                {
                    if (exclusions.Contains(type) || type.IsAbstract || type.IsSealed || type.IsEnum || type.Namespace.IfNullOrEmpty("").EndsWith("Entities.Components"))
                        continue;

                    if (typeof(EntityBase).IsAssignableFrom(type))
                    {
                        var components = type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
                            .Where(t => t.PropertyType.Namespace.EndsWith("Entities.Components"));

                        if (components.Any())
                        {
                            var obj = Activator.CreateInstance(type);
                            foreach (var list in components)
                            {
                                var val = list.GetValue(obj, null);
                                if (val == null)
                                {
                                    Debug.WriteLine("FAIL | " + type.Name + "." + list.Name);
                                    failed = true;
                                }
                                else
                                    Debug.WriteLine("PASS | " + type.Name + "." + list.Name);
                            }
                        }
                    }
                }
            }
            Assert.IsFalse(failed);
        }
開發者ID:GIEMedia,項目名稱:PCT,代碼行數:38,代碼來源:EntityRules.cs

示例11: Run

        /*
         * output - a destination to write results out to. To write output
         * to the standard output, pass in System.Console.Out
         */
        public static void Run(TextWriter output, Result result)
        {
            Assert.Output = output;
              Suite suite = new Suite();
              Type[] entryAssemblyTypes = Assembly.GetEntryAssembly().GetTypes();
              Type[] forbiddenTypes = new Type[] {
            GetTypeFromAssemblyTypes(entryAssemblyTypes, "TestRunner")
              , GetTypeFromAssemblyTypes(entryAssemblyTypes, "WasRunObj")
              , GetTypeFromAssemblyTypes(entryAssemblyTypes, "WasRunSetUpFailed")
              };

              foreach (Type t in entryAssemblyTypes) {
            if (t.IsSubclassOf(typeof(TDDUnit.Case))
              && !forbiddenTypes.Contains(t)) {
              suite.Add(t);
            }
              }

              foreach (string test in suite.FailedTests(result)) {
            output.WriteLine("Failed: " + test);
              }
              output.WriteLine(result.Summary);
        }
開發者ID:yawaramin,項目名稱:TDDUnit,代碼行數:27,代碼來源:Runner.cs

示例12: ValidateNoDanglingAttributes

        public void ValidateNoDanglingAttributes()
        {
            // This list represents attributes that have been cleared to ship without deriving
            // from ArgMetadata.  This test is here to make sure that, by default, the attributes
            // in this project behave like most of the others.  That is, most attributes should
            // derive from ArgMetadata.
            var whitelist = new Type[]
            {
                typeof(ArgReviverAttribute),
            };

            var iArgMetadataSubInterfaces = typeof(Args).Assembly.GetTypes().Where(t =>
                t.IsInterface &&
                t.GetInterfaces().Contains(typeof(IArgMetadata))).ToList();

            // In general, attributes in this project should derive from ArgMetadata
            var danglingAttrs = typeof(Args).Assembly.GetTypes().Where(t =>
                t.IsSubclassOf(typeof(Attribute))   == true &&
                t.GetInterfaces().Contains(typeof(IArgMetadata)) == false &&
                whitelist.Contains(t) == false
            ).ToList();

            // In general, attibutes should use more specific IArgMetadata interfaces
            var danglingAttrs2 = typeof(Args).Assembly.GetTypes().Where(t =>
                t.GetInterfaces().Contains(typeof(Attribute)) == true &&
                (from i in t.GetInterfaces() where iArgMetadataSubInterfaces.Contains(i) select i).Count() == 0 &&
                whitelist.Contains(t) == false
            ).ToList();

            Assert.AreEqual(0, danglingAttrs.Count);
            Assert.AreEqual(0, danglingAttrs2.Count);
        }
開發者ID:Geraint87,項目名稱:PowerArgs,代碼行數:32,代碼來源:ModelTests.cs

示例13: TryGetGenericType

        private static bool TryGetGenericType(this Type type, Type[] acceptableTypes, out Type collectionOf)
        {
            if (!type.IsGenericType)
            {
                collectionOf = null;
                return false;
            }

            var genericType = type.GetGenericTypeDefinition();
            if (acceptableTypes.Contains(genericType))
            {
                collectionOf = type.GetGenericArguments()[0];
                return true;
            }

            collectionOf = null;
            return false;
        }
開發者ID:spelltwister,項目名稱:TypeWalker,代碼行數:18,代碼來源:TypeExtensions.cs

示例14: ConvertToCode

        /// <summary>
        /// Returns code to instantiate an equivalent instance of the given value
        /// </summary>
        /// <param name="value">value to instantiate</param>
        /// <returns>code to instantiate the value</returns>
        private string ConvertToCode(object value)
        {
            Globalization.CultureInfo realCulture = Globalization.CultureInfo.CurrentCulture;

            // null is easy
            //
            if (value == null)
                return "null";

            try
            { 
                System.Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.InvariantCulture;

                // switch based on the type
                Type type = value.GetType();
                Type[] simpleTypes = new Type[] { typeof(bool), typeof(int) };
                Type[] castTypes = new Type[] { typeof(byte), typeof(short), typeof(ushort), typeof(sbyte) };

                if (simpleTypes.Contains(type))
                    return value.ToString().ToLower();
                else if (castTypes.Contains(type))
                    return "(" + type.FullName + ")(" + value.ToString() + ")";
                else if (type == typeof(uint))
                    return value.ToString() + "U";
                else if (type == typeof(long))
                    return value.ToString() + "L";
                else if (type == typeof(ulong))
                    return value.ToString() + "UL";
                else if (type == typeof(decimal))
                    return value.ToString() + "M";
                else if (type == typeof(float))
                {
                    if (float.IsNegativeInfinity((float)value))
                        return "float.NegativeInfinity";
                    if (float.IsPositiveInfinity((float)value))
                        return "float.PositiveInfinity";
                    if (float.IsNaN((float)value))
                        return "float.NaN";
                    if ((float)value == float.MaxValue)
                        return "float.MaxValue";
                    if ((float)value == float.MinValue)
                        return "float.MinValue";
                    return value.ToString() + "f";
                }
                else if (type == typeof(double))
                {
                    if (double.IsNegativeInfinity((double)value))
                        return "double.NegativeInfinity";
                    if (double.IsPositiveInfinity((double)value))
                        return "double.PositiveInfinity";
                    if (double.IsNaN((double)value))
                        return "double.NaN";
                    if ((double)value == double.MaxValue)
                        return "double.MaxValue";
                    if ((double)value == double.MinValue)
                        return "double.MinValue";
                    return value.ToString() + "d";
                }
                else if (type == typeof(string))
                    return "\"" + value + "\"";
                else if (type == typeof(byte[]))
                    return "new byte[] { " + string.Join(", ", (value as byte[]).Select(b => b.ToString()).ToArray()) + "}";
                else if (type == typeof(Guid))
                    return "new Guid(\"" + value.ToString() + "\")";
                else if (type == typeof(DateTime))
                {
                    DateTime dt = (DateTime)value;
                    return "new DateTime(" + dt.Ticks + ", DateTimeKind." + dt.Kind.ToString() + ")";
                }
                else
                {
                    // may need to add more cases in the future, for now this is sufficient
                    throw new NotSupportedException();
                }
            }
            finally
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = realCulture;
            }
        }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:85,代碼來源:CodeGeneratingDataInserter.cs

示例15: IsAuthorizedCall

 /// <summary>
 /// Validates that the required ISteamAuthenticator object is attached to the client prior to initiating execution
 /// </summary>
 /// <param name="validAuthMethods">List of valid authenticators for API access.</param>
 /// <returns>Returns 'true' if the proper authenticator is attached. Throws <see cref="SteamAuthenticationException"/> otherwise.</returns>
 internal bool IsAuthorizedCall( Type[] validAuthMethods )
 {
     if( Authenticator == null || !validAuthMethods.Contains( Authenticator.GetType() ) )
         throw new SteamAuthenticationException( "API call has not been properly authenticated. Please ensure the proper ISteamAuthenticator object is added to the SteamClient (SteamClient.Authenticator)." );
     return true;
 }
開發者ID:chaoscode,項目名稱:SteamSharp,代碼行數:11,代碼來源:SteamClient.cs


注:本文中的System.Type.Contains方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。