/// <summary> /// This constructor creates a type from a ITypeName. /// </summary> public PSTypeName(ITypeName typeName) { if (typeName == null) { throw PSTraceSource.NewArgumentNullException("typeName"); } _type = typeName.GetReflectionType(); if (_type != null) { Name = _type.FullName; } else { var t = typeName as TypeName; if (t != null && t._typeDefinitionAst != null) { TypeDefinitionAst = t._typeDefinitionAst; Name = TypeDefinitionAst.Name; } else { _type = null; Name = typeName.FullName; } } }
internal static Type ResolveTypeName(ITypeName typeName) { Type reflectionType = typeName.GetReflectionType(); if (reflectionType != null) { return(reflectionType); } GenericTypeName name = typeName as GenericTypeName; if (name != null) { Type genericType = name.GetGenericType(ResolveTypeName(name.TypeName)); Type[] typeArguments = (from arg in name.GenericArguments select ResolveTypeName(arg)).ToArray <Type>(); try { if ((genericType != null) && genericType.ContainsGenericParameters) { genericType.MakeGenericType(typeArguments); } } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); throw InterpreterError.NewInterpreterException(typeName, typeof(RuntimeException), null, "TypeNotFoundWithMessage", ParserStrings.TypeNotFoundWithMessage, new object[] { typeName.FullName, exception.Message }); } } ArrayTypeName name2 = typeName as ArrayTypeName; if (name2 != null) { ResolveTypeName(name2.ElementType); } throw InterpreterError.NewInterpreterException(typeName, typeof(RuntimeException), null, "TypeNotFound", ParserStrings.TypeNotFound, new object[] { typeName.FullName }); }
internal static Type ResolveTypeName(ITypeName typeName) { Type reflectionType = typeName.GetReflectionType(); if (reflectionType != null) { return reflectionType; } GenericTypeName name = typeName as GenericTypeName; if (name != null) { Type genericType = name.GetGenericType(ResolveTypeName(name.TypeName)); Type[] typeArguments = (from arg in name.GenericArguments select ResolveTypeName(arg)).ToArray<Type>(); try { if ((genericType != null) && genericType.ContainsGenericParameters) { genericType.MakeGenericType(typeArguments); } } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); throw InterpreterError.NewInterpreterException(typeName, typeof(RuntimeException), null, "TypeNotFoundWithMessage", ParserStrings.TypeNotFoundWithMessage, new object[] { typeName.FullName, exception.Message }); } } ArrayTypeName name2 = typeName as ArrayTypeName; if (name2 != null) { ResolveTypeName(name2.ElementType); } throw InterpreterError.NewInterpreterException(typeName, typeof(RuntimeException), null, "TypeNotFound", ParserStrings.TypeNotFound, new object[] { typeName.FullName }); }
private void CheckTypeName(Ast ast, ITypeName typename) { Type reflectionType = typename.GetReflectionType(); if ((reflectionType == null) || (Type.GetTypeCode(reflectionType.IsArray ? reflectionType.GetElementType() : reflectionType) == TypeCode.Object)) { this.ReportError(ast, () => ParserStrings.TypeNotAllowedInDataSection, new object[] { typename.FullName }); } }
internal static Type ResolveITypeName(ITypeName iTypeName, out Exception exception) { exception = null; var typeName = iTypeName as TypeName; if (typeName == null) { // The type is something more complicated - generic or array. try { return(iTypeName.GetReflectionType()); } catch (Exception e) { exception = e; return(null); } } return(ResolveTypeName(typeName, out exception)); }
internal Expression CompileTypeName(ITypeName typeName, IScriptExtent errorPos) { Type type; try { // If creating the type throws an exception, just defer that error until runtime. type = typeName.GetReflectionType(); } catch (Exception e) { CommandProcessorBase.CheckForSevereException(e); type = null; } if (type != null) { return Expression.Constant(type, typeof(Type)); } return Expression.Call(CachedReflectionInfo.TypeOps_ResolveTypeName, Expression.Constant(typeName), Expression.Constant(errorPos)); }
private void CheckTypeName(Ast ast, ITypeName typename) { Type type = typename.GetReflectionType(); // Only allow simple types of arrays of simple types as defined by System.Typecode // The permitted types are: Empty, Object, DBNull, Boolean, Char, SByte, Byte, // Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double, Decimal, DateTime, String // We reject anything with a typecode or element typecode of object... // If we couldn't resolve the type, then it's definitely an error. if (type == null || ((type.IsArray ? type.GetElementType() : type).GetTypeCode() == TypeCode.Object)) { ReportError(ast, () => ParserStrings.TypeNotAllowedInDataSection, typename.FullName); } }
internal static Expression ConvertValue(ITypeName typeName, Expression expr) { Type reflectionType = typeName.GetReflectionType(); if (reflectionType == null) { return Expression.Dynamic(PSDynamicConvertBinder.Get(), typeof(object), Expression.Call(CachedReflectionInfo.TypeOps_ResolveTypeName, Expression.Constant(typeName)), expr); } if (reflectionType.Equals(typeof(void))) { return Expression.Block(typeof(void), new Expression[] { expr }); } return expr.Convert(reflectionType); }
internal Expression CompileTypeName(ITypeName typeName) { Type reflectionType; try { reflectionType = typeName.GetReflectionType(); } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); reflectionType = null; } if (reflectionType != null) { return Expression.Constant(reflectionType); } return Expression.Call(CachedReflectionInfo.TypeOps_ResolveTypeName, Expression.Constant(typeName)); }