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


C# Type.Any方法代码示例

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


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

示例1: GetConstructor

 public static ConstructorInfo GetConstructor(this Type sourceType, Type[] types) {
     if(sourceType == null)
         throw new ArgumentException("sourceType");
     if (types == null || types.Any(t => t == null))
         throw new ArgumentNullException("types");
     return sourceType.GetTypeInfo().DeclaredConstructors.Where(ci => CheckParametersTypes(ci.GetParameters(), types)).FirstOrDefault();
 }
开发者ID:LINDAIS,项目名称:DevExpress.Mvvm.Free,代码行数:7,代码来源:TypeExtenstions.cs

示例2: MapConventionsForAssemblies

        public static Assembly[] MapConventionsForAssemblies(Type[] viewAssemblyRootAnchors, Type[] viewModelAssemblyRootAnchors)
        {
            if (viewAssemblyRootAnchors == null) throw new ArgumentNullException("viewAssemblyRootAnchors");
            if (viewAssemblyRootAnchors.Any(type => type == null))
                throw new ArgumentException("viewAssemblyRootAnchors contains null elements");
            if (viewModelAssemblyRootAnchors == null) throw new ArgumentNullException("viewModelAssemblyRootAnchors");
            if (viewModelAssemblyRootAnchors.Any(type => type == null))
                throw new ArgumentException("viewModelAssemblyRootAnchors contains null elements");

            foreach (var viewAssemblyRootAnchor in viewAssemblyRootAnchors)
            {
                foreach (var viewModelAssemblyRootAnchor in viewModelAssemblyRootAnchors)
                {
                    //{
                    //    var vmNs = viewModelAssemblyRootAnchor.Namespace + ".ViewModels";
                    //    var vNs = viewAssemblyRootAnchor.Namespace + ".Views";
                    //    ViewLocator.AddNamespaceMapping(vmNs, vNs);
                    //    ViewModelLocator.AddNamespaceMapping(vNs, vmNs);
                    //}

                    {
                        var vmNs = viewModelAssemblyRootAnchor.Namespace + ".ViewModels";
                        var vNs = viewAssemblyRootAnchor.Namespace + ".Views";
                        ViewLocator.AddSubNamespaceMapping(vmNs, vNs);
                        ViewModelLocator.AddSubNamespaceMapping(vNs, vmNs);
                    }
                }
            }

            return
                viewAssemblyRootAnchors.Concat(viewModelAssemblyRootAnchors)
                                       .Select(type => type.Assembly)
                                       .Distinct()
                                       .ToArray();
        }
开发者ID:imtheman,项目名称:WurmAssistant3,代码行数:35,代码来源:CaliburnConventionsHelper.cs

示例3: Close

 // this has been through red and green phase, it has yet to see it's refactor phase
 public Type Close(Type conversionPatternType, Type sourceType, Type targetType)
 {
     var @interface = conversionPatternType.GetInterface(typeof (IConversionPattern<,>));
     if (@interface == null)
     {
         throw new ArgumentException(string.Format("Type {0} doesn't implement {1} and therefore is invalid for this operation.", conversionPatternType, typeof (IConversionPattern<,>)));
     }
     var arguments = @interface.GetGenericArguments();
     var interfaceSourceType = arguments[0];
     var interfaceTargetType = arguments[1];
     if (conversionPatternType.IsGenericType == false)
     {
         if (sourceType.Is(interfaceSourceType) && targetType.Is(interfaceTargetType))
         {
             return conversionPatternType;
         }
         return null;
     }
     var openClassArguments = conversionPatternType.GetGenericArguments();
     var parameters = new Type[openClassArguments.Length];
     if (TryAddParameters(sourceType, interfaceSourceType, parameters, openClassArguments) == false)
     {
         return null;
     }
     if (TryAddParameters(targetType, interfaceTargetType, parameters, openClassArguments) == false)
     {
         return null;
     }
     if (parameters.Any(p => p == null))
     {
         return null;
     }
     return conversionPatternType.MakeGenericType(parameters);
 }
开发者ID:kkozmic,项目名称:Cartographer,代码行数:35,代码来源:ConversionPatternGenericCloser.cs

