System.Type.GetGenericTypeDefinition C# (CSharp) Method

GetGenericTypeDefinition() public method

Returns a T:System.Type object that represents a generic type definition from which the current generic type can be constructed.
The current type is not a generic type. That is, returns false. The invoked method is not supported in the base class. Derived classes must provide an implementation.
public GetGenericTypeDefinition ( ) : Type
return Type
        public virtual Type GetGenericTypeDefinition()
        {
            if (unconstructedType != null)
                return _GetTypeFromTypeFunc(unconstructedType);
            else
                throw new NotSupportedException("This operation is only valid on generic types");
        }

Usage Example

Ejemplo n.º 1
0
        public static Item Create(Type type)
        {
            if (type == typeof(string))
            {
                return new StringItem();
            }

            if (type == typeof(float))
            {
                return new FloatItem();
            }

            if (type == typeof(double))
            {
                return new DoubleItem();
            }
            else if (type.GetCustomAttributes(typeof(CubeHack.Data.EditorDataAttribute), false).Length != 0)
            {
                return new ObjectItem(type);
            }
            else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>) && type.GetGenericArguments()[0] == typeof(string))
            {
                return new DictionaryItem(type.GetGenericArguments()[1]);
            }
            else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
            {
                return new ListItem(type.GetGenericArguments()[0]);
            }
            else
            {
                throw new ArgumentException("type");
            }
        }
All Usage Examples Of System.Type::GetGenericTypeDefinition