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


C# Type.Implements方法代码示例

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


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

示例1: IsCopyableCollectionType

 private static bool IsCopyableCollectionType(Type type)
 {
     return type.IsArray ||
            typeof(IList).IsAssignableFrom(type) ||
            type.Implements(typeof(IList<>)) ||
            typeof(IDictionary).IsAssignableFrom(type) ||
            type.Implements(typeof(IDictionary<,>)) ||
            type.Implements(typeof(ISet<>));
 }
开发者ID:JohanLarsson,项目名称:Gu.State,代码行数:9,代码来源:Copy.Collection.cs

示例2: GetConversionType

        public static BasicTypes GetConversionType(Type innType, Type outType)
        {
            if (innType.Implements<IDictionary>() && outType.Implements<IDictionary>())
                return BasicTypes.Dictionary;
            if (innType.Implements<IEnumerable>() && outType.Implements<IEnumerable>() && !innType.IsValueType())
                return BasicTypes.List;
            if (innType.IsValueType() && outType.IsValueType() || TypeExtensions.CanConvert(outType, innType))
                return BasicTypes.Convertable;
            return BasicTypes.ComplexType;

        }
开发者ID:JonasSyrstad,项目名称:Stardust,代码行数:11,代码来源:MapHelper.cs

示例3: ApplicationComponentDependencyAttribute

 public ApplicationComponentDependencyAttribute(Type dependency)
 {
     if (!dependency.Implements<IApplicationComponent>())
     {
         throw new InvalidOperationException("Application component dependency type must implement IApplicationComponent.");
     }
 }
开发者ID:PowerDMS,项目名称:NContext,代码行数:7,代码来源:ApplicationComponentDependencyAttribute.cs

示例4: Process

            public void Process(Type type, PluginGraph graph)
            {
                if (!IsConcrete(type)) return;

                if (type.Name.EndsWith("Actor") && type.Implements<AsyncHttpActor>())
                    graph.AddType(typeof(AsyncHttpActor), type);
            }
开发者ID:phatboyg,项目名称:Tosca,代码行数:7,代码来源:ActorBootstrapper.cs

示例5: EnsureType

        protected static void EnsureType(Type implementationType, Type serviceType, bool assertImplementation = true)
        {
            if (assertImplementation && (!implementationType.IsClass || implementationType.IsAbstract))
                throw new StyletIoCRegistrationException(String.Format("Type {0} is not a concrete class, and so can't be used to implemented service {1}", implementationType.GetDescription(), serviceType.GetDescription()));

            // Test this first, as it's a bit clearer than hitting 'type doesn't implement service'
            if (assertImplementation && implementationType.IsGenericTypeDefinition)
            {
                if (!serviceType.IsGenericTypeDefinition)
                    throw new StyletIoCRegistrationException(String.Format("You can't use an unbound generic type to implement anything that isn't an unbound generic service. Service: {0}, Type: {1}", serviceType.GetDescription(), implementationType.GetDescription()));

                // This restriction may change when I figure out how to pass down the correct type argument
                if (serviceType.GetTypeInfo().GenericTypeParameters.Length != implementationType.GetTypeInfo().GenericTypeParameters.Length)
                    throw new StyletIoCRegistrationException(String.Format("If you're registering an unbound generic type to an unbound generic service, both service and type must have the same number of type parameters. Service: {0}, Type: {1}", serviceType.GetDescription(), implementationType.GetDescription()));
            }
            else if (serviceType.IsGenericTypeDefinition)
            {
                if (implementationType.GetGenericArguments().Length > 0)
                    throw new StyletIoCRegistrationException(String.Format("You cannot bind the bound generic type {0} to the unbound generic service {1}", implementationType.GetDescription(), serviceType.GetDescription()));
                else
                    throw new StyletIoCRegistrationException(String.Format("You cannot bind the non-generic type {0} to the unbound generic service {1}", implementationType.GetDescription(), serviceType.GetDescription()));
            }

            if (!implementationType.Implements(serviceType))
                throw new StyletIoCRegistrationException(String.Format("Type {0} does not implement service {1}", implementationType.GetDescription(), serviceType.GetDescription()));
        }
开发者ID:modulexcite,项目名称:Stylet,代码行数:26,代码来源:BuilderBindingBase.cs