示例4: VerifyClassHasNotBeenPassedAsAnAdditionalInterface

 private void VerifyClassHasNotBeenPassedAsAnAdditionalInterface(Type[] additionalInterfaces)
 {
     if (additionalInterfaces != null && additionalInterfaces.Any(x => x.IsClass))
     {
         throw new SubstituteException("Can not substitute for multiple classes. To substitute for multiple types only one type can be a concrete class; other types can only be interfaces.");
     }
 }
开发者ID:rodrigoelp,项目名称:NSubstitute,代码行数:7,代码来源:CastleDynamicProxyFactory.cs

示例5: HasType

 /*********
 ** Protected methods
 *********/
 /// <summary>Get whether the value implements an expected type.</summary>
 /// <param name="value">The value to check.</param>
 /// <param name="types">The expected types that the value must implement.</param>
 protected bool HasType(object value, Type[] types)
 {
     if (value == null)
         return true; // type is irrelevant in this case
     Type actualType = value.GetType();
     return types.Any(type => type.IsAssignableFrom(actualType));
 }
开发者ID:Pathoschild,项目名称:DesignByContract,代码行数:13,代码来源:HasTypeAttribute.cs

示例6: IsGenericTypeOf

        public static bool IsGenericTypeOf(this Type t, Type genericDefinition, out Type[] genericParameters)
        {
            genericParameters = new Type[] { };
            if (!genericDefinition.IsGenericType) {
                return false;
            }

            var isMatch = t.IsGenericType && t.GetGenericTypeDefinition() == genericDefinition.GetGenericTypeDefinition();
            if (!isMatch && t.BaseType != null) {
                isMatch = IsGenericTypeOf(t.BaseType, genericDefinition, out genericParameters);
            }
            if (!isMatch && genericDefinition.IsInterface && t.GetInterfaces().Any()) {
                foreach (var i in t.GetInterfaces()) {
                    if (i.IsGenericTypeOf(genericDefinition, out genericParameters)) {
                        isMatch = true;
                        break;
                    }
                }
            }

            if (isMatch && !genericParameters.Any()) {
                genericParameters = t.GetGenericArguments();
            }
            return isMatch;
        }
开发者ID:kneeclass,项目名称:ElasticEPi,代码行数:25,代码来源:TypeExtensions.cs

示例7: GetHandlersForCommandTypes

 private static List<MethodCommandTypeTuple> GetHandlersForCommandTypes(Type type, Type[] commandTypes, MethodParameterInjector injector)
 {
     return type.GetMethods()
         .Select(m => new {Method = m, Params = m.GetParameters()})
         .Where(p => commandTypes.Any(ct => IsValidCommandHandler(ct, p.Method, p.Params, injector)))
         .Select(p => new MethodCommandTypeTuple { Method = p.Method, HandlerType = p.Method.DeclaringType, CommandType = FindCommandTypeInMethodParameters(commandTypes, p.Method)})
         .ToList();
 }
开发者ID:jamie-davis,项目名称:ConsoleTools,代码行数:8,代码来源:CommandHandlerLoader.cs

示例8: IsValidExcelDnaType

        // based on https://exceldna.codeplex.com/wikipage?title=Reference
        public static bool IsValidExcelDnaType(Type type)
        {
            var validTypes =
                new Type[] {typeof(String), typeof(DateTime), typeof(Double), typeof(Double[]), typeof(Double[,]),
                            typeof(Object), typeof(Object[]), typeof(Object[,]), typeof(Boolean), typeof(Int32),
                            typeof(Int16), typeof(UInt16), typeof(Decimal), typeof(Int64)};

            return validTypes.Any(t => type.Equals(t));
        }
开发者ID:Excel-DNA,项目名称:ExcelDnaDoc,代码行数:10,代码来源:ExcelDnaHelper.cs

示例9: IsAnyOf

        /// <summary>
        /// Checks if this exception's type is the same, or a sub-class, of any of the specified types.
        /// </summary>
        /// <param name="ex">This instance.</param>
        /// <param name="types">Types to be matched against.</param>
        /// <returns>Whether or not this exception matched any of the specified types.</returns>
        public static bool IsAnyOf(this Exception ex, Type[] types)
        {
            if (ex == null)
            {
                throw new ArgumentNullException("ex");
            }
            if (types == null)
            {
                throw new ArgumentNullException("types");
            }

            Type exceptionType = ex.GetType();
            return types.Any(type => type.IsAssignableFrom(exceptionType));
        }
