Inheritance: System.CodeDom.CodeExpression
Exemplo n.º 1
0
		public void Constructor0_Deny_Unrestricted ()
		{
			CodeIndexerExpression cie = new CodeIndexerExpression ();
			Assert.AreEqual (0, cie.Indices.Count, "Indices");
			Assert.IsNull (cie.TargetObject, "TargetObject");
			cie.TargetObject = new CodeExpression ();
		}
 private static CodePropertyReferenceExpression DeserializeAppConfigExpression(string[] expressionParts)
 {
     int index = expressionParts.Length - 1;
     CodePropertyReferenceExpression expression = new CodePropertyReferenceExpression {
         PropertyName = expressionParts[index]
     };
     index--;
     CodeIndexerExpression expression2 = new CodeIndexerExpression();
     expression.TargetObject = expression2;
     expression2.Indices.Add(new CodePrimitiveExpression(expressionParts[index]));
     index--;
     CodePropertyReferenceExpression expression3 = new CodePropertyReferenceExpression();
     expression2.TargetObject = expression3;
     expression3.PropertyName = expressionParts[index];
     index--;
     CodeTypeReferenceExpression expression4 = new CodeTypeReferenceExpression();
     expression3.TargetObject = expression4;
     expression4.Type.Options = (CodeTypeReferenceOptions) Enum.Parse(typeof(CodeTypeReferenceOptions), expressionParts[index]);
     index--;
     expression4.Type.BaseType = expressionParts[index];
     index--;
     while (index > 0)
     {
         expression4.Type.BaseType = expressionParts[index] + "." + expression4.Type.BaseType;
         index--;
     }
     return expression;
 }
 public static CodeIndexerExpression Clone(this CodeIndexerExpression expression)
 {
     if (expression == null) return null;
     CodeIndexerExpression e = new CodeIndexerExpression();
     e.Indices.AddRange(expression.Indices.Clone());
     e.TargetObject = expression.TargetObject.Clone();
     e.UserData.AddRange(expression.UserData);
     return e;
 }
Exemplo n.º 4
0
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeExpression target = new CodeExpression ();
			CodeExpression[] indices = new CodeExpression[1] { target };
			CodeIndexerExpression cie = new CodeIndexerExpression (target, indices);
			Assert.AreEqual (1, cie.Indices.Count, "Indices");
			Assert.AreSame (target, cie.TargetObject, "TargetObject");
			cie.TargetObject = new CodeExpression ();
		}
 public TypescriptIndexerExpression(
     IExpressionFactory expressionFactory,
     CodeIndexerExpression codeExpression,
     CodeGeneratorOptions options)
 {
     _codeExpression = codeExpression;
     _options = options;
     _expressionFactory = expressionFactory;
     System.Diagnostics.Debug.WriteLine("TypescriptIndexerExpression Created");
 }
 internal static void GenerateConstructorStatements(CodeConstructor ctor, string url, string appSettingUrlKey, string appSettingBaseUrl, bool soap11)
 {
     bool flag = (url != null) && (url.Length > 0);
     bool flag2 = (appSettingUrlKey != null) && (appSettingUrlKey.Length > 0);
     CodeAssignStatement statement = null;
     if (flag || flag2)
     {
         CodeExpression expression;
         CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Url");
         if (flag)
         {
             expression = new CodePrimitiveExpression(url);
             statement = new CodeAssignStatement(left, expression);
         }
         if (flag && !flag2)
         {
             ctor.Statements.Add(statement);
         }
         else if (flag2)
         {
             CodeVariableReferenceExpression expression3 = new CodeVariableReferenceExpression("urlSetting");
             CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression(typeof(ConfigurationManager));
             CodePropertyReferenceExpression expression5 = new CodePropertyReferenceExpression(targetObject, "AppSettings");
             expression = new CodeIndexerExpression(expression5, new CodeExpression[] { new CodePrimitiveExpression(appSettingUrlKey) });
             ctor.Statements.Add(new CodeVariableDeclarationStatement(typeof(string), "urlSetting", expression));
             if ((appSettingBaseUrl == null) || (appSettingBaseUrl.Length == 0))
             {
                 expression = expression3;
             }
             else
             {
                 if ((url == null) || (url.Length == 0))
                 {
                     throw new ArgumentException(Res.GetString("IfAppSettingBaseUrlArgumentIsSpecifiedThen0"));
                 }
                 string str = new Uri(appSettingBaseUrl).MakeRelative(new Uri(url));
                 CodeExpression[] parameters = new CodeExpression[] { expression3, new CodePrimitiveExpression(str) };
                 expression = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(string)), "Concat", parameters);
             }
             CodeStatement[] trueStatements = new CodeStatement[] { new CodeAssignStatement(left, expression) };
             CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(expression3, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
             if (flag)
             {
                 ctor.Statements.Add(new CodeConditionStatement(condition, trueStatements, new CodeStatement[] { statement }));
             }
             else
             {
                 ctor.Statements.Add(new CodeConditionStatement(condition, trueStatements));
             }
         }
     }
 }
Exemplo n.º 7
0
        // Generates a codedom indexed identifier: one that is an identifier followed by an indexer: ex foo[1].
        public static CodeExpression Emit(IndexedIdentifier indexedIdentifier)
        {
            // Create the codedom indexer expression
            var codeIndex = new CodeIndexerExpression();

            // Set the object that is being indexed.
            codeIndex.TargetObject = new CodeVariableReferenceExpression(indexedIdentifier.Name);

            // Set the expression that is generating the index.
            codeIndex.Indices.Add(CodeDomEmitter.EmitCodeExpression(indexedIdentifier.ChildExpressions[0]));

            return codeIndex;
        }
        public virtual void SetScenarioSetup(CodeMemberMethod memberMethod)
        {
            //ScenarioContext
            var scenarioContext = new CodeTypeReferenceExpression("ScenarioContext");

            // .Current
            var currentContext = new CodePropertyReferenceExpression(scenarioContext, "Current");

            // ["SomeKey"]
            var indexer = new CodeIndexerExpression(currentContext, new CodePrimitiveExpression(CALLING_FEATURE_KEY));

            // = this;
            var assignMent = new CodeAssignStatement(indexer, new CodeThisReferenceExpression());

            //ScenarioContext.Current["SomeKey"] = this;
            memberMethod.Statements.Add(assignMent);
        }
