• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CodeDom.CodeCastExpression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GenerateCastExpression

		protected override void GenerateCastExpression(CodeCastExpression e)
		{
			Output.Write("[CodeCastExpression: {0}]", e.ToString());
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:4,代码来源:CodeDOMVerboseOutputGenerator.cs


示例17: GenerateBody

		/// <summary>
		/// Creates a new body in stlye of an Ado.net Constructor and attaches it to the <paramref name="target"/>
		/// </summary>
		/// <param name="properties"></param>
		/// <param name="settings"></param>
		/// <param name="importNameSpace"></param>
		/// <param name="container"></param>
		/// <param name="target"></param>
		public static void GenerateBody(Dictionary<string, DbPropertyInfoCache> properties,
			FactoryHelperSettings settings,
			CodeNamespace importNameSpace,
			CodeMemberMethod container,
			CodeExpression target)
		{
			foreach (var propertyInfoCache in properties.Values)
			{
				propertyInfoCache.Refresh();

				var columnName = propertyInfoCache.DbName;

				if (settings.EnforcePublicPropertys)
				{
					if (propertyInfoCache.Getter.MethodInfo.IsPrivate)
						throw new AccessViolationException(string.Format(
							"The Getter of {0} is private. Full creation cannot be enforced", propertyInfoCache.PropertyName));
					if (propertyInfoCache.Setter.MethodInfo.IsPrivate)
						throw new AccessViolationException(string.Format(
							"The Setter of {0} is private. Full creation cannot be enforced", propertyInfoCache.PropertyName));
				}

				var codeIndexerExpression = new CodeIndexerExpression(new CodeVariableReferenceExpression("record"),
					new CodePrimitiveExpression(columnName));

				var variableName = columnName.ToLower();
				CodeVariableDeclarationStatement bufferVariable = null;

				//var propertyRef = new CodeVariableReferenceExpression(propertyInfoCache.PropertyName);

				var refToProperty = new CodeFieldReferenceExpression(target, propertyInfoCache.PropertyName);

				var attributes = propertyInfoCache.Attributes;
				var valueConverterAttributeModel =
					attributes.FirstOrDefault(s => s.Attribute is ValueConverterAttribute);
				var isXmlProperty = attributes.FirstOrDefault(s => s.Attribute is FromXmlAttribute);
				CodeVariableReferenceExpression uncastLocalVariableRef = null;

				if (isXmlProperty != null)
				{
					bufferVariable = new CodeVariableDeclarationStatement(typeof(object), variableName);
					container.Statements.Add(bufferVariable);
					uncastLocalVariableRef = new CodeVariableReferenceExpression(variableName);
					var buffAssignment = new CodeAssignStatement(uncastLocalVariableRef, codeIndexerExpression);
					container.Statements.Add(buffAssignment);

					var checkXmlForNull = new CodeConditionStatement();
					checkXmlForNull.Condition = new CodeBinaryOperatorExpression(
						new CodeVariableReferenceExpression(variableName),
						CodeBinaryOperatorType.IdentityInequality,
						new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("System.DBNull"), "Value"));
					container.Statements.Add(checkXmlForNull);

					var xmlRecordType = new CodeTypeReferenceExpression(typeof(XmlDataRecord));
					importNameSpace.Imports.Add(new CodeNamespaceImport(typeof(DbClassInfoCache).Namespace));
					importNameSpace.Imports.Add(new CodeNamespaceImport(typeof(DataConverterExtensions).Namespace));
					importNameSpace.Imports.Add(new CodeNamespaceImport(typeof(DbConfigHelper).Namespace));

					if (propertyInfoCache.CheckForListInterface())
					{
						var typeArgument = propertyInfoCache.PropertyInfo.PropertyType.GetGenericArguments().FirstOrDefault();
						var codeTypeOfListArg = new CodeTypeOfExpression(typeArgument);

						var instanceHelper = new CodeMethodInvokeExpression(
							new CodeTypeReferenceExpression(typeof(NonObservableDbCollection<>).MakeGenericType(typeArgument)),
							"FromXml",
							new CodeCastExpression(typeof(string), new CodeVariableReferenceExpression(variableName)));

						//var tryParse = new CodeMethodInvokeExpression(xmlRecordType,
						//	"TryParse",
						//	new CodeCastExpression(typeof(string), uncastLocalVariableRef),
						//	codeTypeOfListArg,
						//	new CodePrimitiveExpression(false));

						//var xmlDataRecords = new CodeMethodInvokeExpression(tryParse, "CreateListOfItems");
						//var getClassInfo = new CodeMethodInvokeExpression(codeTypeOfListArg, "GetClassInfo");

						//var xmlRecordsToObjects = new CodeMethodInvokeExpression(xmlDataRecords, "Select",
						//	new CodeMethodReferenceExpression(getClassInfo, "SetPropertysViaReflection"));

						//CodeObjectCreateExpression collectionCreate;
						//if (typeArgument != null && (typeArgument.IsClass && typeArgument.GetInterface("INotifyPropertyChanged") != null))
						//{
						//	collectionCreate = new CodeObjectCreateExpression(typeof(DbCollection<>).MakeGenericType(typeArgument),
						//		xmlRecordsToObjects);
						//}
						//else
						//{
						//	collectionCreate = new CodeObjectCreateExpression(typeof(NonObservableDbCollection<>).MakeGenericType(typeArgument),
						//		xmlRecordsToObjects);
						//}

//.........这里部分代码省略.........
开发者ID:JPVenson,项目名称:DataAccess,代码行数:101,代码来源:FactoryHelper.cs


示例18: AddExpressionEvaluation

        private static string AddExpressionEvaluation(CodeTypeDeclaration declaration, CodeExpression root, ref int methodSuffix)
        {
            int currentMethodSuffix = methodSuffix;
            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = string.Format("Eval{0}", currentMethodSuffix);
            method.Attributes = MemberAttributes.Private | MemberAttributes.Final;
            method.ReturnType = new CodeTypeReference(typeof(object));
            method.Parameters.Add(
                new CodeParameterDeclarationExpression(
                    typeof(object[]),
                    "e"));

            if (root is CodeBinaryOperatorExpression)
            {
                CodeBinaryOperatorExpression binaryRoot = (CodeBinaryOperatorExpression)root;

                CodeExpression left = null;
                if (binaryRoot.Left is CodePrimitiveExpression)
                {
                    left = binaryRoot.Left;
                }
                else
                {
                    methodSuffix++;
                    Type expressionType = GetType(binaryRoot.Left, true);
                    if (expressionType == null)
                        return null;
                    left =
                        new CodeCastExpression(expressionType,
                            new CodeMethodInvokeExpression(
                                new CodeThisReferenceExpression(),
                                AddExpressionEvaluation(declaration, binaryRoot.Left, ref methodSuffix),
                                new CodeVariableReferenceExpression("e")));

                }

                CodeExpression right = null;
                if (binaryRoot.Right is CodePrimitiveExpression)
                {
                    right = binaryRoot.Right;
                }
                else
                {
                    methodSuffix++;
                    right =
                        new CodeCastExpression(GetType(binaryRoot.Right, true),
                            new CodeMethodInvokeExpression(
                                new CodeThisReferenceExpression(),
                                AddExpressionEvaluation(declaration, binaryRoot.Right, ref methodSuffix),
                                new CodeVariableReferenceExpression("e")));
                }

                method.Statements.Add(
                    new CodeConditionStatement(
                        new CodeMethodInvokeExpression(
                            new CodeThisReferenceExpression(),
                            "IsEmpty",
                            new CodeArrayIndexerExpression(
                                new CodeVariableReferenceExpression("e"),
                                new CodePrimitiveExpression(currentMethodSuffix))),
                        new CodeStatement[] {
                            new CodeMethodReturnStatement(
                                new CodeBinaryOperatorExpression(
                                    left,
                                    binaryRoot.Operator,
                                    right)) },
                        new CodeStatement[] {
                            new CodeMethodReturnStatement(
                                new CodeArrayIndexerExpression(
                                    new CodeVariableReferenceExpression("e"),
                                    new CodePrimitiveExpression(currentMethodSuffix))) }));
            }
            else
            {
                method.Statements.Add(
                    new CodeConditionStatement(
                        new CodeMethodInvokeExpression(
                            new CodeThisReferenceExpression(),
                            "IsEmpty",
                            new CodeArrayIndexerExpression(
                                new CodeVariableReferenceExpression("e"),
                                new CodePrimitiveExpression(currentMethodSuffix))),
                        new CodeStatement[] {
                            new CodeThrowExceptionStatement(
                                new CodeObjectCreateExpression(
                                    typeof(ArgumentException),
                                    new CodePrimitiveExpression("Cannot have an empty parameter for a non-binary expression"),
                                    new CodePrimitiveExpression("e[" + currentMethodSuffix + "]"))) },
                        new CodeStatement[] {
                            new CodeMethodReturnStatement(
                                new CodeArrayIndexerExpression(
                                    new CodeVariableReferenceExpression("e"),
                                    new CodePrimitiveExpression(currentMethodSuffix))) }));
            }
            declaration.Members.Add(method);

            SetParameterIndex(root, currentMethodSuffix);
            return method.Name;
        }
开发者ID:ssickles,项目名称:archive,代码行数:99,代码来源:EvaluatorGenerator.cs


示例19: GenerateProperties


//.........这里部分代码省略.........
                if (fi.Description != null)
                {
                    prop.Comments.Add(new CodeCommentStatement("<summary>", true));
                    prop.Comments.Add(new CodeCommentStatement(fi.Description, true));
                    prop.Comments.Add(new CodeCommentStatement("</summary>", true));
                }
                ctd.Members.Add(prop);

                if (fi.Size != -1)
                {
                    CodeAttributeDeclaration cad = new CodeAttributeDeclaration("Sooda.SoodaFieldSizeAttribute");
                    cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(fi.Size)));
                    prop.CustomAttributes.Add(cad);
                }

                if (fi.IsPrimaryKey)
                {
                    CodeExpression getPrimaryKeyValue = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "GetPrimaryKeyValue");

                    if (classInfo.GetPrimaryKeyFields().Length > 1)
                    {
                        getPrimaryKeyValue = new CodeMethodInvokeExpression(
                            new CodeTypeReferenceExpression(typeof(SoodaTuple)), "GetValue", getPrimaryKeyValue, new CodePrimitiveExpression(primaryKeyComponentNumber));
                    }

                    if (fi.References != null)
                    {
                        prop.GetStatements.Add(
                            new CodeMethodReturnStatement(
                            new CodeMethodInvokeExpression(
                                LoaderClass(fi.ReferencedClass),
                                "GetRef",
                                GetTransaction(),
                                new CodeCastExpression(
                                    GetReturnType(actualNotNullRepresentation, fi),
                                    getPrimaryKeyValue
                            ))));
                    }
                    else
                    {
                        prop.GetStatements.Add(
                            new CodeMethodReturnStatement(
                            new CodeCastExpression(
                            prop.Type,
                            getPrimaryKeyValue
                            )));
                    }

                    if (!classInfo.ReadOnly && !fi.ReadOnly)
                    {
                        if (classInfo.GetPrimaryKeyFields().Length == 1)
                        {
                            prop.SetStatements.Add(
                                new CodeExpressionStatement(
                                new CodeMethodInvokeExpression(
                                new CodeThisReferenceExpression(), "SetPrimaryKeyValue",
                                new CodePropertySetValueReferenceExpression())));
                        }
                        else
                        {
                            CodeExpression plainValue = new CodePropertySetValueReferenceExpression();
                            if (fi.References != null)
                                plainValue = new CodeMethodInvokeExpression(plainValue, "GetPrimaryKeyValue");
                            prop.SetStatements.Add(
                                new CodeExpressionStatement(
                                new CodeMethodInvokeExpression(
开发者ID:valery-shinkevich,项目名称:sooda,代码行数:67,代码来源:CodeDomClassStubGenerator.cs


示例20: GenerateMethod


//.........这里部分代码省略.........
						methodEnd.ReturnType = cpd.Type;
						GenerateReturnAttributes (outputMembers, outputMembers[n], bodyBinding.Use, method);
						outParams [n] = null;
						continue;
					}
					
					method.Parameters.Add (cpd);
					GenerateMemberAttributes (outputMembers, outputMembers[n], bodyBinding.Use, cpd);
					methodEnd.Parameters.Add (GenerateParameter (outputMembers[n], FieldDirection.Out));
				}
			}
			
			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (AsyncCallback),varCallback));
			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (object),varAsyncState));
			methodBegin.ReturnType = new CodeTypeReference (typeof(IAsyncResult));

			// Array of input parameters
			
			CodeArrayCreateExpression methodParams;
			if (paramArray.Length > 0)
				methodParams = new CodeArrayCreateExpression (typeof(object), paramArray);
			else
				methodParams = new CodeArrayCreateExpression (typeof(object), 0);

			// Assignment of output parameters
			
			CodeStatementCollection outAssign = new CodeStatementCollection ();
			CodeVariableReferenceExpression arrVar = new CodeVariableReferenceExpression (varResults);
			for (int n=0; n<outParams.Length; n++)
			{
				CodeExpression index = new CodePrimitiveExpression (n);
				if (outParams[n] == null)
				{
					CodeExpression res = new CodeCastExpression (method.ReturnType, new CodeArrayIndexerExpression (arrVar, index));
					outAssign.Add (new CodeMethodReturnStatement (res));
				}
				else
				{
					CodeExpression res = new CodeCastExpression (outParams[n].Type, new CodeArrayIndexerExpression (arrVar, index));
					CodeExpression var = new CodeVariableReferenceExpression (outParams[n].Name);
					outAssign.Insert (0, new CodeAssignStatement (var, res));
				}
			}
			
			if (Style == ServiceDescriptionImportStyle.Client) 
			{
				// Invoke call
				
				CodeThisReferenceExpression ethis = new CodeThisReferenceExpression();
				CodePrimitiveExpression varMsgName = new CodePrimitiveExpression (messageName);
				CodeMethodInvokeExpression inv;
				CodeVariableDeclarationStatement dec;
	
				inv = new CodeMethodInvokeExpression (ethis, "Invoke", varMsgName, methodParams);
				if (outputMembers != null && outputMembers.Count > 0)
				{
					dec = new CodeVariableDeclarationStatement (typeof(object[]), varResults, inv);
					method.Statements.Add (dec);
					method.Statements.AddRange (outAssign);
				}
				else
					method.Statements.Add (inv);
				
				// Begin Invoke Call
				
				CodeExpression expCallb = new CodeVariableReferenceExpression (varCallback);
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:67,代码来源:SoapProtocolImporter.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CodeDom.CodeCatchClause类代码示例发布时间:2022-05-26
下一篇:
C# CodeDom.CodeBinaryOperatorExpression类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap