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


C# Type.GetArrayRank方法代码示例

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


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

示例1: ArrayDescriptor

        public ArrayDescriptor(ITypeDescriptorFactory factory, Type type, bool emitDefaultValues, IMemberNamingConvention namingConvention)
            : base(factory, type, emitDefaultValues, namingConvention)
        {
            if (!type.IsArray) throw new ArgumentException(@"Expecting array type", nameof(type));

            if (type.GetArrayRank() != 1)
            {
                throw new ArgumentException("Cannot support dimension [{0}] for type [{1}]. Only supporting dimension of 1".ToFormat(type.GetArrayRank(), type.FullName));
            }

            ElementType = type.GetElementType();
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:12,代码来源:ArrayDescriptor.cs

示例2: ArrayDescriptor

        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectDescriptor" /> class.
        /// </summary>
        /// <param name="attributeRegistry">The attribute registry.</param>
        /// <param name="type">The type.</param>
        /// <exception cref="System.ArgumentException">Expecting arrat type;type</exception>
        public ArrayDescriptor(IAttributeRegistry attributeRegistry, Type type)
            : base(attributeRegistry, type, false)
        {
            if (!type.IsArray) throw new ArgumentException("Expecting array type", "type");

            if (type.GetArrayRank() != 1)
            {
                throw new ArgumentException("Cannot support dimension [{0}] for type [{1}]. Only supporting dimension of 1".DoFormat(type.GetArrayRank(), type.FullName));
            }

            elementType = type.GetElementType();
            listType = typeof(List<>).MakeGenericType(ElementType);
            toArrayMethod = listType.GetMethod("ToArray");
        }
开发者ID:vasily-kirichenko,项目名称:SharpYaml,代码行数:20,代码来源:ArrayDescriptor.cs

示例3: ArrayDescriptor

        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectDescriptor" /> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="type">The type.</param>
        /// <exception cref="System.ArgumentException">Expecting arrat type;type</exception>
        public ArrayDescriptor(ITypeDescriptorFactory factory, Type type)
            : base(factory, type)
        {
            if (!type.IsArray) throw new ArgumentException("Expecting array type", "type");

            if (type.GetArrayRank() != 1)
            {
                throw new ArgumentException("Cannot support dimension [{0}] for type [{1}]. Only supporting dimension of 1".ToFormat(type.GetArrayRank(), type.FullName));
            }

            Category = DescriptorCategory.Array;
            elementType = type.GetElementType();
            listType = typeof(List<>).MakeGenericType(ElementType);
            toArrayMethod = listType.GetMethod("ToArray");
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:21,代码来源:ArrayDescriptor.cs

示例4: ArrayTypeName

 static string ArrayTypeName(Type type)
 {
     if (!type.IsArray) return null;
     string basename = Get(type.GetElementType());
     string rankCommas = new string(',', type.GetArrayRank() - 1);
     return basename + "[" + rankCommas + "]";
 }
开发者ID:rameshbolla,项目名称:ExpressionToCode,代码行数:7,代码来源:CSharpFriendlyTypeName.cs

示例5: SetArrayDimensions

 void SetArrayDimensions(Type type)
 {
     if (type.IsArray && type != typeof(Array)) {
         SetArrayDimensions(type.GetElementType());
         arrays.Insert(0, type.GetArrayRank());
     }
 }
开发者ID:slluis,项目名称:monodevelop-prehistoric,代码行数:7,代码来源:ReflectionReturnType.cs

示例6: AddElementTypes

        internal static Type AddElementTypes(SerializationInfo info, Type type)
        {
            List<int> elementTypes = new List<int>();
            while(type.HasElementType)
            {
                if (type.IsSzArray)
                {
                    elementTypes.Add(SzArray);
                }
                else if (type.IsArray)
                {
                    elementTypes.Add(type.GetArrayRank());
                    elementTypes.Add(Array);
                }
                else if (type.IsPointer)
                {
                    elementTypes.Add(Pointer);
                }
                else if (type.IsByRef)
                {
                    elementTypes.Add(ByRef);
                }
                
                type = type.GetElementType();
            }

            info.AddValue("ElementTypes", elementTypes.ToArray(), typeof(int[]));

            return type;
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:30,代码来源:unityserializationholder.cs

示例7: Array_To_IList

		//
		// From a one-dimensional array-type S[] to System.Collections.IList<T> and base
		// interfaces of this interface, provided there is an implicit reference conversion
		// from S to T.
		//
		static bool Array_To_IList (Type array, Type list, bool isExplicit)
		{
			if ((array.GetArrayRank () != 1) || !TypeManager.IsGenericType (list))
				return false;

			Type gt = TypeManager.DropGenericTypeArguments (list);
			if ((gt != TypeManager.generic_ilist_type) &&
			    (gt != TypeManager.generic_icollection_type) &&
			    (gt != TypeManager.generic_ienumerable_type))
				return false;

			Type element_type = TypeManager.GetElementType (array);
			Type arg_type = TypeManager.TypeToCoreType (TypeManager.GetTypeArguments (list) [0]);

			if (element_type == arg_type)
				return true;

			if (isExplicit)
				return ExplicitReferenceConversionExists (element_type, arg_type);

			Type t = TypeManager.GetElementType (array);
			if (MyEmptyExpr == null)
				MyEmptyExpr = new EmptyExpression (t);
			else
				MyEmptyExpr.SetType (t);

			return ImplicitReferenceConversionExists (MyEmptyExpr, arg_type);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:33,代码来源:convert.cs

示例8: Aggregate

 /// <summary>
 /// Get a function that coerces a sequence of one type into another type.
 /// This is primarily used for aggregators stored in ProjectionExpression's, 
 /// which are used to represent the final transformation of the entire result set of a query.
 /// </summary>
 public static LambdaExpression Aggregate(Type expectedType, Type actualType)
 {
     Type actualElementType = actualType.GetSequenceElementType();
     
     if (!expectedType.IsAssignableFrom(actualType))
     {
         Type expectedElementType = expectedType.GetSequenceElementType();
         ParameterExpression p = Expression.Parameter(actualType, "p");
         Expression body = null;
         
         if (expectedType.IsAssignableFrom(actualElementType))
             body = Expression.Call(typeof(Enumerable), "SingleOrDefault", new Type[] { actualElementType }, p);                
         else if (expectedType.IsGenericType && expectedType.GetGenericTypeDefinition() == typeof(IQueryable<>))
             body = Expression.Call(typeof(Queryable), "AsQueryable", new Type[] { expectedElementType }, 
                 CoerceElement(expectedElementType, p));
         else if (expectedType.IsArray && expectedType.GetArrayRank() == 1)
             body = Expression.Call(typeof(Enumerable), "ToArray", new Type[] { expectedElementType }, 
                 CoerceElement(expectedElementType, p));
         else if (expectedType.IsAssignableFrom(typeof(List<>).MakeGenericType(actualElementType)))
             body = Expression.Call(typeof(Enumerable), "ToList", new Type[] { expectedElementType }, 
                 CoerceElement(expectedElementType, p));
         else
         {
             ConstructorInfo ci = expectedType.GetConstructor(new Type[] { actualType });
             if (ci != null)
                 body = Expression.New(ci, p);
         }
         
         if (body != null)
             return Expression.Lambda(body, p);
     }
     return null;
 }
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:38,代码来源:Aggregator.cs

示例9: CreateSpecialTypeDefOrNull

        TypeDef CreateSpecialTypeDefOrNull(Type type)
        {
            BuiltInTypeDef typeDef = null;

            if (typeof(IEnumerable).IsAssignableFrom(type))
            {
                if (type.IsArray && type.GetArrayRank() == 1)
                {
                    var elementType = type.GetElementType();

                    var typeDefOfContainedType = GetOrCreateTypeDef(new QualifiedClassName(elementType), elementType);

                    typeDef = new BuiltInTypeDef(type, "", string.Format("{0}[]", typeDefOfContainedType.FullyQualifiedTsTypeName));
                }
                else if (!type.IsGenericType)
                {
                    typeDef = new BuiltInTypeDef(type, "", "any[]");
                }
                else if (type.IsGenericType && type.GetGenericArguments().Length == 1)
                {
                    var elementType = type.GetGenericArguments()[0];

                    var typeDefOfContainedType = GetOrCreateTypeDef(new QualifiedClassName(elementType), elementType);

                    typeDef = new BuiltInTypeDef(type, "", string.Format("{0}[]", typeDefOfContainedType.FullyQualifiedTsTypeName));
                }
            }

            if (typeDef != null)
            {
                _types.Add(type, typeDef);
            }

            return typeDef;
        }
开发者ID:RichieYang,项目名称:Cirqus,代码行数:35,代码来源:ProxyGeneratorContext.cs

示例10: FormalTypeName

        public FormalTypeName(Type type)
        {
            if (type.IsArray)
            {
                _arrayRank = type.GetArrayRank();
                _arrayElementType = new FormalTypeName(type.GetElementType());
            }
            _isGenericTypeArg = type.IsGenericParameter;
            _isRef = !type.IsValueType;
            _isByRef = type.IsByRef;
            _name = type.Name;

            if (_isByRef && _name.EndsWith("&"))
                _name = _name.Remove(_name.Length - 1);
            _namespace = type.Namespace;
            if (type.IsNested && type.FullName != null)
            {
                _wrapperClass = new FormalTypeName(type.DeclaringType);
            }
            if (type.IsGenericType)
            {
                if (type.IsGenericTypeDefinition)
                {
                    ReadGenericDefinition(type);
                }
                else
                {
                    ReadGenericDefinition(type.GetGenericTypeDefinition());
                    var args = type.GetGenericArguments();
                    _genericInstance = new FormalTypeName[args.Length];
                    for (var i = 0; i < args.Length; i++)
                        _genericInstance[i] = new FormalTypeName(args[i]);
                }
            }
        }
开发者ID:Alxandr,项目名称:NuDoc,代码行数:35,代码来源:FormalTypeName.cs

示例11: AddElementTypes

 internal static Type AddElementTypes(SerializationInfo info, Type type)
 {
     List<int> list = new List<int>();
     while (type.HasElementType)
     {
         if (type.IsSzArray)
         {
             list.Add(3);
         }
         else if (type.IsArray)
         {
             list.Add(type.GetArrayRank());
             list.Add(2);
         }
         else if (type.IsPointer)
         {
             list.Add(1);
         }
         else if (type.IsByRef)
         {
             list.Add(4);
         }
         type = type.GetElementType();
     }
     info.AddValue("ElementTypes", list.ToArray(), typeof(int[]));
     return type;
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:27,代码来源:UnitySerializationHolder.cs

示例12: ReadJson

		/// <summary>
		/// Reads the JSON representation of the object.
		/// </summary>
		/// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader"/> to read from.</param>
		/// <param name="objectType">Type of the object.</param>
		/// <param name="existingValue">The existing value of object being read.</param>
		/// <param name="serializer">The calling serializer.</param>
		/// <returns>The object value.</returns>
		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			// Handle null values
			if (reader.TokenType == JsonToken.Null) return null;

			var arrayItemType = objectType.GetElementType();
			var arrayRank = objectType.GetArrayRank();

			// Retrieve all the values from the Json
			var arrayValues = ReadRank(reader, serializer);

			// Determine the lengths of all ranks for the array
			var rankLengthList = GetRankLengthList(arrayValues);

			// If empty values were found, make sure the ranks match in size
			for (var i = rankLengthList.Count; i < arrayRank; i++)
			{
				rankLengthList.Add(0);
			}

			var rankLengthArray = rankLengthList.ToArray();

			// Create the array that will hold the values
			var retVal = Array.CreateInstance(arrayItemType, rankLengthArray);

			// Make the assignments
			SetValues(retVal, rankLengthArray, new int[0], 0, arrayValues);

			return retVal;
		}
开发者ID:hibernating-rhinos,项目名称:Raven.Light,代码行数:38,代码来源:JsonMultiDimensionalArrayConverter.cs

示例13: ArrayDecorator

        public ArrayDecorator(IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, Type arrayType, bool overwriteList, bool supportNull)
            : base(tail)
        {
            Helpers.DebugAssert(arrayType != null, "arrayType should be non-null");
            Helpers.DebugAssert(arrayType.IsArray && arrayType.GetArrayRank() == 1, "should be single-dimension array; " + arrayType.FullName);
            this.itemType = arrayType.GetElementType();
#if NO_GENERICS
            Type underlyingItemType = itemType;
#else
            Type underlyingItemType = supportNull ? itemType : (Nullable.GetUnderlyingType(itemType) ?? itemType);
#endif

            Helpers.DebugAssert(underlyingItemType == Tail.ExpectedType, "invalid tail");
            Helpers.DebugAssert(Tail.ExpectedType != typeof(byte), "Should have used BlobSerializer");
            if ((writePacked || packedWireType != WireType.None) && fieldNumber <= 0) throw new ArgumentOutOfRangeException("fieldNumber");
            if (!ListDecorator.CanPack(packedWireType))
            {
                if (writePacked) throw new InvalidOperationException("Only simple data-types can use packed encoding");
                packedWireType = WireType.None;
            }       
            this.fieldNumber = fieldNumber;
            this.packedWireType = packedWireType;
            if (writePacked) options |= OPTIONS_WritePacked;
            if (overwriteList) options |= OPTIONS_OverwriteList;
            if (supportNull) options |= OPTIONS_SupportNull;
            this.arrayType = arrayType;
        }
开发者ID:Ribosome2,项目名称:protobuf-net-1,代码行数:27,代码来源:ArrayDecorator.cs

示例14: GetWriteJsonMethod

 internal static WriteJsonValue GetWriteJsonMethod(Type type)
 {
     var t = Reflection.GetJsonDataType (type);
     if (t == JsonDataType.Primitive) {
         return typeof (decimal).Equals (type) ? WriteDecimal
                 : typeof (byte).Equals (type) ? WriteByte
                 : typeof (sbyte).Equals (type) ? WriteSByte
                 : typeof (short).Equals (type) ? WriteInt16
                 : typeof (ushort).Equals (type) ? WriteUInt16
                 : typeof (uint).Equals (type) ? WriteUInt32
                 : typeof (ulong).Equals (type) ? WriteUInt64
                 : typeof (char).Equals (type) ? WriteChar
                 : (WriteJsonValue)WriteUnknown;
     }
     else if (t == JsonDataType.Undefined) {
         return type.IsSubclassOf (typeof (Array)) && type.GetArrayRank () > 1 ? WriteMultiDimensionalArray
             : type.IsSubclassOf (typeof (Array)) && typeof (byte[]).Equals (type) == false ? WriteArray
             : typeof (KeyValuePair<string,object>).Equals (type) ? WriteKeyObjectPair
             : typeof (KeyValuePair<string,string>).Equals (type) ? WriteKeyValuePair
             : (WriteJsonValue)WriteObject;
     }
     else {
         return _convertMethods[(int)t];
     }
 }
开发者ID:qyezzard,项目名称:PowerJSON,代码行数:25,代码来源:JsonSerializer.cs

示例15: AppendPrettyNameCore

        private static StringBuilder AppendPrettyNameCore(this StringBuilder name, Type type, PrettyNameContext context)
        {
            // Suffixes (array, ref, pointer)
            if (type.IsArray)
                return name
                    .AppendPrettyName(type.GetElementType(), context)
                    .Append('[')
                    .Append(',', type.GetArrayRank() - 1)
                    .Append(']');
            else if (type.IsByRef)
                return name
                    .AppendPrettyName(type.GetElementType(), context)
                    .Append('&');
            else if (type.IsPointer)
                return name
                    .AppendPrettyName(type.GetElementType(), context)
                    .Append('*');

            // Prefixes (nesting, namespace)
            if (type.IsNested)
                name.AppendPrettyNameCore(type.DeclaringType, context)
                    .Append('.');
            else if (context.IsQualified)
                name.Append(type.Namespace)
                    .Append('.');

            // Name and arguments
            if (type.IsGenericType)
                return name
                    .Append(type.Name.WithoutGenericSuffix())
                    .AppendPrettyArguments(type, context);
            else
                return name
                    .Append(type.Name);
        }
开发者ID:sharpjs,项目名称:Projector,代码行数:35,代码来源:TypePrettyName.cs


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