Exemplo n.º 9
0
        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;
        }
 private CodeStatement BuildControlSkinAssignmentStatement(ControlBuilder builder, string skinID)
 {
     Type controlType = builder.ControlType;
     string name = base.GetMethodNameForBuilder(BaseTemplateCodeDomTreeGenerator.buildMethodPrefix, builder) + "_skinKey";
     CodeMemberField field = new CodeMemberField(typeof(object), name) {
         Attributes = MemberAttributes.Private | MemberAttributes.Static
     };
     CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression {
         Method = new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(PageTheme)), "CreateSkinKey")
     };
     expression.Parameters.Add(new CodeTypeOfExpression(controlType));
     expression.Parameters.Add(new CodePrimitiveExpression(skinID));
     field.InitExpression = expression;
     base._sourceDataClass.Members.Add(field);
     CodeFieldReferenceExpression targetObject = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "__controlSkins");
     CodeIndexerExpression left = new CodeIndexerExpression(targetObject, new CodeExpression[] { new CodeVariableReferenceExpression(name) });
     CodeDelegateCreateExpression expression4 = new CodeDelegateCreateExpression(this._controlSkinDelegateType, new CodeThisReferenceExpression(), base.GetMethodNameForBuilder(BaseTemplateCodeDomTreeGenerator.buildMethodPrefix, builder));
     CodeObjectCreateExpression right = new CodeObjectCreateExpression(this._controlSkinType, new CodeExpression[0]);
     right.Parameters.Add(new CodeTypeOfExpression(controlType));
     right.Parameters.Add(expression4);
     return new CodeAssignStatement(left, right);
 }
Exemplo n.º 11
0
	    public void Emit (CodeTypeDeclaration ctd, CodeMemberMethod copy, CodeExpression copyarray, 
			      CodeMemberMethod clone, CodeExpression other)
	    {
		// The field itself

		CodeMemberField f = new CodeMemberField ();
		f.Name = Name;
		f.Attributes = MemberAttributes.Public;
		f.LinePragma = Line;
		f.Type = Type.AsCodeDom;
		f.CustomAttributes.Add (FieldAttr);
		ctd.Members.Add (f);

		// Copy statement in CopyItems

		CodeIndexerExpression index = new CodeIndexerExpression ();
		index.TargetObject = copyarray;
		index.Indices.Add (ResultBuilder.BasePlusN (Idx));
	    
		CodeFieldReferenceExpression fld = CDH.ThisDot (Name);
		CodeMethodInvokeExpression conv = 
		    new CodeMethodInvokeExpression (CDH.This, "FieldAsResult", 
						    new CodeExpression[] { fld });
		CodeAssignStatement assg = 
		    new CodeAssignStatement (index, conv);

		copy.Statements.Add (assg);
	    
		// Add statement to clone result in CloneItems

		CodeFieldReferenceExpression lhs = 
		    new CodeFieldReferenceExpression (other, Name);
		conv = new CodeMethodInvokeExpression (CDH.This, "CloneField", 
						       new CodeExpression[] { fld });
		assg = new CodeAssignStatement (lhs, new CodeCastExpression (f.Type, conv));
		clone.Statements.Add (assg);
	    }
        private void Correct(ref CodeObject target, CodeObject parent, int indent)
        {
            if (target is CodeVariableReferenceExpression)
            {
                CodeVariableReferenceExpression variableExpr = (CodeVariableReferenceExpression) target;

                if (StringUtils.CaseInsensitiveEquals(variableExpr.VariableName, _setValueName))
                {
                    variableExpr.VariableName = _propertyName;
                }
            }
            else if (target is CodeMethodInvokeExpression)
            {
                CodeMethodInvokeExpression methodInvokeExpr = (CodeMethodInvokeExpression) target;

                if (methodInvokeExpr.Method.TargetObject == null && StringUtils.CaseInsensitiveEquals(methodInvokeExpr.Method.MethodName, _setValueName))
                {
                    CodeIndexerExpression indexerExpr = new CodeIndexerExpression(
                        new CodeVariableReferenceExpression(_propertyName));
                    indexerExpr.Indices.AddRange(methodInvokeExpr.Parameters);
                    target = indexerExpr;
                }
            }
        }
Exemplo n.º 13
0
 protected override void GenerateIndexerExpression(CodeIndexerExpression e)
 {
     base.GenerateExpression(e.TargetObject);
     if (e.TargetObject is CodeBaseReferenceExpression)
     {
         base.Output.Write(".Item");
     }
     base.Output.Write("(");
     bool flag = true;
     foreach (CodeExpression expression in e.Indices)
     {
         if (flag)
         {
             flag = false;
         }
         else
         {
             base.Output.Write(", ");
         }
         base.GenerateExpression(expression);
     }
     base.Output.Write(")");
 }
Exemplo n.º 14
0
		protected override void GenerateIndexerExpression (CodeIndexerExpression e)
		{
		}
        //generate part of the xxxProcess method for setting specific adapters for this browser
        internal void GenerateSetAdaptersCode(BrowserDefinition bd, CodeMemberMethod cmm) {
            //GEN: browserCaps.Adapters[xxxControl] = yyyAdapter;
            foreach (DictionaryEntry entry in bd.Adapters) {
                string controlString = (string)entry.Key;
                string adapterString = (string)entry.Value;
                CodePropertyReferenceExpression cpre = new CodePropertyReferenceExpression(_browserCapsRefExpr, "Adapters");
                CodeIndexerExpression indexerExpression = new CodeIndexerExpression(
                    cpre,
                    new CodeExpression[] { new CodePrimitiveExpression(controlString) }
                    );
                CodeAssignStatement assignAdapter = new CodeAssignStatement();
                assignAdapter.Left = indexerExpression;
                assignAdapter.Right = new CodePrimitiveExpression(adapterString);
                cmm.Statements.Add(assignAdapter);
            }

            //GEN: browser.HtmlTextWriter = xxxHtmlTextWriter;
            if(bd.HtmlTextWriterString != null) {
                CodeAssignStatement assignHtmlTextWriter = new CodeAssignStatement();
                assignHtmlTextWriter.Left = new CodePropertyReferenceExpression(_browserCapsRefExpr, "HtmlTextWriter");
                assignHtmlTextWriter.Right = new CodePrimitiveExpression(bd.HtmlTextWriterString);
                cmm.Statements.Add(assignHtmlTextWriter);
            }
            return;
        }
