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


C# CodeExpression.GetType方法代码示例

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


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

示例1: EmitExpression

 void EmitExpression(CodeExpression expr)
 {
     if (expr is CodeMethodInvokeExpression)
         EmitInvoke((CodeMethodInvokeExpression)expr);
     else if (expr is CodeArrayCreateExpression)
         EmitArray((CodeArrayCreateExpression)expr);
     else if (expr is CodePrimitiveExpression)
         EmitPrimitive((CodePrimitiveExpression)expr);
     else if (expr is CodeBinaryOperatorExpression)
         EmitBinary((CodeBinaryOperatorExpression)expr);
     else if (expr is CodeTernaryOperatorExpression)
         EmitTernary((CodeTernaryOperatorExpression)expr);
     else if (expr is CodeVariableReferenceExpression)
         EmitVariableReference((CodeVariableReferenceExpression)expr);
     else if (expr is CodeArgumentReferenceExpression)
         EmitArgumentReference((CodeArgumentReferenceExpression)expr);
     else if (expr is CodeFieldReferenceExpression)
         EmitFieldReference((CodeFieldReferenceExpression)expr);
     else if (expr is CodeTypeReferenceExpression)
         EmitTypeReference((CodeTypeReferenceExpression)expr);
     else if (expr is CodeArrayIndexerExpression)
         EmitArrayIndexer((CodeArrayIndexerExpression)expr);
     else if (expr is CodePropertyReferenceExpression)
         EmitPropertyReference((CodePropertyReferenceExpression)expr);
     else
         throw new ArgumentException("Unrecognised expression: " + expr.GetType());
 }
开发者ID:BillTheBest,项目名称:IronAHK,代码行数:27,代码来源:Expression.cs

示例2: GetExpression

 public IExpression GetExpression(CodeExpression expression, CodeGeneratorOptions options)
 {
     if (expression==null)
     {
         throw new ArgumentNullException("expression");
     }
     return _expressionMap[expression.GetType()](expression, options);
 }
开发者ID:s2quake,项目名称:TypescriptCodeDom,代码行数:8,代码来源:ExpressionFactory.cs