开发者ID:CrossPoint,项目名称:elastic-db-tools,代码行数:20,代码来源:ExceptionExtensionMethods.cs

示例10: GeneratePublicApi

        public static string GeneratePublicApi(Assembly assemby, Type[] includeTypes = null, bool shouldIncludeAssemblyAttributes = true)
        {
            var assemblyResolver = new DefaultAssemblyResolver();
            var assemblyPath = assemby.Location;
            assemblyResolver.AddSearchDirectory(Path.GetDirectoryName(assemblyPath));

            var readSymbols = File.Exists(Path.ChangeExtension(assemblyPath, ".pdb"));
            var asm = AssemblyDefinition.ReadAssembly(assemblyPath, new ReaderParameters(ReadingMode.Deferred)
            {
                ReadSymbols = readSymbols,
                AssemblyResolver = assemblyResolver,
            });

            return CreatePublicApiForAssembly(asm, tr => includeTypes == null || includeTypes.Any(t => t.FullName == tr.FullName && t.Assembly.FullName == tr.Module.Assembly.FullName), shouldIncludeAssemblyAttributes);
        }
开发者ID:Particular,项目名称:NServiceBus,代码行数:15,代码来源:ApiGenerator.cs

示例11: Prepare

        /// <summary>
        /// Prepare the specified types.
        /// </summary>
        public static void Prepare(Type[] types)
        {
            if (!types.Any())
                return;
            if (types.Any(NothingToDo.With))
                throw new InvalidOperationException(
                    "Unable to make proxies for types: " +
                    string.Join(", ", types.Where(NothingToDo.With)));

            var unpreparedTypes = types
                .Where(t => !proxies.ContainsKey(t))
                .ToArray();
            var compiledAssembly = MakeAssembly(cu => {
                cu.ReferencedAssemblies.Add(ShieldedDll);
                foreach (var loc in unpreparedTypes.SelectMany(GetReferences).Distinct())
                    cu.ReferencedAssemblies.Add(loc);

                foreach (var t in unpreparedTypes)
                    PrepareType(t, cu);
            });
            foreach (var t in unpreparedTypes)
                proxies.TryAdd(t, compiledAssembly.GetType(
                    t.Namespace + "." + GetNameForDerivedClass(t)));
        }
开发者ID:jbakic,项目名称:Shielded,代码行数:27,代码来源:ProxyGen.cs

示例12: Create

		//public object Create(IDynamicProxy handler, Type objType, bool isObjInterface) {
		public object Create(IDynamicProxy handler, Type objType, Type[] aditionalInterfaces = null) {

			string typeName = objType.FullName + PROXY_SUFFIX;
			Type type = typeMap[typeName] as Type;

			// Verifica se o tipo já existe no cache de tipos criados dinamicamente. Caso não exista, cria a nova instancia e adiciona ao cache.
			if (type == null) {

				List<Type> interfacesToImplement = new List<Type>();

				// Verifica se foram especificadas interfaces adicionais.
				if (aditionalInterfaces != null && aditionalInterfaces.Any() == true) { interfacesToImplement.AddRange(aditionalInterfaces); }

				if (objType.IsInterface == true) {

					// Pega todas as interfaces que são herdadas.
					Type[] baseInterfaces = objType.GetInterfaces();

					if (baseInterfaces != null) {

						// Adiciona cada interface herdada na lista de interfaces a serem implementadas.
						for (int i = 0; i < baseInterfaces.Length; i++) {
							interfacesToImplement.Add(baseInterfaces[i]);
						}
					}

					interfacesToImplement.Add(objType);
				}
				else {
					interfacesToImplement.AddRange(objType.GetInterfaces());
				}

				// Verifica se foram encontradas interfaces a serem implementadas.
				if (interfacesToImplement == null || interfacesToImplement.Any() == false) {

					throw new ArgumentException(objType.FullName + " has no interfaces to implement", "objType");
				}

				type = CreateType(handler, interfacesToImplement.ToArray(), typeName);

				Type existingType = typeMap[typeName] as Type;
				if (existingType == null) { typeMap.Add(typeName, type); }
			}

			// Retorna uma nova instancia do tipo.
			return Activator.CreateInstance(type, new object[] { handler });
		}
开发者ID:stone-payments,项目名称:Dlp.Framework,代码行数:48,代码来源:ProxyFactory.cs

示例13: ValidateThatOnlyOneServiceIsPresent

        private static void ValidateThatOnlyOneServiceIsPresent(Type[] serviceTypes)
        {
            if (!serviceTypes.Any())
            {
                throw new TypeLoadException("Unable to locate any concrete implementations of IService");
            }

            if (serviceTypes.Count() != 1)
            {
                var services = new StringBuilder("Only one service is allowed per service host. The following services were detected:\n");

                foreach (var serviceType in serviceTypes)
                {
                    services.AppendLine(serviceType.FullName);
                }

                throw new InvalidOperationException(services.ToString());
            }
        }
开发者ID:kehinze,项目名称:Hermes,代码行数:19,代码来源:HostFactory.cs

示例14: AddAdvancedClassTypeConverters

        static void AddAdvancedClassTypeConverters()
        {
            // Add the types we want to have use the AdvancedClassTypeConverter. This is purely just for
            // a better PropertyGrid-based editing experience. Since it doesn't really matter if we add too many
            // types (since it is only really for the PropertyGrid), we just add EVERY table from the DbObjs.
            var filterCreator = new TypeFilterCreator
            {
                IsClass = true,
                IsAbstract = false,
                CustomFilter = (x => x.Name.EndsWith("Table") && (x.Namespace ?? string.Empty).Contains("DbObjs"))
            };
            var filter = filterCreator.GetFilter();

            var typesToAdd = TypeHelper.FindTypes(filter, null);
            AdvancedClassTypeConverter.AddTypes(typesToAdd.ToArray());

            // Also automatically add all the instantiable types that derive from some of our base classes
            var baseTypes = new Type[] { typeof(Entity), typeof(MapBase) };
            filterCreator = new TypeFilterCreator { IsClass = true, IsAbstract = false, CustomFilter = (x => baseTypes.Any(x.IsSubclassOf)) };
            filter = filterCreator.GetFilter();

            typesToAdd = TypeHelper.FindTypes(filter, null);
            AdvancedClassTypeConverter.AddTypes(typesToAdd.ToArray());

            // Manually add some other types we want to have use the AdvancedClassTypeConverter. Again, doesn't
            // really matter what you add here. In general, you should just add to this when you notice that
            // a PropertyGrid isn't using the AdvancedClassTypeConverter.
            AdvancedClassTypeConverter.AddTypes(typeof(MutablePair<ItemTemplateID, byte>),
                typeof(MutablePair<CharacterTemplateID, ushort>), typeof(EditorQuest), typeof(EditorAlliance), typeof(EditorShop),
                typeof(EditorCharacterTemplate));

            // Set the properties we want to force being readonly in the PropertyGrid
            AdvancedClassTypeConverter.SetForceReadOnlyProperties(typeof(CharacterTemplateTable), "ID");
            AdvancedClassTypeConverter.SetForceReadOnlyProperties(typeof(EditorCharacterTemplate), "ID");
            AdvancedClassTypeConverter.SetForceReadOnlyProperties(typeof(ItemTemplateTable), "ID");

#if !TOPDOWN
            // Set the UITypeEditor for specific properties on classes instead of every property with a certain type
            AdvancedClassTypeConverter.SetForceEditor(typeof(ItemTemplateTable),
                new KeyValuePair<string, UITypeEditor>("EquippedBody", new BodyPaperDollTypeEditor()));
#endif
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:42,代码来源:CustomUITypeEditors.cs

示例15: FindAvailableMethods

        public IEnumerable<MethodInfo> FindAvailableMethods(Type[] types)
        {
            if (!string.IsNullOrEmpty(TypeName))
            {
                types = types.Where(type => type.Name == TypeName).ToArray();

                if (!types.Any())
                {
                    var message = string.Format("No type named '{0}' could be found.", TypeName);
                    throw new InvalidOperationException(message);
                }
            }

            const BindingFlags bindingFlags =
                BindingFlags.Public |
                BindingFlags.Static |
                BindingFlags.Instance |
                BindingFlags.DeclaredOnly;

            return types.SelectMany(type => type.GetMethods(bindingFlags)
                .OrderByDescending(method => method.GetParameters().Length));
        }
开发者ID:spooky,项目名称:Gemini.CommandLine,代码行数:22,代码来源:Command.cs


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