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


C# CodeDom.CodeCastExpression类代码示例

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


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

示例1: CreateMethod

		CodeMemberMethod CreateMethod()
		{
			CodeMemberMethod method = new CodeMemberMethod();
			
			// BeginInit method call.
			CodeExpressionStatement statement = new CodeExpressionStatement();
			CodeMethodInvokeExpression methodInvoke = new CodeMethodInvokeExpression();
			statement.Expression = methodInvoke;
			
			CodeMethodReferenceExpression methodRef = new CodeMethodReferenceExpression();
			methodRef.MethodName = "BeginInit";
			
			CodeCastExpression cast = new CodeCastExpression();
			cast.TargetType = new CodeTypeReference();
			cast.TargetType.BaseType = "System.ComponentModel.ISupportInitialize";
			
			CodeFieldReferenceExpression fieldRef = new CodeFieldReferenceExpression();
			fieldRef.FieldName = "pictureBox1";
			fieldRef.TargetObject = new CodeThisReferenceExpression();
			cast.Expression = fieldRef;

			methodRef.TargetObject = cast;
			methodInvoke.Method = methodRef;

			method.Statements.Add(statement);
			return method;
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:27,代码来源:GeneratePictureBoxBeginInitTestFixture.cs

示例2: Constructor1

		public void Constructor1 ()
		{
			CodeTypeReference type1 = new CodeTypeReference ("mono1");
			CodeExpression expression1 = new CodeExpression ();

			CodeCastExpression cce = new CodeCastExpression (type1, expression1);
			Assert.IsNotNull (cce.Expression, "#1");
			Assert.AreSame (expression1, cce.Expression, "#2");
			Assert.IsNotNull (cce.TargetType, "#3");
			Assert.AreSame (type1, cce.TargetType, "#4");

			cce.Expression = null;
			Assert.IsNull (cce.Expression, "#5");

			CodeExpression expression2 = new CodeExpression ();
			cce.Expression = expression2;
			Assert.IsNotNull (cce.Expression, "#6");
			Assert.AreSame (expression2, cce.Expression, "#7");

			cce.TargetType = null;
			Assert.IsNotNull (cce.TargetType, "#8");
			Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#9");

			CodeTypeReference type2 = new CodeTypeReference ("mono2");
			cce.TargetType = type2;
			Assert.IsNotNull (cce.TargetType, "#10");
			Assert.AreSame (type2, cce.TargetType, "#11");

			cce = new CodeCastExpression ((CodeTypeReference) null, (CodeExpression) null);
			Assert.IsNull (cce.Expression, "#12");
			Assert.IsNotNull (cce.TargetType, "#13");
			Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#14");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:33,代码来源:CodeCastExpressionTest.cs

示例3: ConvertTo

        protected CodeExpression ConvertTo(string value, Type type)
        {
            var valueExpression = new CodePrimitiveExpression(value);

            var converter = TypeDescriptor.GetConverter(type);

            if (type == typeof(string) || type == typeof(object))
                return valueExpression;

            if (type == typeof(double))
                return new CodePrimitiveExpression(double.Parse(value, CultureInfo.InvariantCulture));

            if (type == typeof(BindingBase))
            {
                var bindingParser = new BindingParser(State);
                var bindingVariableName = bindingParser.Parse(value);
                return new CodeVariableReferenceExpression(bindingVariableName);
            }

            // there is no conversion availabe, the generated code won't compile, but there is nothing we can do about that
            if (converter == null)
                return valueExpression;

            var conversion = new CodeCastExpression(
                type.Name,
                new CodeMethodInvokeExpression(
                    new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("TypeDescriptor"), "GetConverter",
                                                   new CodeTypeOfExpression(type.Name)), "ConvertFromInvariantString",
                    new CodePrimitiveExpression(value)));

            return conversion;
        }
开发者ID:huinalam,项目名称:XAML-conversion,代码行数:32,代码来源:ParserBase.cs

示例4: GenerateCallStatementC2J

 private CodeStatement GenerateCallStatementC2J(GMethod method, CodeExpression invokeExpression)
 {
     CodeStatement call;
     if (method.IsConstructor || method.IsVoid)
     {
         call = new CodeExpressionStatement(invokeExpression);
     }
     else
     {
         if (method.ReturnType.IsPrimitive)
         {
             if (method.ReturnType.JVMSubst != null)
             {
                 invokeExpression = new CodeCastExpression(method.ReturnType.CLRReference, invokeExpression);
             }
             call = new CodeMethodReturnStatement(invokeExpression);
         }
         else
         {
             CodeMethodInvokeExpression conversionExpression = CreateConversionExpressionJ2CParam(method.ReturnType,
                                                                                             invokeExpression);
             call = new CodeMethodReturnStatement(conversionExpression);
         }
     }
     return call;
 }
开发者ID:Mazrick,项目名称:jni4net,代码行数:26,代码来源:CLRGenerator.C2J.cs

示例5: Constructor0_Deny_Unrestricted

		public void Constructor0_Deny_Unrestricted ()
		{
			CodeCastExpression cce = new CodeCastExpression ();
			Assert.IsNull (cce.Expression, "Expression");
			cce.Expression = new CodeExpression ();
			Assert.AreEqual ("System.Void", cce.TargetType.BaseType, "TargetType.BaseType");
			cce.TargetType = new CodeTypeReference ("System.Void");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:CodeCastExpressionCas.cs

示例6: Clone

 public static CodeCastExpression Clone(this CodeCastExpression expression)
 {
     if (expression == null) return null;
     CodeCastExpression e = new CodeCastExpression();
     e.Expression = expression.Expression.Clone();
     e.TargetType = expression.TargetType.Clone();
     e.UserData.AddRange(expression.UserData);
     return e;
 }
开发者ID:svejdo1,项目名称:CodeDomExtensions,代码行数:9,代码来源:CodeCastExpressionExtensions.cs

示例7: Constructor1_Deny_Unrestricted

		public void Constructor1_Deny_Unrestricted ()
		{
			CodeTypeReference target = new CodeTypeReference ("System.Int32");
			CodeExpression expression = new CodeExpression ();
			CodeCastExpression cce = new CodeCastExpression (target, expression);
			Assert.AreSame (expression, cce.Expression, "Expression");
			cce.Expression = new CodeExpression ();
			Assert.AreEqual ("System.Int32", cce.TargetType.BaseType, "TargetType.BaseType");
			cce.TargetType = new CodeTypeReference ("System.Void");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:10,代码来源:CodeCastExpressionCas.cs

示例8: TypescriptCastExpression

 public TypescriptCastExpression(
     IExpressionFactory expressionFactory,
     CodeCastExpression codeExpression, 
     CodeGeneratorOptions options,
     ITypescriptTypeMapper typescriptTypeMapper)
 {
     _expressionFactory = expressionFactory;
     _codeExpression = codeExpression;
     _options = options;
     _typescriptTypeMapper = typescriptTypeMapper;
     System.Diagnostics.Debug.WriteLine("TypescriptCastExpression Created");
 }
开发者ID:s2quake,项目名称:TypescriptCodeDom,代码行数:12,代码来源:TypescriptCastExpression.cs

示例9: Serialize

        public override object Serialize(IDesignerSerializationManager manager, object value)
        {

            CodeExpression expression = new CodePrimitiveExpression(value);

            if (value == null
                || value is bool
                || value is char
                || value is int
                || value is float
                || value is double)
            {

                // work aroundf for J#, since they don't support auto-boxing of value types yet.
                CodeDomProvider codeProvider = manager.GetService(typeof(CodeDomProvider)) as CodeDomProvider;
                if (codeProvider != null && String.Equals(codeProvider.FileExtension, JSharpFileExtension))
                {
                    // See if we are boxing - if so, insert a cast.
                    ExpressionContext cxt = manager.Context[typeof(ExpressionContext)] as ExpressionContext;
                    //Debug.Assert(cxt != null, "No expression context on stack - J# boxing cast will not be inserted");
                    if (cxt != null)
                    {
                        if (cxt.ExpressionType == typeof(object))
                        {
                            expression = new CodeCastExpression(value.GetType(), expression);
                            expression.UserData.Add("CastIsBoxing", true);
                        }
                    }
                }
                return expression;
            }

            String stringValue = value as string;
            if (stringValue != null)
            {
                // WinWS: The commented code breaks us when we have long strings
                //if (stringValue.Length > 200)
                //{
                // return SerializeToResourceExpression(manager, stringValue);
                //}
                //else 
                return expression;
            }

            // generate a cast for non-int types because we won't parse them properly otherwise because we won't know to convert
            // them to the narrow form.
            //
            return new CodeCastExpression(new CodeTypeReference(value.GetType()), expression);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:49,代码来源:PrimitiveCodeDomSerializer.cs

示例10: Serialize

 public override object Serialize(IDesignerSerializationManager manager, object value)
 {
     CodeExpression left = null;
     using (CodeDomSerializerBase.TraceScope("EnumCodeDomSerializer::Serialize"))
     {
         Enum[] enumArray;
         if (!(value is Enum))
         {
             return left;
         }
         bool flag = false;
         TypeConverter converter = TypeDescriptor.GetConverter(value);
         if ((converter != null) && converter.CanConvertTo(typeof(Enum[])))
         {
             enumArray = (Enum[]) converter.ConvertTo(value, typeof(Enum[]));
             flag = enumArray.Length > 1;
         }
         else
         {
             enumArray = new Enum[] { (Enum) value };
             flag = true;
         }
         CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression(value.GetType());
         TypeConverter converter2 = new EnumConverter(value.GetType());
         foreach (Enum enum2 in enumArray)
         {
             string str = (converter2 != null) ? converter2.ConvertToString(enum2) : null;
             CodeExpression right = !string.IsNullOrEmpty(str) ? new CodeFieldReferenceExpression(targetObject, str) : null;
             if (right != null)
             {
                 if (left == null)
                 {
                     left = right;
                 }
                 else
                 {
                     left = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.BitwiseOr, right);
                 }
             }
         }
         if ((left != null) && flag)
         {
             left = new CodeCastExpression(value.GetType(), left);
         }
     }
     return left;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:47,代码来源:EnumCodeDomSerializer.cs

示例11: Visit

        public void Visit(InsertIntoDirectoryStatement statement)
        {
            if (statement.Select.Args.Length != 2) //can only select one thing into a directory
            {
                Errors.Add(new OnlyTwoSelectParamForDirectory(new Semantic.LineInfo(statement.Line.Line, statement.Line.CharacterPosition)));
                return;
            }

            var domArg = VisitChild(statement.Select);

            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = "InsertIntoDir_" + domArg.MethodIdentifier;
            method.Attributes = MemberAttributes.Private;

            ((Action)domArg.Tag)();

            //needs to foreach around the returned table from select like the other inserts

            method.Statements.Add(new CodeVariableDeclarationStatement(domArg.Scope.CodeDomReference,
                "resultRows",
                domArg.CodeExpression));

            var cast = new CodeCastExpression(typeof(string),
                new CodeIndexerExpression(new CodeIndexerExpression(new CodeVariableReferenceExpression("resultRows"),
                    new CodePrimitiveExpression(0)), new CodePrimitiveExpression(0)));

            method.Statements.Add(new CodeVariableDeclarationStatement(typeof(string), "filename", cast));

            cast = new CodeCastExpression(typeof(byte[]),
                new CodeIndexerExpression(new CodeIndexerExpression(new CodeVariableReferenceExpression("resultRows"),
                    new CodePrimitiveExpression(0)), new CodePrimitiveExpression(1)));

            method.Statements.Add(new CodeVariableDeclarationStatement(typeof(byte[]), "bytes", cast));

            var directoryArgs = VisitChild(statement.Directory);

            method.Statements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("bytes"), "WriteFile",
                directoryArgs.CodeExpression, new CodeVariableReferenceExpression("filename")));

            _mainType.Type.Members.Add(method);

            var methodcall = new CodeMethodInvokeExpression(
                new CodeMethodReferenceExpression(null, method.Name));

            _codeStack.Peek().ParentStatements.Add(methodcall);
            _codeStack.Peek().CodeExpression = methodcall;
        }
开发者ID:bitsummation,项目名称:pickaxe,代码行数:47,代码来源:Visitor.InsertIntoDirectoryStatement.cs

示例12: CreateMethods

		protected internal override void CreateMethods ()
		{
			base.CreateMethods ();

			Type type = parser.MasterType;
			if (type != null) {
				CodeMemberProperty mprop = new CodeMemberProperty ();
				mprop.Name = "Master";
				mprop.Type = new CodeTypeReference (parser.MasterType);
				mprop.Attributes = MemberAttributes.Public | MemberAttributes.New;
				CodeExpression prop = new CodePropertyReferenceExpression (new CodeBaseReferenceExpression (), "Master");
				prop = new CodeCastExpression (parser.MasterType, prop);
				mprop.GetStatements.Add (new CodeMethodReturnStatement (prop));
				mainClass.Members.Add (mprop);
				AddReferencedAssembly (type.Assembly);
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:MasterPageCompiler.cs

示例13: ToClass

        public CodeTypeDeclaration ToClass()
        {
            var cs = new CodeTypeDeclaration(this.Name);
            var iname = "I" + cs.Name;
            if (cs.Name.Contains('`'))
            {
                cs.Name = cs.Name.Substring(0, cs.Name.Length - 2);

                if (cs.Name.EndsWith("Base"))
                {
                    iname = "I" + cs.Name.Substring(0, cs.Name.Length - 4);
                }
                cs.Name += "<T>";
            }
            if (iname != null)
            {
                cs.BaseTypes.Add(new CodeTypeReference(iname));
            }

            cs.IsPartial = true;

            foreach (var p in Properties)
            {
                if (p.IsInherited) continue;
                var prop = new CodeMemberProperty();
                prop.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                prop.Name = p.Name;
                prop.Type = new CodeTypeReference(p.Type);

                prop.HasGet = true;
                prop.HasSet = false;

                var indexer = new CodeIndexerExpression(new CodeThisReferenceExpression(), new CodePrimitiveExpression(p.Name));

                var cast = new CodeCastExpression(prop.Type, indexer);

                prop.GetStatements.Add(new CodeMethodReturnStatement(cast));

                cs.Members.Add(prop);
            }

            return cs;
        }
开发者ID:mrkurt,项目名称:mubble-old,代码行数:43,代码来源:TypeCollection.cs

示例14: Serialize

 public override object Serialize(IDesignerSerializationManager manager, object value)
 {
     CodeExpression expression = new CodePrimitiveExpression(value);
     if ((((value == null) || (value is bool)) || ((value is char) || (value is int))) || ((value is float) || (value is double)))
     {
         CodeDomProvider service = manager.GetService(typeof(CodeDomProvider)) as CodeDomProvider;
         if ((service != null) && string.Equals(service.FileExtension, JSharpFileExtension))
         {
             ExpressionContext context = manager.Context[typeof(ExpressionContext)] as ExpressionContext;
             if ((context != null) && (context.ExpressionType == typeof(object)))
             {
                 expression = new CodeCastExpression(value.GetType(), expression);
                 expression.UserData.Add("CastIsBoxing", true);
             }
         }
         return expression;
     }
     if (value is string)
     {
         return expression;
     }
     return new CodeCastExpression(new CodeTypeReference(value.GetType()), expression);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:23,代码来源:PrimitiveCodeDomSerializer.cs

示例15: Constructor0

		public void Constructor0 ()
		{
			CodeCastExpression cce = new CodeCastExpression ();
			Assert.IsNull (cce.Expression, "#1");
			Assert.IsNotNull (cce.TargetType, "#2");
			Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#3");

			CodeExpression expression = new CodeExpression ();
			cce.Expression = expression;
			Assert.IsNotNull (cce.Expression, "#4");
			Assert.AreSame (expression, cce.Expression, "#5");

			cce.Expression = null;
			Assert.IsNull (cce.Expression, "#6");

			CodeTypeReference type = new CodeTypeReference ("mono");
			cce.TargetType = type;
			Assert.IsNotNull (cce.TargetType, "#7");
			Assert.AreSame (type, cce.TargetType, "#8");

			cce.TargetType = null;
			Assert.IsNotNull (cce.TargetType, "#9");
			Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#10");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:24,代码来源:CodeCastExpressionTest.cs


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