Exemplo n.º 16
0
		protected override void GenerateIndexerExpression (CodeIndexerExpression expression)
		{
			TextWriter output = Output;

			GenerateExpression (expression.TargetObject);
			output.Write ('(');
			OutputExpressionList (expression.Indices);
			output.Write (')');
		}
        public bool ValidateCodeIndexerExpression (CodeIndexerExpression exp) {
            bool result = true;
            PushLocation (exp);

            if (!IsSimpleTarget (exp.TargetObject))
                result = false;

            if (exp.Indices == null || exp.Indices.Count != 1) {
                PushError ("There must be at least one index.");
                result = false;
            }

            if (exp.Indices.Count == 1 && !IsSimpleTarget (exp.Indices[0])) {
                PushError ("Index must be a simple target.");
                result = false;
            }

            PopLocation();
            return result;
        }
		protected override void GenerateIndexerExpression(CodeIndexerExpression e)
		{
			Output.Write("[CodeIndexerExpression: {0}]", e.ToString());
		}
Exemplo n.º 19
0
		/// <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);
						//}

						var setExpr = new CodeAssignStatement(refToProperty, instanceHelper);
						checkXmlForNull.TrueStatements.Add(setExpr);
					}
					else
					{
						var typeofProperty = new CodeTypeOfExpression(propertyInfoCache.PropertyType);
						var getClassInfo = new CodeMethodInvokeExpression(typeofProperty, "GetClassInfo");

						var tryParse = new CodeMethodInvokeExpression(xmlRecordType,
							"TryParse",
							new CodeCastExpression(typeof(string), uncastLocalVariableRef),
							typeofProperty,
							new CodePrimitiveExpression(true));

						var setProps = new CodeMethodInvokeExpression(getClassInfo, "SetPropertysViaReflection", tryParse,
							new CodeSnippetExpression("null"),
							new CodeSnippetExpression("null"));
						var setExpr = new CodeAssignStatement(refToProperty,
							new CodeCastExpression(propertyInfoCache.PropertyType, setProps));
						checkXmlForNull.TrueStatements.Add(setExpr);
					}
				}
				else
				{
					//Should the SQL value be converted
					if (valueConverterAttributeModel != null)
					{
						//create object buff123;
						bufferVariable = new CodeVariableDeclarationStatement(typeof(object), variableName);
						container.Statements.Add(bufferVariable);
						//Assing buff123 = record[x]
						uncastLocalVariableRef = new CodeVariableReferenceExpression(variableName);
						var buffAssignment = new CodeAssignStatement(uncastLocalVariableRef, codeIndexerExpression);
						container.Statements.Add(buffAssignment);

						var converter = valueConverterAttributeModel.Attribute as ValueConverterAttribute;
						//Create the converter and then convert the value before everything else

						importNameSpace.Imports.Add(new CodeNamespaceImport(converter.Converter.Namespace));
						var converterCall = new CodeObjectCreateExpression(converter.Converter);
						var converterInstanceCall = new CodeMethodInvokeExpression(converterCall, "Convert",
							new CodeVariableReferenceExpression(variableName),
							new CodeTypeOfExpression(propertyInfoCache.PropertyType),
							new CodePrimitiveExpression(converter.Parameter),
							new CodeVariableReferenceExpression("System.Globalization.CultureInfo.CurrentCulture"));
						var codeAssignment = new CodeAssignStatement(new CodeVariableReferenceExpression(variableName),
							converterInstanceCall);
						container.Statements.Add(codeAssignment);
					}
					else
					{
						if (propertyInfoCache.PropertyType.IsEnum)
						{
							bufferVariable = new CodeVariableDeclarationStatement(typeof(object), variableName);
							container.Statements.Add(bufferVariable);
							uncastLocalVariableRef = new CodeVariableReferenceExpression(variableName);
							var setToValue = new CodeAssignStatement(refToProperty,
							new CodeCastExpression(
								new CodeTypeReference(propertyInfoCache.PropertyType, CodeTypeReferenceOptions.GenericTypeParameter),
									uncastLocalVariableRef));
							container.Statements.Add(setToValue);
						}
					}

					var isNullable = false;

					var baseType = Nullable.GetUnderlyingType(propertyInfoCache.PropertyType);

					if (baseType != null)
						isNullable = true;

					if (propertyInfoCache.PropertyType == typeof(string))
					{
						baseType = typeof(string);
					}
					else if (propertyInfoCache.PropertyType.IsArray)
					{
						baseType = propertyInfoCache.PropertyType;
					}

					if (baseType != null)
					{
						if (bufferVariable == 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 checkForDbNull = new CodeConditionStatement
						{
							Condition = new CodeBinaryOperatorExpression(uncastLocalVariableRef,
								CodeBinaryOperatorType.IdentityEquality,
								new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("System.DBNull"), "Value"))
						};

						CodeAssignStatement setToNull;
						if (!isNullable && baseType != typeof(string))
						{
							setToNull = new CodeAssignStatement(refToProperty,
							new CodeDefaultValueExpression(
								CreateShortCodeTypeReference(baseType, importNameSpace.Imports)));
						}
						else
						{
							setToNull = new CodeAssignStatement(refToProperty, new CodePrimitiveExpression(null));
						}

						var setToValue = new CodeAssignStatement(refToProperty,
							new CodeCastExpression(
								new CodeTypeReference(baseType, CodeTypeReferenceOptions.GenericTypeParameter),
								uncastLocalVariableRef));
						checkForDbNull.TrueStatements.Add(setToNull);
						checkForDbNull.FalseStatements.Add(setToValue);
						container.Statements.Add(checkForDbNull);
					}
					else
					{
						if (bufferVariable != null)
						{
							CodeExpression castExp = new CodeCastExpression(
						new CodeTypeReference(propertyInfoCache.PropertyType, CodeTypeReferenceOptions.GenericTypeParameter),
						new CodeVariableReferenceExpression(bufferVariable.Name));
							var setExpr = new CodeAssignStatement(refToProperty, castExp);
							container.Statements.Add(setExpr);
						}
						else
						{
							CodeExpression castExp = new CodeCastExpression(
		new CodeTypeReference(propertyInfoCache.PropertyType, CodeTypeReferenceOptions.GenericTypeParameter),
		codeIndexerExpression);
							var setExpr = new CodeAssignStatement(refToProperty, castExp);
							container.Statements.Add(setExpr);
						}

					}
				}
			}
		}