示例3: Match

 public static bool Match(CodeExpression firstExpression, CodeExpression secondExpression)
 {
     if ((firstExpression == null) && (secondExpression == null))
     {
         return true;
     }
     if ((firstExpression == null) || (secondExpression == null))
     {
         return false;
     }
     if (firstExpression.GetType() != secondExpression.GetType())
     {
         return false;
     }
     return GetExpression(firstExpression).Match(firstExpression, secondExpression);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:16,代码来源:RuleExpressionWalker.cs

示例4: GetExpression

 private static RuleExpressionInternal GetExpression(CodeExpression expression)
 {
     Type type = expression.GetType();
     int length = typeWrappers.Length;
     for (int i = 0; i < length; i++)
     {
         TypeWrapperTuple tuple = typeWrappers[i];
         if (type == tuple.codeDomType)
         {
             return tuple.internalExpression;
         }
     }
     IRuleExpression ruleExpr = expression as IRuleExpression;
     if (ruleExpr != null)
     {
         return new CustomExpressionWrapper(ruleExpr);
     }
     return null;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:19,代码来源:RuleExpressionWalker.cs

示例5: GetCodeTypeReferenceInCodeExpression

        private CodeTypeReference GetCodeTypeReferenceInCodeExpression(CodeExpression expression)
        {
            if (typeof(CodeTypeOfExpression) == expression.GetType())
            {
                return ((CodeTypeOfExpression)expression).Type;
            }

            if (typeof(CodeTypeReferenceExpression) == expression.GetType())
            {
                return ((CodeTypeReferenceExpression)expression).Type;
            }

            if (typeof(CodeFieldReferenceExpression) == expression.GetType())
            {
                return GetCodeTypeReferenceInCodeExpression(((CodeFieldReferenceExpression)expression).TargetObject);
            }

            if (typeof(CodeObjectCreateExpression) == expression.GetType())
            {
                return ((CodeObjectCreateExpression)expression).CreateType;
            }

            if (typeof(CodeCastExpression) == expression.GetType())
            {
                return ((CodeCastExpression)expression).TargetType;
            }

            if (typeof(CodeMethodInvokeExpression) == expression.GetType())
            {
                return GetCodeTypeReferenceInCodeExpression(((CodeMethodInvokeExpression)expression).Method);
            }

            if (typeof(CodeMethodReferenceExpression) == expression.GetType())
            {
                return GetCodeTypeReferenceInCodeExpression(((CodeMethodReferenceExpression)expression).TargetObject);
            }

            return null;
        }
开发者ID:WSCF,项目名称:WSCF,代码行数:39,代码来源:CodeRefactoringAgent.cs

示例6: GetValue

		private static object GetValue (RuleExecution execution, CodeExpression obj)
		{
			if (obj.GetType () == typeof (System.CodeDom.CodePrimitiveExpression)) {
				return (((System.CodeDom.CodePrimitiveExpression) obj).Value);
			}

			if (obj.GetType () == typeof (CodeFieldReferenceExpression)) {
				return RuleExpressionCondition.CodeFieldReferenceValue (execution, obj);
			}

			if (obj.GetType () == typeof (CodePropertyReferenceExpression)) {
				return RuleExpressionCondition.CodePropertyReferenceValue (execution, obj);
			}

			return null;
		}
开发者ID:alesliehughes,项目名称:olive,代码行数:16,代码来源:RuleExpressionBinaryOperatorResolver.cs

示例7: GenerateExpression

 public void GenerateExpression(CodeExpression expression)
 {
     if (expression is CodeArrayIndexerExpression)
         GenerateArrayIndexerExpression((CodeArrayIndexerExpression)expression);
     else if (expression is CodeBinaryOperatorExpression)
         GenerateBinaryOperatorExpression((CodeBinaryOperatorExpression)expression);
     else if (expression is CodeCastExpression)
         GenerateCastExpression((CodeCastExpression)expression);
     else if (expression is CodeDelegateCreateExpression)
         GenerateDelegateCreateExpression((CodeDelegateCreateExpression)expression);
     else if (expression is CodeFieldReferenceExpression)
         GenerateFieldReferenceExpression((CodeFieldReferenceExpression)expression);
     else if (expression is CodeMethodInvokeExpression)
         GenerateMethodInvokeExpression((CodeMethodInvokeExpression)expression);
     else if (expression is CodeMethodReferenceExpression)
         GenerateMethodReferenceExpression((CodeMethodReferenceExpression)expression);
     else if (expression is CodeObjectCreateExpression)
         GenerateObjectCreateExpression((CodeObjectCreateExpression)expression);
     else if (expression is CodePrimitiveExpression)
         GeneratePrimitiveExpression((CodePrimitiveExpression)expression);
     else if (expression is CodePropertyReferenceExpression)
         GeneratePropertyReferenceExpression((CodePropertyReferenceExpression)expression);
     else if (expression is CodeThisReferenceExpression)
         GenerateThisReferenceExpression((CodeThisReferenceExpression)expression);
     else if (expression is CodeTypeOfExpression)
         GenerateTypeOfExpression((CodeTypeOfExpression)expression);
     else if (expression is CodeArrayCreateExpression)
         GenerateArrayCreateExpression((CodeArrayCreateExpression)expression);
     else if (expression is CodeTypeReferenceExpression)
         GenerateTypeReferenceExpression((CodeTypeReferenceExpression)expression);
     else
         throw new NotSupportedException(expression.GetType().ToString());
 }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:33,代码来源:RubyCodeGenerator.cs

示例8: FindTargetType

        /// <summary>
        /// Track down the real type of a CodeExpression's target.
        /// </summary>
        /// <param name="targetObject"></param>
        /// <param name="thisType"></param>
        /// <returns></returns>
        private static Type FindTargetType(CodeExpression targetObject, Type thisType)
        {
            Type targetType = GetType(targetObject, false);

            if (targetType != null)
            {
                return targetType;
            }
            else if (targetObject is CodeVariableReferenceExpression)
            {
                throw new ApplicationException("Cannot determine the type of a CodeVariableReferenceExpression: " + Serialize(targetObject));
            }
            else if (targetObject is CodeTypeOfExpression)
            {
                // Results in a System.Type.
                return typeof(Type);
            }
            else if (targetObject is CodeThisReferenceExpression)
            {
                if (thisType == null)
                {
                    throw new ApplicationException("There is a CodeThisReferenceExpression and the thisType supplied was null.");
                }

                return thisType;
            }
            else if (targetObject is CodePrimitiveExpression)
            {
                return ((CodePrimitiveExpression)targetObject).Value.GetType();
            }
            else if (targetObject is CodePropertyReferenceExpression)
            {
                Type toExamine = FindTargetType(((CodePropertyReferenceExpression)targetObject).TargetObject, thisType);
                PropertyInfo propInfo = toExamine.GetProperty(((CodePropertyReferenceExpression)targetObject).PropertyName);
                return propInfo.PropertyType;
            }
            else if (targetObject is CodeMethodInvokeExpression)
            {
                Type toExamine = FindTargetType(((CodeMethodInvokeExpression)targetObject).Method.TargetObject, thisType);
                MethodInfo methodInfo = toExamine.GetMethod(((CodeMethodInvokeExpression)targetObject).Method.MethodName);
                return methodInfo.ReturnType;
            }
            else if (targetObject is CodeFieldReferenceExpression)
            {
                Type toExamine = FindTargetType(((CodeFieldReferenceExpression)targetObject).TargetObject, thisType);
                String fieldName = ((CodeFieldReferenceExpression)targetObject).FieldName;
                FieldInfo fieldInfo = toExamine.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                return fieldInfo.FieldType;
            }
            else if (targetObject is CodeTypeReferenceExpression)
            {
                CodeTypeReference typeReference = ((CodeTypeReferenceExpression)targetObject).Type;
                return thisType.Assembly.GetType(typeReference.BaseType);
            }
            throw new NotSupportedException("Specified CodeExpression type is not currently supported: " + targetObject.GetType().FullName);
        }
开发者ID:ssickles,项目名称:archive,代码行数:62,代码来源:EvaluatorGenerator.cs

示例9: PrintExpression


//.........这里部分代码省略.........
                {
                    if (i > 0)
                        output.Write(", ");
                    PrintExpression(output, coce.Parameters[i]);

                }

                output.Write(')');
                return;
            }

            if (expression is CodeArrayIndexerExpression)
            {
                CodeArrayIndexerExpression caie = (CodeArrayIndexerExpression)expression;
                output.Write("arrayitem(");
                PrintExpression(output, caie.TargetObject);
                for (int i = 0; i < caie.Indices.Count; ++i)
                {
                    output.Write(", ");
                    PrintExpression(output, caie.Indices[i]);
                }
                output.Write(')');
                return;
            }

            if (expression is CodeArrayCreateExpression)
            {
                CodeArrayCreateExpression cace = (CodeArrayCreateExpression)expression;
                output.Write("newarray(");
                PrintTypeReference(output, cace.CreateType);
                output.Write(',');
                PrintExpression(output, cace.SizeExpression);
                output.Write(')');
                return;
            }

            if (expression is CodeBinaryOperatorExpression)
            {
                CodeBinaryOperatorExpression cboe = (CodeBinaryOperatorExpression)expression;
                switch (cboe.Operator)
                {
                    case CodeBinaryOperatorType.ValueEquality:
                        output.Write("equals");
                        break;

                    case CodeBinaryOperatorType.IdentityEquality:
                        output.Write("refequal");
                        break;

                    case CodeBinaryOperatorType.IdentityInequality:
                        output.Write("refnotequal");
                        break;

                    case CodeBinaryOperatorType.Add:
                        output.Write("add");
                        break;

                    default:
                        output.Write("UNKNOWN CBOE: {0}", cboe.Operator);
                        break;
                }
                output.Write('(');
                PrintExpression(output, cboe.Left);
                output.Write(", ");
                PrintExpression(output, cboe.Right);
                output.Write(')');
                return;
            }

            if (expression is CodePropertySetValueReferenceExpression)
            {
                output.Write("setvalue");
                return;
            }

            if (expression is CodeDirectionExpression)
            {
                switch (((CodeDirectionExpression)expression).Direction)
                {
                    case FieldDirection.In:
                        PrintExpression(output, ((CodeDirectionExpression)expression).Expression);
                        break;

                    case FieldDirection.Out:
                        output.Write("out(");
                        PrintExpression(output, ((CodeDirectionExpression)expression).Expression);
                        output.Write(')');
                        break;

                    case FieldDirection.Ref:
                        output.Write("ref(");
                        PrintExpression(output, ((CodeDirectionExpression)expression).Expression);
                        output.Write(')');
                        break;
                }
                return;
            }

            output.Write("*** UNKNOWN EXPRESSION:" + expression.GetType() + " ***");
        }
开发者ID:valery-shinkevich,项目名称:sooda,代码行数:101,代码来源:CDILPrettyPrinter.cs

示例10: GenerateExpression

 /// <devdoc>
 ///    <para>Generates code for the specified CodeDom code expression representation.</para>
 /// </devdoc>
 private void GenerateExpression(CodeExpression e) {
     if (e is CodeArrayCreateExpression) {
         GenerateArrayCreateExpression((CodeArrayCreateExpression)e);
     }
     else if (e is CodeBaseReferenceExpression) {
         GenerateBaseReferenceExpression((CodeBaseReferenceExpression)e);
     }
     else if (e is CodeBinaryOperatorExpression) {
         GenerateBinaryOperatorExpression((CodeBinaryOperatorExpression)e);
     }
     else if (e is CodeCastExpression) {
         GenerateCastExpression((CodeCastExpression)e);
     }
     else if (e is CodeDelegateCreateExpression) {
         GenerateDelegateCreateExpression((CodeDelegateCreateExpression)e);
     }
     else if (e is CodeFieldReferenceExpression) {
         GenerateFieldReferenceExpression((CodeFieldReferenceExpression)e);
     }
     else if (e is CodeArgumentReferenceExpression) {
         GenerateArgumentReferenceExpression((CodeArgumentReferenceExpression)e);
     }
     else if (e is CodeVariableReferenceExpression) {
         GenerateVariableReferenceExpression((CodeVariableReferenceExpression)e);
     }
     else if (e is CodeIndexerExpression) {
         GenerateIndexerExpression((CodeIndexerExpression)e);
     }
     else if (e is CodeArrayIndexerExpression) {
         GenerateArrayIndexerExpression((CodeArrayIndexerExpression)e);
     }
     else if (e is CodeSnippetExpression) {
         GenerateSnippetExpression((CodeSnippetExpression)e);
     }
     else if (e is CodeMethodInvokeExpression) {
         GenerateMethodInvokeExpression((CodeMethodInvokeExpression)e);
     }
     else if (e is CodeMethodReferenceExpression) {
         GenerateMethodReferenceExpression((CodeMethodReferenceExpression)e);
     }
     else if (e is CodeEventReferenceExpression) {
         GenerateEventReferenceExpression((CodeEventReferenceExpression)e);
     }
     else if (e is CodeDelegateInvokeExpression) {
         GenerateDelegateInvokeExpression((CodeDelegateInvokeExpression)e);
     }
     else if (e is CodeObjectCreateExpression) {
         GenerateObjectCreateExpression((CodeObjectCreateExpression)e);
     }
     else if (e is CodeParameterDeclarationExpression) {
         GenerateParameterDeclarationExpression((CodeParameterDeclarationExpression)e);
     }
     else if (e is CodeDirectionExpression) {
         GenerateDirectionExpression((CodeDirectionExpression)e);
     }
     else if (e is CodePrimitiveExpression) {
         GeneratePrimitiveExpression((CodePrimitiveExpression)e);
     }
     else if (e is CodePropertyReferenceExpression) {
         GeneratePropertyReferenceExpression((CodePropertyReferenceExpression)e);
     }
     else if (e is CodePropertySetValueReferenceExpression) {
         GeneratePropertySetValueReferenceExpression((CodePropertySetValueReferenceExpression)e);
     }
     else if (e is CodeThisReferenceExpression) {
         GenerateThisReferenceExpression((CodeThisReferenceExpression)e);
     }
     else if (e is CodeTypeReferenceExpression) {
         GenerateTypeReferenceExpression((CodeTypeReferenceExpression)e);
     }
     else if (e is CodeTypeOfExpression) {
         GenerateTypeOfExpression((CodeTypeOfExpression)e);
     }
     else if (e is CodeDefaultValueExpression) {
         GenerateDefaultValueExpression((CodeDefaultValueExpression)e);
     }
     else {
         if (e == null) {
             throw new ArgumentNullException("e");
         }
         else {
             throw new ArgumentException(SR.GetString(SR.InvalidElementType, e.GetType().FullName), "e");
         }
     }
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:88,代码来源:csharpcodeprovider.cs

示例11: Validate

 public static RuleExpressionInfo Validate(RuleValidation validation, CodeExpression expression, bool isWritten)
 {
     if (validation == null)
     {
         throw new ArgumentNullException("validation");
     }
     RuleExpressionInfo info = null;
     if (!isWritten)
     {
         info = validation.ExpressionInfo(expression);
     }
     if (info != null)
     {
         return info;
     }
     RuleExpressionInternal ruleExpr = GetExpression(expression);
     if (ruleExpr == null)
     {
         ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, new object[] { expression.GetType().FullName }), 0x548);
         item.UserData["ErrorObject"] = expression;
         if (validation.Errors == null)
         {
             string name = string.Empty;
             if ((validation.ThisType != null) && (validation.ThisType.Name != null))
             {
                 name = validation.ThisType.Name;
             }
             throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ErrorsCollectionMissing, new object[] { name }));
         }
         validation.Errors.Add(item);
         return null;
     }
     return validation.ValidateSubexpression(expression, ruleExpr, isWritten);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:34,代码来源:RuleExpressionWalker.cs

