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


C# Type.GetElementType方法代码示例

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


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

示例1: CodeTypeReference

		public CodeTypeReference (Type baseType)
		{
#if NET_2_0
			if (baseType == null) {
				throw new ArgumentNullException ("baseType");
			}

			if (baseType.IsGenericParameter) {
				this.baseType = baseType.Name;
				this.referenceOptions = CodeTypeReferenceOptions.GenericTypeParameter;
			}
			else if (baseType.IsGenericTypeDefinition)
				this.baseType = baseType.FullName;
			else if (baseType.IsGenericType) {
				this.baseType = baseType.GetGenericTypeDefinition ().FullName;
				foreach (Type arg in baseType.GetGenericArguments ()) {
					if (arg.IsGenericParameter)
						TypeArguments.Add (new CodeTypeReference (new CodeTypeParameter (arg.Name)));
					else
						TypeArguments.Add (new CodeTypeReference (arg));
				}
			}
			else
#endif
			if (baseType.IsArray) {
				this.arrayRank = baseType.GetArrayRank ();
				this.arrayElementType = new CodeTypeReference (baseType.GetElementType ());
				this.baseType = arrayElementType.BaseType;
			} else {
				Parse (baseType.FullName);
			}
			this.isInterface = baseType.IsInterface;
		}
开发者ID:runefs,项目名称:Marvin,代码行数:33,代码来源:CodeTypeReference.cs

示例2: SharpKitTypeName

    public static string SharpKitTypeName(Type type)
    {
        string name = string.Empty;
        if (type.IsByRef)
        {
            name = SharpKitTypeName(type.GetElementType());
        }
        else if (type.IsArray)
        {
            while (type.IsArray)
            {
                Type subt = type.GetElementType();
                name += SharpKitTypeName(subt) + '$';
                type = subt;
            }
            name += "Array";
        }
        else if (type.IsGenericType)
        {
            name = type.Name;
            Type[] ts = type.GetGenericArguments();
            for (int i = 0; i < ts.Length; i++)
            {
                name += "$" + SharpKitTypeName(ts[i]);
            }
        }
        else
        {
            name = type.Name;
        }
        return name;

    }
开发者ID:benbon,项目名称:qjsbunitynew,代码行数:33,代码来源:CSGenerator.cs

示例3: SharpKitTypeName

    public static string SharpKitTypeName(Type type)
    {
        if (type == null)
            return "";
        string name = string.Empty;
        if (type.IsByRef)
        {
            name = SharpKitTypeName(type.GetElementType());
        }
        else if (type.IsArray)
        {
            while (type.IsArray)
            {
                Type subt = type.GetElementType();
                name += SharpKitTypeName(subt) + '$';
                type = subt;
            }
            name += "Array";
        }
        else if (type.IsGenericTypeDefinition)
        {
            // never come here
            name = type.Name;
        }
        else if (type.IsGenericType)
        {
            name = type.Name;
            Type[] ts = type.GetGenericArguments();

            bool hasGenericParameter = false;
            for (int i = 0; i < ts.Length; i++)
            {
                if (ts[i].IsGenericParameter)
                {
                    hasGenericParameter = true;
                    break;
                }
            }

            if (!hasGenericParameter)
            {
                for (int i = 0; i < ts.Length; i++)
                {
                    name += "$" + SharpKitTypeName(ts[i]);
                }
            }
        }
        else
        {
            name = type.Name;
        }
        return name;

    }
开发者ID:benbon,项目名称:qjsbunitynew,代码行数:54,代码来源:JSGenerator.cs

示例4: AreAssignable

 //CONFORMING
 internal static bool AreAssignable(Type dest, Type src) {
     if (dest == src) {
         return true;
     }
     if (dest.IsAssignableFrom(src)) {
         return true;
     }
     if (dest.IsArray && src.IsArray && dest.GetArrayRank() == src.GetArrayRank() && AreReferenceAssignable(dest.GetElementType(), src.GetElementType())) {
         return true;
     }
     if (src.IsArray && dest.IsGenericType &&
         (dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IEnumerable<>)
         || dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IList<>)
         || dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.ICollection<>))
         && dest.GetGenericArguments()[0] == src.GetElementType()) {
         return true;
     }
     return false;
 }
开发者ID:joshholmes,项目名称:ironruby,代码行数:20,代码来源:TypeUtils.cs

示例5: CreateObject

		public ScriptObject CreateObject (Type type, object obj = null)
		{
			if (obj == null) {
				return ManagedObject.GetManagedObject (Activator.CreateInstance (type));
			}

			if (obj is double || obj is int) {
				int size = int.Parse (obj.ToString());
				Type t = type.GetElementType ();
				if (t == null)
					return null;
				return ManagedObject.GetManagedObject (Array.CreateInstance (t, size));
			}
			return ManagedObject.GetManagedObject (JsonDeserialize (obj, type));
		}
