Inheritance: System.CodeDom.CodeExpression
 public override void ImportClass()
 {
     SoapAddressBinding binding = (base.ImportContext.Port == null) ? null : ((SoapAddressBinding) base.ImportContext.Port.Extensions.Find(typeof(SoapAddressBinding)));
     if (base.ImportContext.Style == ServiceDescriptionImportStyle.Client)
     {
         base.ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(SoapHttpClientProtocol).FullName);
         CodeConstructor ctor = WebCodeGenerator.AddConstructor(base.ImportContext.CodeTypeDeclaration, new string[0], new string[0], null, CodeFlags.IsPublic);
         ctor.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true));
         bool flag = true;
         if (base.ImportContext is Soap12ProtocolImporter)
         {
             flag = false;
             CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression(typeof(SoapProtocolVersion));
             CodeFieldReferenceExpression right = new CodeFieldReferenceExpression(targetObject, Enum.Format(typeof(SoapProtocolVersion), SoapProtocolVersion.Soap12, "G"));
             CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "SoapVersion");
             CodeAssignStatement statement = new CodeAssignStatement(left, right);
             ctor.Statements.Add(statement);
         }
         ServiceDescription serviceDescription = base.ImportContext.Binding.ServiceDescription;
         string url = (binding != null) ? binding.Location : null;
         string appSettingUrlKey = serviceDescription.AppSettingUrlKey;
         string appSettingBaseUrl = serviceDescription.AppSettingBaseUrl;
         ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, appSettingUrlKey, appSettingBaseUrl, flag && !base.ImportContext.IsEncodedBinding);
     }
     else if (base.ImportContext.Style == ServiceDescriptionImportStyle.Server)
     {
         base.ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(WebService).FullName);
     }
 }
Beispiel #2
0
        protected CodeStatementCollection GenerateSetMappedPropertyCode(CodeExpression targetObj, CodeExpression value)
        {
            CodeStatementCollection statements = new CodeStatementCollection();

            CodePropertyReferenceExpression property = new CodePropertyReferenceExpression(targetObj, MappedProperty.Name);

            if (_mappedProperty.PropertyType.IsArray)
            {
                statements.Add(new CodeAssignStatement(
                    new CodeIndexerExpression(property, new CodePrimitiveExpression(_index)), value));
                return statements;
            }

            if (IsCollection(_mappedProperty.PropertyType))
            {
                CodeBinaryOperatorExpression isNull =
                    new CodeBinaryOperatorExpression(property, CodeBinaryOperatorType.ValueEquality, new CodeSnippetExpression("null"));
                CodeAssignStatement create = new CodeAssignStatement(property, new CodeObjectCreateExpression(_mappedProperty.PropertyType));

                statements.Add(new CodeConditionStatement(isNull, create));
                statements.Add(new CodeMethodInvokeExpression(property, "Add", value));
                return statements;
            }

            statements.Add(new CodeAssignStatement(property, value));
            return statements;
        }
        private void BuildAddContentPlaceHolderNames(CodeMemberMethod method, string placeHolderID) {
            CodePropertyReferenceExpression propertyExpr = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "ContentPlaceHolders");
            CodeExpressionStatement stmt = new CodeExpressionStatement();
            stmt.Expression = new CodeMethodInvokeExpression(propertyExpr, "Add", new CodePrimitiveExpression(placeHolderID.ToLower(CultureInfo.InvariantCulture)));

            method.Statements.Add(stmt);
        }
 public override void ImportClass() {
     // grab this here so it gets marked "handled" for both client and server
     SoapAddressBinding soapAddress = ImportContext.Port == null ? null : (SoapAddressBinding)ImportContext.Port.Extensions.Find(typeof(SoapAddressBinding));
     if (ImportContext.Style == ServiceDescriptionImportStyle.Client) {
         ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(SoapHttpClientProtocol).FullName);                                
         CodeConstructor ctor = WebCodeGenerator.AddConstructor(ImportContext.CodeTypeDeclaration, new string[0], new string[0], null, CodeFlags.IsPublic);
         ctor.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
         bool soap11 = true;
         if (ImportContext is Soap12ProtocolImporter) {
             soap11 = false;
             // add version code
             CodeTypeReferenceExpression versionEnumTypeReference = new CodeTypeReferenceExpression(typeof(SoapProtocolVersion));
             CodeFieldReferenceExpression versionEnumFieldReference = new CodeFieldReferenceExpression(versionEnumTypeReference, Enum.Format(typeof(SoapProtocolVersion), SoapProtocolVersion.Soap12, "G"));
             CodePropertyReferenceExpression versionPropertyReference = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "SoapVersion");
             CodeAssignStatement assignVersionStatement = new CodeAssignStatement(versionPropertyReference, versionEnumFieldReference);
             ctor.Statements.Add(assignVersionStatement);
         }
         ServiceDescription serviceDescription = ImportContext.Binding.ServiceDescription;
         string url = (soapAddress != null) ? soapAddress.Location : null;
         string urlKey = serviceDescription.AppSettingUrlKey;
         string baseUrl = serviceDescription.AppSettingBaseUrl;
         ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, urlKey, baseUrl, soap11 && !ImportContext.IsEncodedBinding);
     }
     else if (ImportContext.Style == ServiceDescriptionImportStyle.Server) {
         ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(WebService).FullName);
     }
 }
 public override object Serialize(IDesignerSerializationManager manager, object value)
 {
     object obj2 = ((CodeDomSerializer) manager.GetSerializer(typeof(ImageList).BaseType, typeof(CodeDomSerializer))).Serialize(manager, value);
     ImageList list = value as ImageList;
     if (list != null)
     {
         StringCollection keys = list.Images.Keys;
         if (!(obj2 is CodeStatementCollection))
         {
             return obj2;
         }
         CodeExpression targetObject = base.GetExpression(manager, value);
         if (targetObject == null)
         {
             return obj2;
         }
         CodeExpression expression2 = new CodePropertyReferenceExpression(targetObject, "Images");
         if (expression2 == null)
         {
             return obj2;
         }
         for (int i = 0; i < keys.Count; i++)
         {
             if ((keys[i] != null) || (keys[i].Length != 0))
             {
                 CodeMethodInvokeExpression expression3 = new CodeMethodInvokeExpression(expression2, "SetKeyName", new CodeExpression[] { new CodePrimitiveExpression(i), new CodePrimitiveExpression(keys[i]) });
                 ((CodeStatementCollection) obj2).Add(expression3);
             }
         }
     }
     return obj2;
 }
 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;
 }