Exemplo n.º 20
0
		void InitMethod (ControlBuilder builder, bool isTemplate, bool childrenAsProperties)
		{
			currentLocation = builder.Location;
			bool inBuildControlTree = builder is RootBuilder;
			string tailname = (inBuildControlTree ? "Tree" : ("_" + builder.ID));
//			bool isProperty = builder.IsProperty;
			CodeMemberMethod method = new CodeMemberMethod ();
			builder.Method = method;
			builder.MethodStatements = method.Statements;

			method.Name = "__BuildControl" + tailname;
			method.Attributes = MemberAttributes.Private | MemberAttributes.Final;
			Type type = builder.ControlType;
			
			/* in the case this is the __BuildControlTree
			 * method, allow subclasses to insert control
			 * specific code. */
			if (inBuildControlTree) {
				SetCustomAttributes (method);
				AddStatementsToInitMethodTop (builder, method);
			}
			
			if (builder.HasAspCode) {
				CodeMemberMethod renderMethod = new CodeMemberMethod ();
				builder.RenderMethod = renderMethod;
				renderMethod.Name = "__Render" + tailname;
				renderMethod.Attributes = MemberAttributes.Private | MemberAttributes.Final;
				CodeParameterDeclarationExpression arg1 = new CodeParameterDeclarationExpression ();
				arg1.Type = new CodeTypeReference (typeof (HtmlTextWriter));
				arg1.Name = "__output";
				CodeParameterDeclarationExpression arg2 = new CodeParameterDeclarationExpression ();
				arg2.Type = new CodeTypeReference (typeof (Control));
				arg2.Name = "parameterContainer";
				renderMethod.Parameters.Add (arg1);
				renderMethod.Parameters.Add (arg2);
				mainClass.Members.Add (renderMethod);
			}
			
			if (childrenAsProperties || type == null) {
				string typeString;
				bool isGlobal = true;
				bool returnsControl;

				if (builder is RootBuilder) {
					typeString = parser.ClassName;
					isGlobal = false;
					returnsControl = false;
				} else {
					returnsControl = builder.PropertyBuilderShouldReturnValue;
					if (type != null && builder.IsProperty && !typeof (ITemplate).IsAssignableFrom (type)) {
						typeString = type.FullName;
						isGlobal = !type.IsPrimitive;
					} else 
						typeString = "System.Web.UI.Control";
					ProcessTemplateChildren (builder);
				}
				CodeTypeReference ctrlTypeRef = new CodeTypeReference (typeString);
				if (isGlobal)
					ctrlTypeRef.Options |= CodeTypeReferenceOptions.GlobalReference;
				
				if (returnsControl) {
					method.ReturnType = ctrlTypeRef;

					// $controlType _ctrl = new $controlType ($parameters);
					//
					method.Statements.Add (CreateControlVariable (type, builder, method, ctrlTypeRef));
				} else
					method.Parameters.Add (new CodeParameterDeclarationExpression (typeString, "__ctrl"));
			} else {
				CodeTypeReference ctrlTypeRef = new CodeTypeReference (type.FullName);
				if (!type.IsPrimitive)
					ctrlTypeRef.Options |= CodeTypeReferenceOptions.GlobalReference;
				
				if (typeof (Control).IsAssignableFrom (type))
					method.ReturnType = ctrlTypeRef;

				// $controlType _ctrl = new $controlType ($parameters);
				//
				method.Statements.Add (AddLinePragma (CreateControlVariable (type, builder, method, ctrlTypeRef), builder));
								
				// this.$builderID = _ctrl;
				//
				CodeFieldReferenceExpression builderID = new CodeFieldReferenceExpression ();
				builderID.TargetObject = thisRef;
				builderID.FieldName = builder.ID;
				CodeAssignStatement assign = new CodeAssignStatement ();
				assign.Left = builderID;
				assign.Right = ctrlVar;
				method.Statements.Add (AddLinePragma (assign, builder));

				if (typeof (UserControl).IsAssignableFrom (type)) {
					CodeMethodReferenceExpression mref = new CodeMethodReferenceExpression ();
					mref.TargetObject = builderID;
					mref.MethodName = "InitializeAsUserControl";
					CodeMethodInvokeExpression initAsControl = new CodeMethodInvokeExpression (mref);
					initAsControl.Parameters.Add (new CodePropertyReferenceExpression (thisRef, "Page"));
					method.Statements.Add (initAsControl);
				}

				if (builder.ParentTemplateBuilder is System.Web.UI.WebControls.ContentBuilderInternal) {
					PropertyInfo pi;

					try {
						pi = type.GetProperty ("TemplateControl");
					} catch (Exception) {
						pi = null;
					}

					if (pi != null && pi.CanWrite) {
						// __ctrl.TemplateControl = this;
						assign = new CodeAssignStatement ();
						assign.Left = new CodePropertyReferenceExpression (ctrlVar, "TemplateControl");;
						assign.Right = thisRef;
						method.Statements.Add (assign);
					}
				}
				
				// _ctrl.SkinID = $value
				// _ctrl.ApplyStyleSheetSkin (this);
				//
				// the SkinID assignment needs to come
				// before the call to
				// ApplyStyleSheetSkin, for obvious
				// reasons.  We skip SkinID in
				// CreateAssignStatementsFromAttributes
				// below.
				// 
				string skinid = builder.GetAttribute ("skinid");
				if (!String.IsNullOrEmpty (skinid))
					CreateAssignStatementFromAttribute (builder, "skinid");

				if (typeof (WebControl).IsAssignableFrom (type)) {
					CodeMethodInvokeExpression applyStyleSheetSkin = new CodeMethodInvokeExpression (ctrlVar, "ApplyStyleSheetSkin");
					if (typeof (Page).IsAssignableFrom (parser.BaseType))
						applyStyleSheetSkin.Parameters.Add (thisRef);
					else
						applyStyleSheetSkin.Parameters.Add (new CodePropertyReferenceExpression (thisRef, "Page"));
					method.Statements.Add (applyStyleSheetSkin);
				}

				// Process template children before anything else
				ProcessTemplateChildren (builder);

				// process ID here. It should be set before any other attributes are
				// assigned, since the control code may rely on ID being set. We
				// skip ID in CreateAssignStatementsFromAttributes
				string ctl_id = builder.GetAttribute ("id");
				if (ctl_id != null && ctl_id.Length != 0)
					CreateAssignStatementFromAttribute (builder, "id");
				
				if (typeof (ContentPlaceHolder).IsAssignableFrom (type)) {
					List <string> placeHolderIds = MasterPageContentPlaceHolders;
					string cphID = builder.ID;
					
					if (!placeHolderIds.Contains (cphID))
						placeHolderIds.Add (cphID);

					CodeConditionStatement condStatement;

					// Add the __Template_* field
					string templateField = "__Template_" + cphID;
					CodeMemberField fld = new CodeMemberField (typeof (ITemplate), templateField);
					fld.Attributes = MemberAttributes.Private;
					mainClass.Members.Add (fld);

					CodeFieldReferenceExpression templateID = new CodeFieldReferenceExpression ();
					templateID.TargetObject = thisRef;
					templateID.FieldName = templateField;

					CreateContentPlaceHolderTemplateProperty (templateField, "Template_" + cphID);
					
					// if ((this.ContentTemplates != null)) {
					// 	this.__Template_$builder.ID = ((System.Web.UI.ITemplate)(this.ContentTemplates["$builder.ID"]));
					// }
					//
					CodeFieldReferenceExpression contentTemplates = new CodeFieldReferenceExpression ();
					contentTemplates.TargetObject = thisRef;
					contentTemplates.FieldName = "ContentTemplates";

					CodeIndexerExpression indexer = new CodeIndexerExpression ();
					indexer.TargetObject = new CodePropertyReferenceExpression (thisRef, "ContentTemplates");
					indexer.Indices.Add (new CodePrimitiveExpression (cphID));

					assign = new CodeAssignStatement ();
					assign.Left = templateID;
					assign.Right = new CodeCastExpression (new CodeTypeReference (typeof (ITemplate)), indexer);

					condStatement = new CodeConditionStatement (new CodeBinaryOperatorExpression (contentTemplates,
														      CodeBinaryOperatorType.IdentityInequality,
														      new CodePrimitiveExpression (null)),
										    assign);

					method.Statements.Add (condStatement);

					// if ((this.__Template_mainContent != null)) {
					// 	this.__Template_mainContent.InstantiateIn(__ctrl);
					// }
					// and also set things up such that any additional code ends up in:
					// else {
					// 	...
					// }
					//
					CodeMethodReferenceExpression methodRef = new CodeMethodReferenceExpression ();
					methodRef.TargetObject = templateID;
					methodRef.MethodName = "InstantiateIn";

					CodeMethodInvokeExpression instantiateInInvoke;
					instantiateInInvoke = new CodeMethodInvokeExpression (methodRef, ctrlVar);

					condStatement = new CodeConditionStatement (new CodeBinaryOperatorExpression (templateID,
														      CodeBinaryOperatorType.IdentityInequality,
														      new CodePrimitiveExpression (null)),
										    new CodeExpressionStatement (instantiateInInvoke));
					method.Statements.Add (condStatement);

					// this is the bit that causes the following stuff to end up in the else { }
					builder.MethodStatements = condStatement.FalseStatements;
				}
			}

			if (inBuildControlTree)
				AddStatementsToInitMethodBottom (builder, method);
			
			mainClass.Members.Add (method);
		}
Exemplo n.º 21
0
        /// <summary>
        /// Generates code for Property Set for Cimtype.DateTime and CimType.Reference type property
        /// </summary>
        void AddPropertySet(CodeIndexerExpression prop,bool bArray,CodeStatementCollection statColl,string strType,CodeVariableReferenceExpression varValue)
        {
            if(varValue == null)
            {
                varValue = new CodeVariableReferenceExpression("value");
            }

            if(bArray == false)
            {
                statColl.Add(new CodeAssignStatement(prop,
                    ConvertPropertyToString(strType, varValue)));
            }
            else
            {
                string strLength = "len";
                string strnCtr = "iCounter";
                string strArray = "arrProp";

                CodeConditionStatement cis1 = new CodeConditionStatement();
                CodeBinaryOperatorExpression cboe1 = new CodeBinaryOperatorExpression();
                cboe1.Left = varValue;
                cboe1.Operator = CodeBinaryOperatorType.IdentityInequality;
                cboe1.Right = new CodePrimitiveExpression(null);
                cis1.Condition = cboe1;

                CodePropertyReferenceExpression LenProp = 
                    new CodePropertyReferenceExpression(
                    new CodeCastExpression(
                    new CodeTypeReference("System.Array"),
                    varValue
                    ),
                    "Length"
                    );

                cis1.TrueStatements.Add(
                    new CodeVariableDeclarationStatement(
                    new CodeTypeReference("System.Int32"),
                    strLength,
                    LenProp
                    )
                    );

                CodeTypeReference arrPathType = 
                    new CodeTypeReference(new CodeTypeReference("System.String"), 1);

                cis1.TrueStatements.Add(
                    new CodeVariableDeclarationStatement(
                    arrPathType,
                    strArray,
                    new CodeArrayCreateExpression(
                    new CodeTypeReference("System.String"),
                    new CodeVariableReferenceExpression(strLength)
                    )
                    )
                    );

                cfls = new CodeIterationStatement();

                cfls.InitStatement = new CodeVariableDeclarationStatement(
                    new CodeTypeReference("System.Int32"),
                    strnCtr,
                    new CodePrimitiveExpression(0)
                    );

                cboe1 = new CodeBinaryOperatorExpression();
                cboe1.Left = new CodeVariableReferenceExpression(strnCtr);
                cboe1.Operator = CodeBinaryOperatorType.LessThan;
                cboe1.Right = new CodeVariableReferenceExpression(strLength);

                cfls.TestExpression = cboe1;

                cfls.IncrementStatement = 
                    new CodeAssignStatement(
                    new CodeVariableReferenceExpression(strnCtr),
                    new CodeBinaryOperatorExpression(
                    new CodeVariableReferenceExpression(strnCtr),
                    CodeBinaryOperatorType.Add,
                    new CodePrimitiveExpression(1)
                    )
                    );

                CodeMethodInvokeExpression cmie1 = new CodeMethodInvokeExpression();
                cmie1.Method.MethodName = "GetValue";
                cmie1.Method.TargetObject = new CodeCastExpression(new CodeTypeReference("System.Array"),varValue);
                        
                cmie1.Parameters.Add(new CodeVariableReferenceExpression(strnCtr));

                cfls.Statements.Add( new CodeAssignStatement(new CodeIndexerExpression(new CodeVariableReferenceExpression(strArray),
                    new CodeVariableReferenceExpression(strnCtr)),ConvertPropertyToString(strType,cmie1)));

                cis1.TrueStatements.Add(cfls);

                cis1.TrueStatements.Add(new CodeAssignStatement(prop,new CodeVariableReferenceExpression(strArray)));
                cis1.FalseStatements.Add(new CodeAssignStatement(prop,new CodePrimitiveExpression(null)));
                statColl.Add (cis1);
            }
        }
Exemplo n.º 22
0
        /// <include file='doc\CSharpCodeProvider.uex' path='docs/doc[@for="CSharpCodeGenerator.GenerateIndexerExpression"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Generates code for the specified CodeDom based indexer expression
        ///       representation.
        ///    </para>
        /// </devdoc>
        protected override void GenerateIndexerExpression(CodeIndexerExpression e) {
            GenerateExpression(e.TargetObject);
            Output.Write("[");
            bool first = true;
            foreach(CodeExpression exp in e.Indices) {            
                if (first) {
                    first = false;
                }
                else {
                    Output.Write(", ");
                }
                GenerateExpression(exp);
            }
            Output.Write("]");

        }
Exemplo n.º 23
0
 private void ValidateIndexerExpression(CodeIndexerExpression e) {
     ValidateExpression(e.TargetObject);
     foreach(CodeExpression exp in e.Indices) {            
         ValidateExpression(exp);
     }
 }
        internal static void GenerateConstructorStatements(CodeConstructor ctor, string url, string appSettingUrlKey, string appSettingBaseUrl, bool soap11) {
            CodeExpression value; 
            bool generateFixedUrlAssignment = (url != null && url.Length > 0);
            bool generateConfigUrlAssignment = appSettingUrlKey != null && appSettingUrlKey.Length > 0;
            CodeAssignStatement assignUrlStatement = null;

            if (!generateFixedUrlAssignment && !generateConfigUrlAssignment)
                return;

            // this.Url property
            CodePropertyReferenceExpression urlPropertyReference = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Url");

            if (generateFixedUrlAssignment) {
                value = new CodePrimitiveExpression(url);
                assignUrlStatement = new CodeAssignStatement(urlPropertyReference, value);
            }

            if (generateFixedUrlAssignment && !generateConfigUrlAssignment) {
                ctor.Statements.Add(assignUrlStatement);
            }
            else if (generateConfigUrlAssignment) {
                // urlSetting local variable
                CodeVariableReferenceExpression urlSettingReference = new CodeVariableReferenceExpression("urlSetting");                

                // Generate: string urlSetting = System.Configuration.ConfigurationManager.AppSettings["<appSettingUrlKey>"];
                CodeTypeReferenceExpression codeTypeReference = new CodeTypeReferenceExpression(typeof(ConfigurationManager));
                CodePropertyReferenceExpression propertyReference = new CodePropertyReferenceExpression(codeTypeReference, "AppSettings");
                value = new CodeIndexerExpression(propertyReference, new CodeExpression[] { new CodePrimitiveExpression(appSettingUrlKey) });
                ctor.Statements.Add(new CodeVariableDeclarationStatement(typeof(string), "urlSetting", value));

                if (appSettingBaseUrl == null || appSettingBaseUrl.Length == 0) {
                    // Generate: this.Url = urlSetting;
                    value = urlSettingReference;
                }
                else {
                    // Generate: this.Url = "http://localhost/mywebapplication/simple.asmx";
                    if (url == null || url.Length == 0)
                        throw new ArgumentException(Res.GetString(Res.IfAppSettingBaseUrlArgumentIsSpecifiedThen0));
                    string relativeUrl = new Uri(appSettingBaseUrl).MakeRelative(new Uri(url));
                    CodeExpression[] parameters = new CodeExpression[] { urlSettingReference, new CodePrimitiveExpression(relativeUrl) };
                    value = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(System.String)), "Concat", parameters);                
                }
                CodeStatement[] trueStatements = new CodeStatement[] { new CodeAssignStatement(urlPropertyReference, value) };        

                // Generate: if (urlSetting != null) { <truestatement> } else { <falsestatement> }
                CodeBinaryOperatorExpression checkIfNull = new CodeBinaryOperatorExpression(urlSettingReference, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
                if (generateFixedUrlAssignment)
                    ctor.Statements.Add(new CodeConditionStatement(checkIfNull, trueStatements, new CodeStatement[] { assignUrlStatement }));
                else
                    ctor.Statements.Add(new CodeConditionStatement(checkIfNull, trueStatements));
            }
        }
Exemplo n.º 25
0
 protected override void GenerateIndexerExpression(System.CodeDom.CodeIndexerExpression e)
 {
     throw new Exception("The method or operation is not implemented.");
 }
 internal void GenerateSetAdaptersCode(BrowserDefinition bd, CodeMemberMethod cmm)
 {
     foreach (DictionaryEntry entry in bd.Adapters)
     {
         string key = (string) entry.Key;
         string str2 = (string) entry.Value;
         CodePropertyReferenceExpression targetObject = new CodePropertyReferenceExpression(this._browserCapsRefExpr, "Adapters");
         CodeIndexerExpression expression2 = new CodeIndexerExpression(targetObject, new CodeExpression[] { new CodePrimitiveExpression(key) });
         CodeAssignStatement statement = new CodeAssignStatement {
             Left = expression2,
             Right = new CodePrimitiveExpression(str2)
         };
         cmm.Statements.Add(statement);
     }
     if (bd.HtmlTextWriterString != null)
     {
         CodeAssignStatement statement2 = new CodeAssignStatement {
             Left = new CodePropertyReferenceExpression(this._browserCapsRefExpr, "HtmlTextWriter"),
             Right = new CodePrimitiveExpression(bd.HtmlTextWriterString)
         };
         cmm.Statements.Add(statement2);
     }
 }
Exemplo n.º 27
0
        public CodeExpression ParseBaseExpression()
        {
            if (TokenType == CDILToken.Integer)
            {
                CodePrimitiveExpression expr = new CodePrimitiveExpression(TokenValue);
                GetNextToken();
                return expr;
            }
            if (TokenType == CDILToken.String)
            {
                CodePrimitiveExpression expr = new CodePrimitiveExpression(TokenValue);
                GetNextToken();
                return expr;
            }
            if (IsKeyword("base"))
            {
                GetNextToken();
                return new CodeBaseReferenceExpression();
            }

            if (IsKeyword("null"))
            {
                GetNextToken();
                return new CodePrimitiveExpression(null);
            }

            if (IsKeyword("false"))
            {
                GetNextToken();
                return new CodePrimitiveExpression(false);
            }

            if (IsKeyword("true"))
            {
                GetNextToken();
                return new CodePrimitiveExpression(true);
            }

            if (IsKeyword("this"))
            {
                GetNextToken();
                return new CodeThisReferenceExpression();
            }

            if (IsKeyword("setvalue"))
            {
                GetNextToken();
                return new CodePropertySetValueReferenceExpression();
            }

            if (IsKeyword("arg"))
            {
                GetNextToken();
                Expect(CDILToken.LeftParen);
                string name = EatKeyword();
                Expect(CDILToken.RightParen);
                return new CodeArgumentReferenceExpression(name);
            }

            if (IsKeyword("delegatecall"))
            {
                CodeDelegateInvokeExpression retval = new CodeDelegateInvokeExpression();
                GetNextToken();
                Expect(CDILToken.LeftParen);
                retval.TargetObject = ParseExpression();
                Expect(CDILToken.RightParen);
                Expect(CDILToken.LeftParen);
                while (TokenType != CDILToken.RightParen && TokenType != CDILToken.EOF)
                {
                    CodeExpression expr = ParseExpression();
                    retval.Parameters.Add(expr);
                    if (TokenType == CDILToken.Comma)
                    {
                        GetNextToken();
                    }
                }
                Expect(CDILToken.RightParen);
                return retval;
            }

            if (IsKeyword("typeref"))
            {
                GetNextToken();
                Expect(CDILToken.LeftParen);
                CodeTypeReference typeRef = ParseType();
                Expect(CDILToken.RightParen);
                return new CodeTypeReferenceExpression(typeRef);
            }

            if (IsKeyword("typeof"))
            {
                GetNextToken();
                Expect(CDILToken.LeftParen);
                CodeTypeReference typeRef = ParseType();
                Expect(CDILToken.RightParen);
                return new CodeTypeOfExpression(typeRef);
            }

            if (IsKeyword("add"))
            {
                CodeBinaryOperatorExpression cboe = new CodeBinaryOperatorExpression();
                cboe.Operator = CodeBinaryOperatorType.Add;
                GetNextToken();
                Expect(CDILToken.LeftParen);
                cboe.Left = ParseExpression();
                Expect(CDILToken.Comma);
                cboe.Right = ParseExpression();
                Expect(CDILToken.RightParen);
                return cboe;
            }

            if (IsKeyword("equal"))
            {
                CodeBinaryOperatorExpression cboe = new CodeBinaryOperatorExpression();
                cboe.Operator = CodeBinaryOperatorType.ValueEquality;
                GetNextToken();
                Expect(CDILToken.LeftParen);
                cboe.Left = ParseExpression();
                Expect(CDILToken.Comma);
                cboe.Right = ParseExpression();
                Expect(CDILToken.RightParen);
                return cboe;
            }

            if (IsKeyword("refequal"))
            {
                CodeBinaryOperatorExpression cboe = new CodeBinaryOperatorExpression();
                cboe.Operator = CodeBinaryOperatorType.IdentityEquality;
                GetNextToken();
                Expect(CDILToken.LeftParen);
                cboe.Left = ParseExpression();
                Expect(CDILToken.Comma);
                cboe.Right = ParseExpression();
                Expect(CDILToken.RightParen);
                return cboe;
            }

            if (IsKeyword("refnotequal"))
            {
                CodeBinaryOperatorExpression cboe = new CodeBinaryOperatorExpression();
                cboe.Operator = CodeBinaryOperatorType.IdentityInequality;
                GetNextToken();
                Expect(CDILToken.LeftParen);
                cboe.Left = ParseExpression();
                Expect(CDILToken.Comma);
                cboe.Right = ParseExpression();
                Expect(CDILToken.RightParen);
                return cboe;
            }

            if (IsKeyword("arrayitem"))
            {
                GetNextToken();
                Expect(CDILToken.LeftParen);
                CodeArrayIndexerExpression caie = new CodeArrayIndexerExpression();
                caie.TargetObject = ParseExpression();
                while (TokenType == CDILToken.Comma)
                {
                    Expect(CDILToken.Comma);
                    caie.Indices.Add(ParseExpression());
                }
                Expect(CDILToken.RightParen);
                return caie;
            }

            if (IsKeyword("index"))
            {
                GetNextToken();
                Expect(CDILToken.LeftParen);
                CodeIndexerExpression cie = new CodeIndexerExpression();
                cie.TargetObject = ParseExpression();
                while (TokenType == CDILToken.Comma)
                {
                    Expect(CDILToken.Comma);
                    cie.Indices.Add(ParseExpression());
                }
                Expect(CDILToken.RightParen);
                return cie;
            }

            if (IsKeyword("var"))
            {
                GetNextToken();
                Expect(CDILToken.LeftParen);
                string name = EatKeyword();
                Expect(CDILToken.RightParen);
                return new CodeVariableReferenceExpression(name);
            }

            if (IsKeyword("defaultscope"))
            {
                GetNextToken();
                return null;
            }

            if (IsKeyword("ref"))
            {
                GetNextToken();
                Expect(CDILToken.LeftParen);
                CodeExpression expr = ParseExpression();
                Expect(CDILToken.RightParen);
                return new CodeDirectionExpression(FieldDirection.Ref, expr);
            }

            if (IsKeyword("out"))
            {
                GetNextToken();
                Expect(CDILToken.LeftParen);
                CodeExpression expr = ParseExpression();
                Expect(CDILToken.RightParen);
                return new CodeDirectionExpression(FieldDirection.Out, expr);
            }

            if (IsKeyword("cast"))
            {
                GetNextToken();
                Expect(CDILToken.LeftParen);
                CodeTypeReference type = ParseType();
                Expect(CDILToken.Comma);
                CodeExpression expr = ParseExpression();
                Expect(CDILToken.RightParen);
                return new CodeCastExpression(type, expr);
            }
            if (IsKeyword("new"))
            {
                GetNextToken();
                CodeTypeReference type = ParseType();
                CodeObjectCreateExpression retval = new CodeObjectCreateExpression(type);
                Expect(CDILToken.LeftParen);
                while (TokenType != CDILToken.RightParen && TokenType != CDILToken.EOF)
                {
                    CodeExpression expr = ParseExpression();
                    retval.Parameters.Add(expr);
                    if (TokenType == CDILToken.Comma)
                    {
                        GetNextToken();
                    }
                }
                Expect(CDILToken.RightParen);
                return retval;
            }

            if (IsKeyword("newarray"))
            {
                GetNextToken();
                Expect(CDILToken.LeftParen);
                CodeArrayCreateExpression retval = new CodeArrayCreateExpression();
                retval.CreateType = ParseType();
                Expect(CDILToken.Comma);
                retval.SizeExpression = ParseExpression();
                Expect(CDILToken.RightParen);
                return retval;
            }

            throw BuildException("Unexpected token '" + TokenType + "'");
        }