示例12: MatchArgument

        private object MatchArgument(Type parameterType, CodeExpression arg)
        {
            Type argExprType = arg.GetType();

            if (TypeProvider.IsAssignable(parameterType, argExprType))
            {
                // The argument expression type is assignable to the parameter type,
                // so it goes through unscathed.
                return arg;
            }
            else
            {
                // See if the argument is a constant value, whose type is compatible with
                // the parameter.
                CodePrimitiveExpression argPrimitive = arg as CodePrimitiveExpression;
                if (argPrimitive != null)
                {
                    ValidationError error = null;
                    Type argPrimitiveType = validation.ExpressionInfo(argPrimitive).ExpressionType;
                    if (RuleValidation.TypesAreAssignable(argPrimitiveType, parameterType, argPrimitive, out error))
                    {
                        // The constant expression's type matched the parameter, so
                        // use the actual primitive's value as the argument.
                        return argPrimitive.Value;
                    }
                }
            }

            return null;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:30,代码来源:Parser.cs

示例13: TryGetCachedExpression

		private CodeExpression TryGetCachedExpression (IDesignerSerializationManager manager, object value, 
													   CodeExpression parentExpression, object presetValue)
		{
			CodeExpression expression = null;
			if (value != null) // in order to support null value serialization
				expression = base.GetExpression (manager, value);
			if (expression == null) {
				if (parentExpression == null)
					manager.Context.Push (new ExpressionContext (null, null, value, presetValue));
				else
					manager.Context.Push (new ExpressionContext (parentExpression, parentExpression.GetType (), value, presetValue));
				expression = base.SerializeToExpression (manager, value);
				manager.Context.Pop ();
			}
			return expression;
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:16,代码来源:PropertyCodeDomSerializer.cs

示例14: Translate

 private Expression Translate(CodeExpression expr){
   if (expr == null) return null;
   if (expr is CodeArgumentReferenceExpression) return this.Translate((CodeArgumentReferenceExpression)expr);
   if (expr is CodeArrayCreateExpression) return this.Translate((CodeArrayCreateExpression)expr);
   if (expr is CodeArrayIndexerExpression) return this.Translate((CodeArrayIndexerExpression)expr);
   if (expr is CodeBaseReferenceExpression) return this.Translate((CodeBaseReferenceExpression)expr);
   if (expr is CodeBinaryOperatorExpression) return this.Translate((CodeBinaryOperatorExpression)expr);
   if (expr is CodeCastExpression) return this.Translate((CodeCastExpression)expr);
   if (expr is CodeDelegateCreateExpression) return this.Translate((CodeDelegateCreateExpression)expr);
   if (expr is CodeDelegateInvokeExpression) return this.Translate((CodeDelegateInvokeExpression)expr);
   if (expr is CodeDirectionExpression) return this.Translate((CodeDirectionExpression)expr);
   if (expr is CodeEventReferenceExpression) return this.Translate((CodeEventReferenceExpression)expr);
   if (expr is CodeFieldReferenceExpression) return this.Translate((CodeFieldReferenceExpression)expr);
   if (expr is CodeIndexerExpression) return this.Translate((CodeIndexerExpression)expr);
   if (expr is CodeMethodInvokeExpression) return this.Translate((CodeMethodInvokeExpression)expr);
   if (expr is CodeMethodReferenceExpression) return this.Translate((CodeMethodReferenceExpression)expr);
   if (expr is CodeObjectCreateExpression) return this.Translate((CodeObjectCreateExpression)expr);
   if (expr is CodePrimitiveExpression) return this.Translate((CodePrimitiveExpression)expr);
   if (expr is CodePropertyReferenceExpression) return this.Translate((CodePropertyReferenceExpression)expr);
   if (expr is CodePropertySetValueReferenceExpression) return this.Translate((CodePropertySetValueReferenceExpression)expr);
   if (expr is CodeSnippetExpression) return this.Translate((CodeSnippetExpression)expr);
   if (expr is CodeThisReferenceExpression) return this.Translate((CodeThisReferenceExpression)expr);
   if (expr is CodeTypeOfExpression) return this.Translate((CodeTypeOfExpression)expr);
   if (expr is CodeTypeReferenceExpression) return this.Translate((CodeTypeReferenceExpression)expr);
   if (expr is CodeVariableReferenceExpression) return this.Translate((CodeVariableReferenceExpression)expr);
   Debug.Assert(false);
   this.HandleError(Error.DidNotExpect, expr.GetType().FullName);
   return null;
 }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:29,代码来源:CodeDom.cs

示例15: GetPrecedence

        private static Operation GetPrecedence(CodeExpression expression)
        {
            // Assume the operation needs no parentheses.
            Operation operation = Operation.NoParentheses;

            ComputePrecedence computePrecedence;
            if (precedenceMap.TryGetValue(expression.GetType(), out computePrecedence))
                operation = computePrecedence(expression);

            return operation;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:11,代码来源:CodeDomDecompiler.cs


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