Beispiel #7
0
 public override void HandleBoolean()
 {
     this.proprefContainerField = new CodePropertyReferenceExpression(CodeBuilderCommon.varrefReadValue, "DbusBoolean");
     #if !INHERIT_FROM_INTERFACE
     base.HandleBoolean();
     #endif // !INHERIT_FROM_INTERFACE
 }
		public void Constructor0 ()
		{
			CodePropertyReferenceExpression cpre = new CodePropertyReferenceExpression ();

			Assert.IsNotNull (cpre.PropertyName, "#1");
			Assert.AreEqual (string.Empty, cpre.PropertyName, "#2");
			Assert.IsNull (cpre.TargetObject, "#3");

			string propertyName = "mono";
			cpre.PropertyName = propertyName;
			Assert.IsNotNull (cpre.PropertyName, "#4");
			Assert.AreSame (propertyName, cpre.PropertyName, "#5");

			cpre.PropertyName = null;
			Assert.IsNotNull (cpre.PropertyName, "#6");
			Assert.AreEqual (string.Empty, cpre.PropertyName, "#7");

			CodeExpression expression = new CodeExpression ();
			cpre.TargetObject = expression;
			Assert.IsNotNull (cpre.TargetObject, "#8");
			Assert.AreSame (expression, cpre.TargetObject, "#9");

			cpre.TargetObject = null;
			Assert.IsNull (cpre.TargetObject, "#10");
		}
		protected override void CreateConstructor (CodeStatementCollection localVars,
							CodeStatementCollection trueStmt)
		{
			if (pageParser.ClientTarget != null) {
				CodeExpression prop;
				prop = new CodePropertyReferenceExpression (thisRef, "ClientTarget");
				CodeExpression ct = new CodePrimitiveExpression (pageParser.ClientTarget);
				if (localVars == null)
					localVars = new CodeStatementCollection ();
				localVars.Add (new CodeAssignStatement (prop, ct));
			}

#if NET_2_0
			if (pageParser.MasterPageFile != null) {
				CodeExpression prop;
				prop = new CodePropertyReferenceExpression (thisRef, "MasterPageFile");
				CodeExpression ct = new CodePrimitiveExpression (pageParser.MasterPageFile);
				if (localVars == null)
					localVars = new CodeStatementCollection ();
				localVars.Add (new CodeAssignStatement (prop, ct));
			}
#endif

			base.CreateConstructor (localVars, trueStmt);
		}
		void GenerateXmlType (XmlQualifiedName qname)
		{
			var cns = GetCodeNamespace (qname.Namespace);
			var td = new CodeTypeDeclaration () {
				Name = GetUniqueName (CodeIdentifier.MakeValid (qname.Name), cns),
				TypeAttributes = GenerateInternal ? TypeAttributes.NotPublic : TypeAttributes.Public,
				IsPartial = true };
			cns.Types.Add (td);
			td.BaseTypes.Add (new CodeTypeReference (typeof (IXmlSerializable)));

			var thisNodes = new CodePropertyReferenceExpression (new CodeThisReferenceExpression (), "Nodes"); // property this.Nodes
			var xmlSerializableServices = new CodeTypeReferenceExpression (typeof (XmlSerializableServices)); // static XmlSerializableServices.
			var qnameType = new CodeTypeReference (typeof (XmlQualifiedName));

			// XmlQualifiedName qname = new XmlQualifiedName ({qname.Name}, {qname.Namespace});
			td.Members.Add (new CodeMemberField () { Name = "qname", Type = qnameType, InitExpression = new CodeObjectCreateExpression (qnameType, new CodePrimitiveExpression (qname.Name), new CodePrimitiveExpression (qname.Namespace)) });

			// public XmlNode[] Nodes { get; set; }
			td.Members.Add (new CodeMemberProperty () { Name = "Nodes", Type = new CodeTypeReference (typeof (XmlNode [])), Attributes = (GenerateInternal ? MemberAttributes.Assembly : MemberAttributes.Public) | MemberAttributes.Final, HasGet = true, HasSet = true });

			// public void ReadXml(XmlReader reader) {
			var read = new CodeMemberMethod () { Name = "ReadXml", Attributes = (GenerateInternal ? MemberAttributes.Assembly : MemberAttributes.Public) | MemberAttributes.Final };
			read.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference (typeof (XmlReader)), "reader"));
			//   this.Nodes = XmlSerializableServices.ReadXml(reader);
			read.Statements.Add (
				new CodeAssignStatement (thisNodes,
					new CodeMethodInvokeExpression (
						new CodeMethodReferenceExpression (xmlSerializableServices, "ReadXml"),
						new CodeArgumentReferenceExpression ("reader"))));
			// }
			td.Members.Add (read);

			// public void WriteXml(XmlWriter writer) {
			var write = new CodeMemberMethod () { Name = "WriteXml",Attributes = (GenerateInternal ? MemberAttributes.Assembly : MemberAttributes.Public) | MemberAttributes.Final };
			write.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference (typeof (XmlWriter)), "writer"));
			//   XmlSerializableServices.WriteXml(writer, this.Nodes);
			write.Statements.Add (
				new CodeMethodInvokeExpression (
					new CodeMethodReferenceExpression (xmlSerializableServices, "WriteXml"),
					new CodeArgumentReferenceExpression ("writer"),
					thisNodes));
			// }
			td.Members.Add (write);

			// public XmlSchema GetSchema () { return null; }
			var getSchema = new CodeMemberMethod () { Name = "GetSchema", Attributes = (GenerateInternal ? MemberAttributes.Assembly : MemberAttributes.Public) | MemberAttributes.Final, ReturnType = new CodeTypeReference (typeof (XmlSchema)) };
			getSchema.Statements.Add (new CodeMethodReturnStatement (new CodePrimitiveExpression (null)));
			td.Members.Add (getSchema);

			// public static XmlQualifiedName ExportSchema (XmlSchemaSet schemas) {
			var export = new CodeMemberMethod () { Name = "ExportSchema", Attributes = (GenerateInternal ? MemberAttributes.Assembly : MemberAttributes.Public) | MemberAttributes.Final | MemberAttributes.Static, ReturnType = qnameType };
			export.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference (typeof (XmlSchemaSet)), "schemas"));
			//   XmlSerializableServices.AddDefaultSchema (schemas);
			export.Statements.Add (new CodeMethodInvokeExpression (xmlSerializableServices, "AddDefaultSchema", new CodeArgumentReferenceExpression ("schemas")));
			//   return qname;
			export.Statements.Add (new CodeMethodReturnStatement (new CodeFieldReferenceExpression (new CodeThisReferenceExpression (), "qname")));
			// }
			td.Members.Add (export);
		}
 private void BuildAddContentPlaceHolderNames(CodeMemberMethod method, string placeHolderID)
 {
     CodePropertyReferenceExpression targetObject = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "ContentPlaceHolders");
     CodeExpressionStatement statement = new CodeExpressionStatement {
         Expression = new CodeMethodInvokeExpression(targetObject, "Add", new CodeExpression[] { new CodePrimitiveExpression(placeHolderID.ToLower(CultureInfo.InvariantCulture)) })
     };
     method.Statements.Add(statement);
 }
		public void Constructor0_Deny_Unrestricted ()
		{
			CodePropertyReferenceExpression cpre = new CodePropertyReferenceExpression ();
			Assert.AreEqual (String.Empty, cpre.PropertyName, "PropertyName");
			cpre.PropertyName = "mono";
			Assert.IsNull (cpre.TargetObject, "TargetObject");
			cpre.TargetObject = new CodeExpression ();
		}
		public override string GetClassCodeForProcessingRun ()
		{
			var hostProp = new CodePropertyReferenceExpression (new CodeThisReferenceExpression (), "Host");
			return TemplatingEngine.GenerateIndentedClassCode (
				languageProvider,
				CreateIsTrueMethod (hostProp),
				CreateTagsProperty (hostProp)
			);
		}
 public static CodePropertyReferenceExpression Clone(this CodePropertyReferenceExpression expression)
 {
     if (expression == null) return null;
     CodePropertyReferenceExpression e = new CodePropertyReferenceExpression();
     e.PropertyName = expression.PropertyName;
     e.TargetObject = expression.TargetObject.Clone();
     e.UserData.AddRange(expression.UserData);
     return e;
 }
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeExpression target = new CodeExpression ();
			CodePropertyReferenceExpression cpre = new CodePropertyReferenceExpression (target, "mono");
			Assert.AreEqual ("mono", cpre.PropertyName, "PropertyName");
			cpre.PropertyName = String.Empty;
			Assert.AreSame (target, cpre.TargetObject, "TargetObject");
			cpre.TargetObject = new CodeExpression ();
		}
 public TypescriptPropertyReferenceExpression(
     IExpressionFactory expressionFactory, 
     CodePropertyReferenceExpression codeExpression, 
     CodeGeneratorOptions options)
 {
     _expressionFactory = expressionFactory;
     _codeExpression = codeExpression;
     _options = options;
     System.Diagnostics.Debug.WriteLine("TypescriptPropertyReferenceExpression Created");
 }
        public override void Generate(CodeObject codeObject, Entity entity)
        {
            var propNode = (CodeMemberProperty) codeObject;
            var property = (GenericProperty) entity;

            var contentRef = new CodePropertyReferenceExpression(null, "Content");
            var getPropertyValueMethod = new CodeMethodReferenceExpression(contentRef, "GetPropertyValue", propNode.Type);
            var getPropertyValueCall = new CodeMethodInvokeExpression(getPropertyValueMethod, new CodePrimitiveExpression(property.Alias));
            propNode.GetStatements.Add(new CodeMethodReturnStatement(getPropertyValueCall));
        }
 internal static CodeExpression BuildPropertyReferenceExpression(CodeExpression objRefExpr, string propName)
 {
     string[] strArray = propName.Split(new char[] { '.' });
     CodeExpression targetObject = objRefExpr;
     foreach (string str in strArray)
     {
         targetObject = new CodePropertyReferenceExpression(targetObject, str);
     }
     return targetObject;
 }
Beispiel #19
0
		protected override void AddStatementsToInitMethodTop (ControlBuilder builder, CodeMemberMethod method)
		{
			base.AddStatementsToInitMethodTop (builder, method);
			if (parser.MasterPageFile != null) {
				CodeExpression prop;
				prop = new CodePropertyReferenceExpression (new CodeArgumentReferenceExpression("__ctrl"), "MasterPageFile");
				CodeExpression ct = new CodePrimitiveExpression (parser.MasterPageFile);
				method.Statements.Add (AddLinePragma (new CodeAssignStatement (prop, ct), parser.DirectiveLocation));
			}
		}
 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));
             }
         }
     }
 }
        protected override void ParseElement(XElement element)
        {
            if (!m_firstElement)
                throw new InvalidOperationException();

            var objectParser = new ObjectParser(State);
            objectParser.Parse(element);

            var left = new CodePropertyReferenceExpression(
                new CodeVariableReferenceExpression(Parent.VariableName), Name);
            var right = new CodeVariableReferenceExpression(objectParser.VariableName);
            var assignment = new CodeAssignStatement(left, right);
            State.AddStatement(assignment);
        }
        public override void SetTestInitializeMethod(TestClassGenerationContext generationContext)
        {
            base.SetTestInitializeMethod(generationContext);

            // SenarioContext.Current.SetTestInstance(this);
            var scenarioContext = new CodeTypeReferenceExpression("ScenarioContext");
            var currentContext = new CodePropertyReferenceExpression(scenarioContext, "Current");
            var scenarioContextExtensions = new CodeTypeReferenceExpression("ScenarioContextExtensions");
            var setTestInstance = new CodeMethodInvokeExpression(scenarioContextExtensions, "SetTestInstance",
                currentContext, new CodeThisReferenceExpression());

            // Add it to ScenarioSetup
            generationContext.ScenarioInitializeMethod.Statements.Add(new CodeExpressionStatement(setTestInstance));
        }
		private void SerializeNormalProperty (IDesignerSerializationManager manager, 
											  object value, PropertyDescriptor descriptor, CodeStatementCollection statements)
		{
			CodeExpression leftSide = base.SerializeToExpression (manager, value);
			CodeExpression rightSide = null;

			MemberRelationship relationship = GetRelationship (manager, value, descriptor);
			if (!relationship.IsEmpty) 
				rightSide = new CodePropertyReferenceExpression (base.SerializeToExpression (manager, relationship.Owner), 
																 relationship.Member.Name);
			else
				rightSide = base.SerializeToExpression (manager, descriptor.GetValue (value));

			statements.Add (new CodeAssignStatement (leftSide, rightSide));
		}
		static CodeTypeMember CreateIsTrueMethod (CodePropertyReferenceExpression hostProp)
		{
			var stringTypeRef = new CodeTypeReference (typeof(string));
			var boolTypeRef = new CodeTypeReference (typeof(bool));
			var meth = new CodeMemberMethod { Name = "IsTrue" };
			meth.Parameters.Add (new CodeParameterDeclarationExpression (stringTypeRef, "key"));
			meth.ReturnType = boolTypeRef;
			meth.Statements.Add (
				new CodeMethodReturnStatement (
					new CodeMethodInvokeExpression (
						hostProp, "IsTrue", new CodeArgumentReferenceExpression (meth.Parameters[0].Name)
					)
				)
			);
			return meth;
		}
Beispiel #25
0
        public void SetNodeValue(XmlNode n)
        {
            for (int i = 0; i < n.Attributes.Count; i++)
            {
                string value = n.Attributes[i].Value;

                //AddField(n.Attributes[i].Name, value, MemberAttributes.Private);
                fieldList.Add(new ItemField(n.Attributes[i].Name, value, MemberAttributes.Private));

                ItemProperty item = new ItemProperty(n.Attributes[i].Name);
                item.SetGetName();
                item.SetValueType(value);
                item.SetModifier(MemberAttributes.Public | MemberAttributes.Final);
                propertyList.Add(item);

                CodeConditionStatement condition = new CodeConditionStatement();
                condition.Condition = new CodeVariableReferenceExpression("inArg0.ContainsKey(\"" + n.Attributes[i].Name + "\")");

                string parseLeft = "";
                string parseRight = "";
                if (Stringer.IsNumber(value))
                {
                    parseLeft = value.Contains(".") ? "float.Parse(" : "uint.Parse(";
                    parseRight = ")";
                }
                CodeVariableReferenceExpression right = new CodeVariableReferenceExpression(parseLeft + "inArg0[\"" + n.Attributes[i].Name + "\"]" + parseRight);
                CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "_" + Stringer.FirstLetterLower(n.Attributes[i].Name));

                if (Stringer.IsNumber(value))
                {
                    CodeConditionStatement numCondition = new CodeConditionStatement();
                    numCondition.Condition = new CodeVariableReferenceExpression("inArg0[\"" + n.Attributes[i].Name + "\"] == \"\"");

                    numCondition.TrueStatements.Add(new CodeAssignStatement(left, new CodeVariableReferenceExpression("0")));
                    numCondition.FalseStatements.Add(new CodeAssignStatement(left, right));

                    condition.TrueStatements.Add(numCondition);
                }
                else
                {
                    condition.TrueStatements.Add(new CodeAssignStatement(left, right));
                }

                AddConditionStatement(condition);
            }
            Create();
        }