Exemplo n.º 28
0
			public void Visit (CodeIndexerExpression o)
			{
				g.GenerateIndexerExpression (o);
			}
Exemplo n.º 29
0
		protected abstract void GenerateIndexerExpression (CodeIndexerExpression e);
Exemplo n.º 30
0
		void AddRenderControl (ControlBuilder builder)
		{
			CodeIndexerExpression indexer = new CodeIndexerExpression ();
			indexer.TargetObject = new CodePropertyReferenceExpression (
							new CodeArgumentReferenceExpression ("parameterContainer"),
							"Controls");
							
			indexer.Indices.Add (new CodePrimitiveExpression (builder.RenderIndex));
			
			CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (indexer, "RenderControl");
			invoke.Parameters.Add (new CodeArgumentReferenceExpression ("__output"));
			builder.RenderMethod.Statements.Add (invoke);
			builder.IncreaseRenderIndex ();
		}
Exemplo n.º 31
0
        void AddGetStatementsForEnumArray(CodeIndexerExpression ciProp,CodeMemberProperty cmProp)
        {
            string strArray = "arrEnumVals";
            string ArrToRet = "enumToRet";
            string strnCtr = "counter";
            string strEnumName = cmProp.Type.BaseType;
        

            cmProp.GetStatements.Add(new CodeVariableDeclarationStatement("System.Array",strArray,
                new CodeCastExpression(new CodeTypeReference("System.Array"),ciProp)));

            cmProp.GetStatements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference(strEnumName,1),ArrToRet,
                new CodeArrayCreateExpression(new CodeTypeReference(strEnumName),
                new CodePropertyReferenceExpression(
                new CodeVariableReferenceExpression(strArray),"Length"))));
            
            cfls = new CodeIterationStatement();

            cmProp.GetStatements.Add(new CodeVariableDeclarationStatement("System.Int32",strnCtr,new CodePrimitiveExpression(0)));
            cfls.InitStatement = new CodeAssignStatement(new CodeVariableReferenceExpression(strnCtr),new CodePrimitiveExpression(0));
            CodeBinaryOperatorExpression cboe1 = new CodeBinaryOperatorExpression();
            cboe1.Left = new CodeVariableReferenceExpression(strnCtr);
            cboe1.Operator = CodeBinaryOperatorType.LessThan;
            cboe1.Right = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(strArray),"Length");
            cfls.TestExpression = cboe1;
            cfls.IncrementStatement = new CodeAssignStatement(new CodeVariableReferenceExpression(strnCtr),
                new CodeBinaryOperatorExpression(
                new CodeVariableReferenceExpression(strnCtr),
                CodeBinaryOperatorType.Add,
                new CodePrimitiveExpression(1)));


            CodeMethodInvokeExpression cmie1 = new CodeMethodInvokeExpression();
            cmie1.Method.MethodName = "GetValue";
            cmie1.Method.TargetObject = new CodeVariableReferenceExpression(strArray);
            cmie1.Parameters.Add(new CodeVariableReferenceExpression(strnCtr));
            
            CodeMethodInvokeExpression cmie2 = new CodeMethodInvokeExpression();
            cmie2.Method.TargetObject = new CodeTypeReferenceExpression("System.Convert");
            cmie2.Parameters.Add(cmie1);
            cmie2.Method.MethodName = arrConvFuncName;
            cfls.Statements.Add(new CodeAssignStatement(new CodeIndexerExpression(new CodeVariableReferenceExpression(ArrToRet),
                new CodeVariableReferenceExpression(strnCtr)),
                new CodeCastExpression(new CodeTypeReference(strEnumName),cmie2 )));


            cmProp.GetStatements.Add(cfls);

            cmProp.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression(ArrToRet)));
            
        }