示例6: ErrorFilter

 public ErrorFilter(Type exceptionType, IStringMatcher messageMatcher = null, IStringMatcher sourceMatcher = null, bool recurseInnerExceptions=false)
     : base(messageMatcher,sourceMatcher)
 {
     if(exceptionType!=null && !exceptionType.Implements<Exception>()) throw new ArgumentException("The type must be an exception. It was: " + exceptionType, "exceptionType");
     _exceptionType = exceptionType;
     _recurseInnerExceptions = recurseInnerExceptions;
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:7,代码来源:ErrorFilter.cs

示例7: SpecificationAttribute

        public SpecificationAttribute(Type specificationType)
        {
            if (!specificationType.Implements(typeof (ISpecification)))
            {
                throw new ValidationException("You must provide a valid specification type.");
            }

            SpecificationType = specificationType as ISpecification;
        }
开发者ID:modulexcite,项目名称:graveyard,代码行数:9,代码来源:SpecificationAttribute.cs

示例8: Materialize

 public object Materialize(Type type)
 {
     if (type.Implements(typeof(IList<>)) == false) {
         throw new NotImplementedException("Collection that does not implement IList<T> are not implemented yet.");
     }
     var argumentType = type.GetGenericArguments()[0];
     var collection = (IList) Activator.CreateInstance(type);
     foreach (var jsonObject in _jsonObjects) {
         collection.Add(jsonObject.Materialize(argumentType));
     }
     return collection;
 }
开发者ID:pierregillon,项目名称:ConnectUs,代码行数:12,代码来源:JsonArray.cs

示例9: CheckRequiresReferenceHandling

        internal static TypeErrorsBuilder CheckRequiresReferenceHandling(
            this TypeErrorsBuilder typeErrors,
            Type type,
            MemberSettings settings,
            Func<Type, bool> requiresReferenceHandling)
        {
            if (settings.ReferenceHandling == ReferenceHandling.Throw)
            {
                if (typeof(IEnumerable).IsAssignableFrom(type))
                {
                    if (type.Implements(typeof(IDictionary<,>)))
                    {
                        var arguments = type.GetGenericArguments();
                        if (arguments.Length != 2 ||
                            requiresReferenceHandling(arguments[0]) ||
                            requiresReferenceHandling(arguments[1]))
                        {
                            typeErrors = typeErrors.CreateIfNull(type)
                                                   .Add(RequiresReferenceHandling.Enumerable);
                        }
                    }
                    else if (requiresReferenceHandling(type.GetItemType()))
                    {
                        typeErrors = typeErrors.CreateIfNull(type)
                                               .Add(RequiresReferenceHandling.Enumerable);
                    }
                }
                else if (type.IsKeyValuePair())
                {
                    var arguments = type.GetGenericArguments();
                    if (requiresReferenceHandling(arguments[0]) || requiresReferenceHandling(arguments[1]))
                    {
                        typeErrors = typeErrors.CreateIfNull(type)
                                               .Add(RequiresReferenceHandling.ComplexType);
                    }
                }
                else if (requiresReferenceHandling(type))
                {
                    typeErrors = typeErrors.CreateIfNull(type)
                                           .Add(RequiresReferenceHandling.ComplexType);
                }
            }

            return typeErrors;
        }
开发者ID:JohanLarsson,项目名称:Gu.State,代码行数:45,代码来源:ErrorBuilder.cs

示例10: CreateCommandParserFor

        /// <summary>
        /// Get the appropriate <see cref="ICommandParser"/> used by the <see cref="IEvent"/> of the passed type.
        /// </summary>
        /// <param name="type">Type of the <see cref="IEvent"/> to get the parser for.</param>
        /// <returns>
        /// <see cref="ICommandParser"/> for the <see cref="IEvent"/> of the passed type. 
        /// If the <see cref="IEvent"/> of the passed type dosen't provide a <see cref="ICommandParser"/> <c>null</c> is returned.
        /// </returns>
        public static ICommandParser CreateCommandParserFor(Type type)
        {
            if(type.Implements<IEvent>())
            {
                IEvent action = EventFactory.CreateEvent(type);

                UsedCommandParser usedCommandParser = action.GetAttribute<UsedCommandParser>();
                if(usedCommandParser != null)
                {
                    Type commandParserType = usedCommandParser.ParserType;
                    object instance = Activator.CreateInstance(commandParserType);

                    if (instance.Implements<ICommandParser>())
                    {
                        return (ICommandParser)instance;
                    }
                }
            }
            return null;
        }
开发者ID:haleox,项目名称:mortar,代码行数:28,代码来源:CommandParserFactory.cs

示例11: IsEquatableCore

        protected static bool IsEquatableCore(Type type)
        {
            if (type == null)
            {
                return false;
            }

            bool result;
            if (EquatableCheckedTypes.TryGetValue(type, out result))
            {
                return result;
            }

            if (type.IsNullable())
            {
                var underlyingType = Nullable.GetUnderlyingType(type);
                result = IsEquatableCore(underlyingType);
                EquatableCheckedTypes.TryAdd(type, result);
                return result;
            }

            if (type.IsEnum)
            {
                result = true;
            }
            else if (type.IsImmutableArray())
            {
                // special casing ImmutableArray due to weird equality
                // Implements IEquatable<ImmutableArray> but Equals does not compare elements.
                result = false;
            }
            else
            {
                result = type.Implements(typeof(IEquatable<>), type);
            }

            EquatableCheckedTypes.TryAdd(type, result);
            return result;
        }
开发者ID:JohanLarsson,项目名称:Gu.State,代码行数:39,代码来源:MemberSettings.IsEquatable.cs

示例12: resolveOperatorType

        protected override Type resolveOperatorType(Context ctx, Type leftType, Type rightType)
        {
            if (rightType == typeof(int))
            {
                // string repetition
                if (leftType == typeof(string))
                    return typeof(string);

                // array repetition
                if (leftType.IsArray)
                    return leftType;

                // typed sequence repetition
                var enumerable = leftType.ResolveImplementationOf(typeof(IEnumerable<>));
                if (enumerable != null)
                    return enumerable;

                // untyped sequence repetition
                if (leftType.Implements(typeof(IEnumerable), false))
                    return typeof(IEnumerable);
            }

            return null;
        }
开发者ID:menozz,项目名称:lens,代码行数:24,代码来源:MultiplyOperatorNode.cs

示例13: ToOrientValueString

        public static string ToOrientValueString(this object value, Type targetType = null)
        {
            if (targetType == null)
            {
                if (value == null)
                    targetType = typeof(object);
                else
                    targetType = value.GetType();
            }

            if (value == null && targetType == typeof(object))
                return "null";
            else if (targetType.IsEnum)
            {
                if (value == DBNull.Value) return "null";
                return ((int)value).ToString();
            }
            else if (targetType == typeof(string))
            {
                if (value == DBNull.Value) return "null";
                return string.Format("'{0}'", EscapeText((string)value));
            }
            else if (targetType == typeof(ulong))
            {
                if (value == DBNull.Value) return "null";
                throw new NotSupportedException("Unsigned Long Integer values are not supported.  Use either Decimal, Double or byte[] storage types.");
            }
            else if (targetType == typeof(DateTime))
            {
                if (value == DBNull.Value) return "null";
                var dateString = ((DateTime)value).Kind == DateTimeKind.Utc ?
                    ((DateTime)value).ToString("s").Replace('T', ' ')
                    : ((DateTime)value).ToUniversalTime().ToString("s").Replace('T', ' ');
                return string.Format("'{0}'", dateString);
            }
            else if (targetType.IsArray)
            {
                if (value == DBNull.Value) return "null";
                if (value == null)
                {
                    return "null";
                }
                else if(((Array)value).Rank == 1)
                {
                    if (((Array)value).GetType().GetElementType().IsValueType || ((Array)value).GetType().GetElementType() == typeof(string))
                    {
                        var converter = CreateByteConverter(((Array)value).GetType().GetElementType());
                        var count = ((Array)value).Length;
                        var type = GetElementType(((Array)value).GetType().GetElementType());
                        using (var stream = new MemoryStream())
                        {
                            stream.Write(BitConverter.GetBytes(count), 0, 4);
                            stream.Write(BitConverter.GetBytes(type), 0, 4); // this approach will only work for intrinsic value types
                            byte[] bytes;
                            foreach (var item in (Array)value)
                            {
                                bytes = converter(item);
                                stream.Write(bytes, 0, bytes.Length);
                            }
                            stream.Position = 0;
                            return string.Format("'{0}'", Convert.ToBase64String(stream.ToArray()));
                        }
                    }
                    else if (((Array)value).GetType().GetElementType().Implements<IIdentifiable>())
                    {
                        StringBuilder sb = new StringBuilder();
                        for (int i = 0; i < ((Array)value).Length; i++)
                        {
                            var item = ((Array)value).GetValue(i) as IIdentifiable;
                            if (item != null && !string.IsNullOrEmpty(item.Id))
                            {
                                if (sb.Length > 0)
                                    sb.Append(", ");
                                sb.Append(item.Id);
                            }
                        }
                        return sb.Length > 0 ? "[" + sb.ToString() + "]" : "null";
                    }
                }
            }
            else if (targetType == typeof(decimal))
            {
                if (value == DBNull.Value) return "null";
                var sValue = value.ToString();
                if (!sValue.Contains("."))
                    sValue += ".";
                return string.Format("'{0}'", sValue);
            }
            else if (targetType == typeof(double) || targetType == typeof(float))
            {
                if (value == DBNull.Value) return "null";
                return string.Format("'{0}'", value.ToString()); // wrapping in quotes allows orient to parse exponential number formats
            }
            else if (targetType.IsValueType)
            {
                if (value == DBNull.Value) return "null";
                return value.ToString();
            }
            else if (targetType.Implements<IIdentifiable>())
            {
//.........这里部分代码省略.........
开发者ID:PaybackMan,项目名称:Cinder,代码行数:101,代码来源:OQueryExpressionStringifier.cs

示例14: IsIEnumerableType

 public static bool IsIEnumerableType(Type type)
 {
     return type.Implements(typeof(IEnumerable)) && type.IsInterface;
 }
开发者ID:odinhaus,项目名称:Suffuz,代码行数:4,代码来源:IEnumerableSerializer.cs

示例15: GetCollectionTCountProperty

		private static PropertyInfo GetCollectionTCountProperty( Type targetType, Type elementType )
		{
			if ( !targetType.GetIsValueType() && targetType.Implements( typeof( ICollection<> ) ) )
			{
				return typeof( ICollection<> ).MakeGenericType( elementType ).GetProperty( "Count" );
			}

			var property = targetType.GetProperty( "Count" );
			if ( property != null && property.PropertyType == typeof( int ) && property.GetIndexParameters().Length == 0 )
			{
				return property;
			}

			return null;
		}
开发者ID:songotony,项目名称:RType-Client,代码行数:15,代码来源:ReflectionExtensions.cs


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