Beispiel #26
0
		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);
			}
		}
		private void SerializeNormalProperty (IDesignerSerializationManager manager, 
											  object component, PropertyDescriptor descriptor, CodeStatementCollection statements)
		{
			CodeAssignStatement assignment = new CodeAssignStatement ();

			CodeExpression leftSide = null;
			CodePropertyReferenceExpression propRef = null;
			ExpressionContext expression = manager.Context[typeof (ExpressionContext)] as ExpressionContext;
			RootContext root = manager.Context[typeof (RootContext)] as RootContext;

			if (expression != null && expression.PresetValue == component && expression.Expression != null) {
				leftSide = new CodePropertyReferenceExpression (expression.Expression, descriptor.Name);
			} else if (root != null && root.Value == component) {
				leftSide = new CodePropertyReferenceExpression (root.Expression, descriptor.Name);
			} else {
				propRef = new CodePropertyReferenceExpression ();
				propRef.PropertyName =  descriptor.Name;
				propRef.TargetObject = TryGetCachedExpression (manager, component, propRef);
				leftSide = propRef;
			}

			CodeExpression rightSide = null;

			MemberRelationship relationship = GetRelationship (manager, component, descriptor);
			if (!relationship.IsEmpty) {
				propRef = new CodePropertyReferenceExpression ();
				propRef.PropertyName = relationship.Member.Name;
				propRef.TargetObject = TryGetCachedExpression (manager, relationship.Owner, propRef);
				rightSide = propRef;
			} else {
				object rightSideValue = descriptor.GetValue (component);
				rightSide = TryGetCachedExpression (manager, rightSideValue, null, component);
			}

			if (rightSide == null) {
				Console.WriteLine ("SerializeNormalProperty: <" + component.GetType().Name + "." +
								   descriptor.Name + "> - unable to serialize the right side of the assignment to expression");
			} else if (leftSide == null) {
				Console.WriteLine ("SerializeNormalProperty: <" + component.GetType().Name + "." +
								   descriptor.Name + "> - unable to serialize the left side of the assignment to expression");
			} else  {
				assignment.Left = leftSide;
				assignment.Right = rightSide;
				statements.Add (assignment);
			}
		}
        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);
        }