开发者ID:dfr0,项目名称:moon,代码行数:15,代码来源:HostServices.cs

示例6: GetBinder

        public override IModelBinder GetBinder(HttpConfiguration configuration, Type modelType)
        {
            if (modelType == null)
            {
                throw Error.ArgumentNull("modelType");
            }

            if (!modelType.IsArray)
            {
                return null;
            }

            Type elementType = modelType.GetElementType();
            return (IModelBinder)Activator.CreateInstance(typeof(ArrayModelBinder<>).MakeGenericType(elementType));
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:15,代码来源:ArrayModelBinderProvider.cs

示例7: UnwrapPossibleArrayType

        private static object UnwrapPossibleArrayType(object value, Type destinationType, CultureInfo culture)
        {
            if (value == null || destinationType.IsInstanceOfType(value))
            {
                return value;
            }

            // array conversion results in four cases, as below
            Array valueAsArray = value as Array;
            if (destinationType.IsArray)
            {
                Type destinationElementType = destinationType.GetElementType();
                if (valueAsArray != null)
                {
                    // case 1: both destination + source type are arrays, so convert each element
                    IList converted = Array.CreateInstance(destinationElementType, valueAsArray.Length);
                    for (int i = 0; i < valueAsArray.Length; i++)
                    {
                        converted[i] = ConvertSimpleType(valueAsArray.GetValue(i), destinationElementType, culture);
                    }
                    return converted;
                }
                else
                {
                    // case 2: destination type is array but source is single element, so wrap element in array + convert
                    object element = ConvertSimpleType(value, destinationElementType, culture);
                    IList converted = Array.CreateInstance(destinationElementType, 1);
                    converted[0] = element;
                    return converted;
                }
            }
            else if (valueAsArray != null)
            {
                // case 3: destination type is single element but source is array, so extract first element + convert
                if (valueAsArray.Length > 0)
                {
                    value = valueAsArray.GetValue(0);
                    return ConvertSimpleType(value, destinationType, culture);
                }
                else
                {
                    // case 3(a): source is empty array, so can't perform conversion
                    return null;
                }
            }
            // case 4: both destination + source type are single elements, so convert
            return ConvertSimpleType(value, destinationType, culture);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:48,代码来源:HtmlHelper.Internal.cs

示例8: CodeTypeReference

	public CodeTypeReference(Type type)
			{
				if(!(type.IsArray))
				{
					baseType = type.FullName;
					arrayElementType = null;
					arrayRank = 0;
				}
				else
				{
					baseType = null;
					arrayElementType =
						new CodeTypeReference(type.GetElementType());
					arrayRank = type.GetArrayRank();
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:16,代码来源:CodeTypeReference.cs

示例9: GetItemType

 Type GetItemType(Type type)
 {
     if (type.IsArray)
     {
         if (type.GetArrayRank() != 1)
         {
             throw new NotSupportedException("Multi-dimension arrays are supported");
         }
         Type itemType = type.GetElementType();
         if (itemType == typeof(byte))
         {
             return null;    // byte[] 不作为数组处理
         }
         else
         {
             return itemType;
         }
     }
     return TypeModel.GetListItemType(RuntimeTypeModel.Default, type); ;
 }
开发者ID:wpszz,项目名称:CSLightForUnity,代码行数:20,代码来源:CSLightMng_ProtoBuf.cs

示例10: GetInnerMostElementType

        /// <summary>
        /// Returns the innermost element type for a given type, dealing with
        /// nullables, arrays, etc.
        /// </summary>
        /// <param name="type">The type from which to get the innermost type.</param>
        /// <returns>The innermost element type</returns>
        internal static Type GetInnerMostElementType(Type type)
        {
            Contract.Assert(type != null);

            while (true)
            {
                Type nullableUnderlyingType = Nullable.GetUnderlyingType(type);
                if (nullableUnderlyingType != null)
                {
                    type = nullableUnderlyingType;
                }
                else if (type.HasElementType)
                {
                    type = type.GetElementType();
                }
                else
                {
                    return type;
                }
            }
        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:27,代码来源:TypeHelper.cs

示例11: CodeTypeReference

        public CodeTypeReference(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (type.IsArray)
            {
                ArrayRank = type.GetArrayRank();
                ArrayElementType = new CodeTypeReference(type.GetElementType());
                _baseType = null;
            }
            else
            {
                InitializeFromType(type);
                ArrayRank = 0;
                ArrayElementType = null;
            }

            _isInterface = type.IsInterface;
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:22,代码来源:CodeTypeReference.cs

示例12: FetchActiveRecord

        public object FetchActiveRecord(Type paramType, string paramName,
            HttpRequestBase request,
            IDictionary<string, object> customActionParameters)
        {
            bool isArray = paramType.IsArray;

            if (isArray)
                paramType = paramType.GetElementType();

            ActiveRecordModel model = ActiveRecordModel.GetModel(paramType);

            if (model == null) {
                throw new ApplicationException(String.Format("'{0}' is not an ActiveRecord " +
                                                             "class. It could not be bound to an [ARFetch] attribute.", paramType.Name));
            }

            if (model.CompositeKey != null) {
                throw new ApplicationException("ARFetch only supports single-attribute primary keys");
            }

            String webParamName = attr.RequestParameterName ?? paramName;

            if (!isArray) {
                string value = GetParameterValue(webParamName, customActionParameters, request);
                return LoadActiveRecord(paramType, value, model);
            }

            object[] pks = GetParameterValues(webParamName, customActionParameters, request);

            Array objs = Array.CreateInstance(paramType, pks.Length);

            for (int i = 0; i < objs.Length; i++) {
                objs.SetValue(LoadActiveRecord(paramType, pks[i], model), i);
            }

            return objs;
        }
开发者ID:ruanzx,项目名称:mausch,代码行数:37,代码来源:ARFetcher.cs

示例13: ValueAs

		private object ValueAs (string text, Type type, IXmlNamespaceResolver resolver, bool isArrayItem)
		{
			try {
				if (type == typeof (object))
					return text;
				if (type.IsArray && !isArrayItem) {
					var elemType = type.GetElementType ();
					var sarr = text.Split ((string []) null, StringSplitOptions.RemoveEmptyEntries);
					var ret = Array.CreateInstance (elemType, sarr.Length);
					for (int i = 0; i < ret.Length; i++)
						ret.SetValue (ValueAs (sarr [i], elemType, resolver, true), i);
					return ret;
				}

				if (type == typeof (XmlQualifiedName)) {
					if (resolver != null)
						return XmlQualifiedName.Parse (text, resolver, true);
					else
						return XmlQualifiedName.Parse (text, this, true);
				}
				if (type == typeof (Uri))
					return XmlConvert.ToUri (text);
				if (type == typeof (TimeSpan))
					return XmlConvert.ToTimeSpan (text);
				if (type == typeof (DateTimeOffset))
					return XmlConvert.ToDateTimeOffset (text);

				switch (Type.GetTypeCode (type)) {
				case TypeCode.Boolean:
					return XQueryConvert.StringToBoolean (text);
				case TypeCode.DateTime:
					return XQueryConvert.StringToDateTime (text);
				case TypeCode.Decimal:
					return XQueryConvert.StringToDecimal (text);
				case TypeCode.Double:
					return XQueryConvert.StringToDouble (text);
				case TypeCode.Int32:
					return XQueryConvert.StringToInt (text);
				case TypeCode.Int64:
					return XQueryConvert.StringToInteger (text);
				case TypeCode.Single:
					return XQueryConvert.StringToFloat (text);
				case TypeCode.String:
					return text;
				}
			} catch (Exception ex) {
				throw XmlError (String.Format ("Current text value '{0}' is not acceptable for specified type '{1}'. {2}", text, type, ex != null ? ex.Message : String.Empty), ex);
			}
			throw new ArgumentException (String.Format ("Specified type '{0}' is not supported.", type));
		}
开发者ID:carrie901,项目名称:mono,代码行数:50,代码来源:XmlReader.cs

示例14: GetClrTypeFullNameForArray

 private static string GetClrTypeFullNameForArray(Type type)
 {
     int rank = type.GetArrayRank();
     Debug.Assert(rank >= 1);
     string typeName = GetClrTypeFullName(type.GetElementType());
     return rank == 1 ?
         typeName + "[]" :
         typeName + "[" + new string(',', rank - 1) + "]";
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:9,代码来源:FormatterServices.cs

示例15: GetTypeStr

    //获取类型名字
    public static string GetTypeStr(Type t)
    {
        //if (t.Namespace != null && t.Namespace != string.Empty)
        //{
        //    usingList.Add(t.Namespace);
        //}

        if (t.IsArray)
        {
            t = t.GetElementType();
            string str = GetTypeStr(t);
            str += "[]";
            return str;
        }
        else if(t.IsGenericType)
        {
            return GetGenericName(t);
        }
        else
        {
            return _C(t.ToString());
        }
    }
开发者ID:amadabarney,项目名称:Bead,代码行数:24,代码来源:ToLuaExport.cs


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