Beispiel #29
0
        protected CodeExpression GetMappedProperty(CodeExpression targetObj)
        {
            CodePropertyReferenceExpression property = new CodePropertyReferenceExpression(targetObj, MappedProperty.Name);
            if (IsCollection(_mappedProperty.PropertyType))
            {
                return new CodeIndexerExpression(property,
                    new CodeBinaryOperatorExpression(
                        new CodePropertyReferenceExpression(property, "Count"), 
                        CodeBinaryOperatorType.Subtract, new CodePrimitiveExpression(1)));

            }

            if (_mappedProperty.PropertyType.IsArray)
                return new CodeIndexerExpression(property, new CodePrimitiveExpression(_index));

            return property;
        }
		public void Constructor1 ()
		{
			CodeExpression expression = new CodeExpression ();
			string propertyName = "mono";

			CodePropertyReferenceExpression cpre = new CodePropertyReferenceExpression (
				expression, propertyName);
			Assert.IsNotNull (cpre.PropertyName, "#1");
			Assert.AreSame (propertyName, cpre.PropertyName, "#2");
			Assert.IsNotNull (cpre.TargetObject, "#3");
			Assert.AreSame (expression, cpre.TargetObject, "#4");

			cpre = new CodePropertyReferenceExpression ((CodeExpression) null,
				(string) null);
			Assert.IsNotNull (cpre.PropertyName, "#5");
			Assert.AreEqual (string.Empty, cpre.PropertyName, "#6");
			Assert.IsNull (cpre.TargetObject, "#7");
		}
Beispiel #31
0
 protected override void GeneratePropertyReferenceExpression(System.CodeDom.CodePropertyReferenceExpression e)
 {
     GenerateExpression(e.TargetObject);
     Output.Write(".");
     Output.Write(e.PropertyName);
 }