Inheritance: System.CodeDom.CodeExpression
		public void Constructor0 ()
		{
			CodeMethodReferenceExpression cmre = new CodeMethodReferenceExpression ();

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

#if NET_2_0
			Assert.IsNotNull (cmre.TypeArguments, "#4");
			Assert.AreEqual (0, cmre.TypeArguments.Count, "#5");
#endif

			string methodName = "mono";
			cmre.MethodName = methodName;
			Assert.IsNotNull (cmre.MethodName, "#6");
			Assert.AreSame (methodName, cmre.MethodName, "#7");

			cmre.MethodName = null;
			Assert.IsNotNull (cmre.MethodName, "#8");
			Assert.AreEqual (string.Empty, cmre.MethodName, "#9");

			CodeExpression expression = new CodeExpression ();
			cmre.TargetObject = expression;
			Assert.IsNotNull (cmre.TargetObject, "#10");
			Assert.AreSame (expression, cmre.TargetObject, "#11");

			cmre.TargetObject = null;
			Assert.IsNull (cmre.TargetObject, "#12");
		}
		public CodeMethodInvokeExpression (CodeExpression targetObject,
						   string methodName,
						   params CodeExpression [] parameters)
		{
			this.method = new CodeMethodReferenceExpression( targetObject, methodName );
			this.Parameters.AddRange (parameters);
		}
Exemplo n.º 3
0
        public override CodeExpression GCode_CodeDom_GetValue(CodeGenerateSystem.Base.LinkControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            RefreshValueFromTemplateClass2PropertyInfoList();
            if (element == mCtrlreturnLink)
            {
                var info = GetLinkObjInfo(mCtrlparamLink);

                string value = "CSUtility.Data.DataTemplateManager<";
                value += mParamType.FullName + ", " + mReturnType.FullName + ">.Instance";

                System.CodeDom.CodeMethodReferenceExpression methodRef = new System.CodeDom.CodeMethodReferenceExpression();
                methodRef.TargetObject = new System.CodeDom.CodeSnippetExpression(value);
                methodRef.MethodName   = "GetDataTemplate";

                CodeExpression[] exps = new CodeExpression[1];
                if (info.HasLink)
                {
                    var ep = info.GetLinkObject(0, true).GCode_CodeDom_GetValue(info.GetLinkElement(0, true), context);
                    exps[0] = ep;
                }
                else
                {
                    foreach (var proInfo in mCustomPropertyInfos)
                    {
                        if (proInfo.PropertyName == "Id")
                        {
                            exps[0] = new CodePrimitiveExpression(proInfo.CurrentValue);
                            break;
                        }
                    }
                }
                return(new System.CodeDom.CodeMethodInvokeExpression(methodRef, exps));
            }
            return(base.GCode_CodeDom_GetValue(element, context));
        }
		public void Constructor0 ()
		{
			CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression ();
			Assert.IsNotNull (cmie.Method, "#1");
			Assert.AreEqual (string.Empty, cmie.Method.MethodName, "#2");
			Assert.IsNull (cmie.Method.TargetObject, "#3");
#if NET_2_0
			Assert.AreEqual (0, cmie.Method.TypeArguments.Count, "#4");
#endif
			Assert.IsNotNull (cmie.Parameters, "#5");
			Assert.AreEqual (0, cmie.Parameters.Count, "#6");

			CodeMethodReferenceExpression method = new CodeMethodReferenceExpression ();
			cmie.Method = method;
			Assert.IsNotNull (cmie.Method, "#7");
			Assert.AreSame (method, cmie.Method, "#8");

			cmie.Method = null;
			Assert.IsNotNull (cmie.Method, "#9");
			Assert.AreEqual (string.Empty, cmie.Method.MethodName, "#10");
			Assert.IsNull (cmie.Method.TargetObject, "#11");
#if NET_2_0
			Assert.AreEqual (0, cmie.Method.TypeArguments.Count, "#12");
#endif
		}
        protected override CodeMemberMethod CreateService(CodeTypeReference typerefWCFService, CodeTypeReference typerefService)
        {
            CodeTypeReferenceExpression typerefexprService = new CodeTypeReferenceExpression(typerefService);
            CodeMethodReferenceExpression methodrefDbusServiceCreate = new CodeMethodReferenceExpression(typerefexprService, "Create");

            CodeMemberMethod methodCreateService = new CodeMemberMethod();
            methodCreateService.Name = CreateServiceName;
            methodCreateService.ReturnType = typerefWCFService;
            methodCreateService.Attributes = MemberAttributes.Static;
            methodCreateService.Parameters.Add(new CodeParameterDeclarationExpression(CodeBuilderCommon.typerefWCFServiceParams, nameWCFServiceParamsArg));
            CodeMethodReferenceExpression methodrefCreateDbusService = new CodeMethodReferenceExpression(CodeBuilderCommon.typerefexprLookupTargetFunctions, CodeBuilderCommon.CreateDbusService);
            methodrefCreateDbusService.TypeArguments.Add(typerefService);

            methodCreateService.Statements.Add(new CodeVariableDeclarationStatement(typerefService, dbusService, // * <dbus_service> dbusService =
                new CodeMethodInvokeExpression(methodrefCreateDbusService // * Udbus.WCF.Dbus.Service.LookupTargetFunctions.CreateDbusService(
                    , argrefWCFServiceParams // * wcfserviceparams
                    , methodrefDbusServiceCreate // * , <dbus_service>.Create // createService1
                    , methodrefDbusServiceCreate // * , <dbus_service>.Create // createService2
                    , new CodePropertyReferenceExpression(typerefexprService, CodeBuilderCommon.DefaultConnectionParameters) // * <dbus_service>.DefaultConnectionParameters);
                )
            ));

            // * <wcfservice> wcfService = new <wcfservice>(dbusservice);
            methodCreateService.Statements.Add(new CodeVariableDeclarationStatement(typerefWCFService, wcfService
                , new CodeObjectCreateExpression(typerefWCFService, varrefDbusService)
            ));

            // return wcfService;
            methodCreateService.Statements.Add(new CodeMethodReturnStatement(varrefWcfService));
            return methodCreateService;
        }
		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;
		}
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeMethodReferenceExpression method = new CodeMethodReferenceExpression ();
			CodeExpression[] parameters = new CodeExpression[1] { new CodeExpression () };
			CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression (method, parameters);
			Assert.AreSame (method, cmie.Method, "Method");
			cmie.Method = new CodeMethodReferenceExpression ();
			Assert.AreEqual (1, cmie.Parameters.Count, "Parameters");
		}
        public override void Generate(object codeObject, Entity entity)
        {
            var propNode = (CodeMemberProperty) codeObject;
            var property = (GenericProperty) entity;

            var getPropertyValueMethod = new CodeMethodReferenceExpression(null, "GetValue", propNode.Type);
            var getPropertyValueCall = new CodeMethodInvokeExpression(getPropertyValueMethod, new CodePrimitiveExpression(property.Alias));
            propNode.GetStatements.Add(new CodeMethodReturnStatement(getPropertyValueCall));
        }
		public void Constructor0_Deny_Unrestricted ()
		{
			CodeMethodReferenceExpression cmre = new CodeMethodReferenceExpression ();
			Assert.AreEqual (String.Empty, cmre.MethodName, "MethodName");
			cmre.MethodName = "mono";
			Assert.IsNull (cmre.TargetObject, "TargetObject");
			cmre.TargetObject = new CodeExpression ();
			Assert.AreEqual (0, cmre.TypeArguments.Count, "TypeArguments");
		}
 public override object Serialize(IDesignerSerializationManager manager, object value)
 {
     PropertyDescriptor descriptor = (PropertyDescriptor) manager.Context[typeof(PropertyDescriptor)];
     ExpressionContext context = (ExpressionContext) manager.Context[typeof(ExpressionContext)];
     bool flag = (value != null) ? CodeDomSerializerBase.GetReflectionTypeHelper(manager, value).IsSerializable : true;
     bool flag2 = !flag;
     bool flag3 = (descriptor != null) && descriptor.Attributes.Contains(DesignerSerializationVisibilityAttribute.Content);
     if (!flag2)
     {
         flag2 = ((context != null) && (context.PresetValue != null)) && (context.PresetValue == value);
     }
     if (((this._model == CodeDomLocalizationModel.PropertyReflection) && !flag3) && !flag2)
     {
         CodeStatementCollection statements = (CodeStatementCollection) manager.Context[typeof(CodeStatementCollection)];
         bool flag4 = false;
         ExtenderProvidedPropertyAttribute attribute = null;
         if (descriptor != null)
         {
             attribute = descriptor.Attributes[typeof(ExtenderProvidedPropertyAttribute)] as ExtenderProvidedPropertyAttribute;
             if ((attribute != null) && (attribute.ExtenderProperty != null))
             {
                 flag4 = true;
             }
         }
         if ((!flag4 && (context != null)) && (statements != null))
         {
             string name = manager.GetName(context.Owner);
             CodeExpression expression = base.SerializeToExpression(manager, context.Owner);
             if ((name != null) && (expression != null))
             {
                 RootContext context2 = manager.Context[typeof(RootContext)] as RootContext;
                 if ((context2 != null) && (context2.Value == context.Owner))
                 {
                     name = "$this";
                 }
                 base.SerializeToResourceExpression(manager, value, false);
                 if (this.EmitApplyMethod(manager, context.Owner))
                 {
                     ResourceManager manager2 = manager.Context[typeof(ResourceManager)] as ResourceManager;
                     CodeMethodReferenceExpression expression3 = new CodeMethodReferenceExpression(base.GetExpression(manager, manager2), "ApplyResources");
                     CodeMethodInvokeExpression expression4 = new CodeMethodInvokeExpression {
                         Method = expression3
                     };
                     expression4.Parameters.Add(expression);
                     expression4.Parameters.Add(new CodePrimitiveExpression(name));
                     statements.Add(expression4);
                 }
                 return null;
             }
         }
     }
     if (flag2)
     {
         return this._currentSerializer.Serialize(manager, value);
     }
     return base.SerializeToResourceExpression(manager, value);
 }
 public static CodeMethodReferenceExpression Clone(this CodeMethodReferenceExpression expression)
 {
     if (expression == null) return null;
     CodeMethodReferenceExpression e = new CodeMethodReferenceExpression();
     e.MethodName = expression.MethodName;
     e.TargetObject = expression.TargetObject.Clone();
     e.TypeArguments.AddRange(expression.TypeArguments.Clone());
     e.UserData.AddRange(expression.UserData);
     return e;
 }
 public TypescriptMethodReferenceExpression(
     IExpressionFactory expressionFactory,
     CodeMethodReferenceExpression codeExpression, 
     CodeGeneratorOptions options)
 {
     _expressionFactory = expressionFactory;
     _codeExpression = codeExpression;
     _options = options;
     System.Diagnostics.Debug.WriteLine("TypescriptMethodReferenceExpression Created");
 }
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeExpression target = new CodeExpression ();
			CodeMethodReferenceExpression cmre = new CodeMethodReferenceExpression (target, "mono");
			Assert.AreEqual ("mono", cmre.MethodName, "MethodName");
			cmre.MethodName = String.Empty;
			Assert.AreSame (target, cmre.TargetObject, "TargetObject");
			cmre.TargetObject = new CodeExpression ();
			Assert.AreEqual (0, cmre.TypeArguments.Count, "TypeArguments");
		}
 private static CodeMethodReferenceExpression CloneMethodReference(CodeMethodReferenceExpression oldReference)
 {
     CodeMethodReferenceExpression result = new CodeMethodReferenceExpression {
         MethodName = oldReference.MethodName,
         TargetObject = RuleExpressionWalker.Clone(oldReference.TargetObject)
     };
     foreach (CodeTypeReference reference in oldReference.TypeArguments)
     {
         result.TypeArguments.Add(TypeReferenceExpression.CloneType(reference));
     }
     ConditionHelper.CloneUserData(oldReference, result);
     return result;
 }
Exemplo n.º 15
0
 public Script(string namespaceToGen, string className)
 {
     this.compileUnit = new CodeCompileUnit();
     this.codeNamespace = new CodeNamespace(namespaceToGen);
     this.compileUnit.Namespaces.Add(this.codeNamespace);
     this.codeClass = new CodeTypeDeclaration(className);
     this.codeNamespace.Types.Add(this.codeClass);
     this.proxySetting = ProxySettings.RequiredHeaders;
     this.mainMethod = new CodeEntryPointMethod();
     this.mainMethod.Name = "Main";
     this.mainMethod.Attributes = MemberAttributes.Public | MemberAttributes.Static;
     this.codeClass.Members.Add(this.mainMethod);
     this.dumpMethodRef = this.BuildDumper();
 }
        private CodeThrowExceptionStatement GenerateExceptionStatement(GenerateErrorActivity activity)
        {
            var parameters = DefaultActivityBuilder.GenerateParameters(new List<string> {
                @"""Message : {0}\nMessage code : {1} """
            }, activity);

            CodeMethodInvokeExpression stringFormatCall = new CodeMethodInvokeExpression();
            stringFormatCall.Parameters.AddRange(parameters);

            CodeMethodReferenceExpression formatMethod = new CodeMethodReferenceExpression();
            formatMethod.MethodName = "Format";
            CodeVariableReferenceExpression stringObject = new CodeVariableReferenceExpression();
            stringObject.VariableName = "String";
            formatMethod.TargetObject = stringObject;
            stringFormatCall.Method = formatMethod;
            CodeThrowExceptionStatement throwException = new CodeThrowExceptionStatement(new CodeObjectCreateExpression(new CodeTypeReference(typeof(System.Exception)), stringFormatCall));
            return throwException;
        }
 public override object Serialize(IDesignerSerializationManager manager, object value)
 {
     object obj2 = null;
     StringDictionary dictionary = value as StringDictionary;
     if (dictionary == null)
     {
         return obj2;
     }
     object current = manager.Context.Current;
     ExpressionContext context = current as ExpressionContext;
     if ((context != null) && (context.Owner == value))
     {
         current = context.Expression;
     }
     CodePropertyReferenceExpression targetObject = current as CodePropertyReferenceExpression;
     if (targetObject == null)
     {
         return obj2;
     }
     object component = base.DeserializeExpression(manager, null, targetObject.TargetObject);
     if ((component == null) || (TypeDescriptor.GetProperties(component)[targetObject.PropertyName] == null))
     {
         return obj2;
     }
     CodeStatementCollection statements = new CodeStatementCollection();
     CodeMethodReferenceExpression expression2 = new CodeMethodReferenceExpression(targetObject, "Add");
     foreach (DictionaryEntry entry in dictionary)
     {
         CodeExpression expression3 = base.SerializeToExpression(manager, entry.Key);
         CodeExpression expression4 = base.SerializeToExpression(manager, entry.Value);
         if ((expression3 != null) && (expression4 != null))
         {
             CodeMethodInvokeExpression expression5 = new CodeMethodInvokeExpression {
                 Method = expression2
             };
             expression5.Parameters.Add(expression3);
             expression5.Parameters.Add(expression4);
             statements.Add(expression5);
         }
     }
     return statements;
 }
Exemplo n.º 18
0
		public void Constructor1 ()
		{
			CodeMethodReferenceExpression method1 = new CodeMethodReferenceExpression ();
			CodeExpression param1 = new CodeExpression ();
			CodeExpression param2 = new CodeExpression ();

			CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression (
				method1, param1, param2);
			Assert.IsNotNull (cmie.Method, "#1");
			Assert.AreSame (method1, cmie.Method, "#2");

			cmie.Method = null;
			Assert.IsNotNull (cmie.Method, "#3");
			Assert.AreEqual (string.Empty, cmie.Method.MethodName, "#4");
			Assert.IsNull (cmie.Method.TargetObject, "#5");
#if NET_2_0
			Assert.AreEqual (0, cmie.Method.TypeArguments.Count, "#6");
#endif

			CodeMethodReferenceExpression method2 = new CodeMethodReferenceExpression ();
			cmie.Method = method2;
			Assert.IsNotNull (cmie.Method, "#7");
			Assert.AreSame (method2, cmie.Method, "#8");

			Assert.IsNotNull (cmie.Parameters, "#9");
			Assert.AreEqual (2, cmie.Parameters.Count, "#10");
			Assert.AreEqual (0, cmie.Parameters.IndexOf (param1), "#11");
			Assert.AreEqual (1, cmie.Parameters.IndexOf (param2), "#12");

			cmie = new CodeMethodInvokeExpression ((CodeMethodReferenceExpression) null, 
				param2);
			Assert.IsNotNull (cmie.Method, "#13");
			Assert.AreEqual (string.Empty, cmie.Method.MethodName, "#14");
			Assert.IsNull (cmie.Method.TargetObject, "#15");
#if NET_2_0
			Assert.AreEqual (0, cmie.Method.TypeArguments.Count, "#16");
#endif

			Assert.IsNotNull (cmie.Parameters, "#17");
			Assert.AreEqual (1, cmie.Parameters.Count, "#18");
			Assert.AreEqual (0, cmie.Parameters.IndexOf (param2), "#19");
		}
Exemplo n.º 19
0
        private CodeMethodInvokeExpression GenerateLoggerCodeInvocation(WriteToLogActivity activity)
        {
            var parameters = DefaultActivityBuilder.GenerateParameters(new List<string> {
                @"""Message : {0}\nMessage code : {1} """
            }, activity);

            CodeMethodInvokeExpression stringFormatCall = new CodeMethodInvokeExpression();
            stringFormatCall.Parameters.AddRange(parameters);

            CodeMethodReferenceExpression formatMethod = new CodeMethodReferenceExpression();
            formatMethod.MethodName = "Format";
            CodeVariableReferenceExpression stringObject = new CodeVariableReferenceExpression();
            stringObject.VariableName = "String";
            formatMethod.TargetObject = stringObject;
            stringFormatCall.Method = formatMethod;

            var loggerReference = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), VariableHelper.ToVariableName("logger"));
            var methodInvocation = new CodeMethodInvokeExpression(loggerReference, activity.Role, stringFormatCall);
            return methodInvocation;
        }
		public void Constructor1 ()
		{
			CodeExpression expression = new CodeExpression ();
			string methodName = "mono";

			CodeMethodReferenceExpression cmre = new CodeMethodReferenceExpression (
				expression, methodName);
			Assert.IsNotNull (cmre.MethodName, "#1");
			Assert.AreSame (methodName, cmre.MethodName, "#2");
			Assert.IsNotNull (cmre.TargetObject, "#3");
			Assert.AreSame (expression, cmre.TargetObject, "#4");

			Assert.IsNotNull (cmre.TypeArguments, "#5");
			Assert.AreEqual (0, cmre.TypeArguments.Count, "#6");

			cmre = new CodeMethodReferenceExpression ((CodeExpression) null,
				(string) null);
			Assert.IsNotNull (cmre.MethodName, "#7");
			Assert.AreEqual (string.Empty, cmre.MethodName, "#8");
			Assert.IsNull (cmre.TargetObject, "#9");
		}
 internal void GenerateOverrideMatchedHeaders(CodeTypeDeclaration typeDeclaration)
 {
     CodeMemberMethod method = new CodeMemberMethod {
         Name = "PopulateMatchedHeaders",
         Attributes = MemberAttributes.Family | MemberAttributes.Override,
         ReturnType = new CodeTypeReference(typeof(void))
     };
     CodeParameterDeclarationExpression expression = new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(IDictionary)), "dictionary");
     method.Parameters.Add(expression);
     typeDeclaration.Members.Add(method);
     CodeMethodReferenceExpression expression2 = new CodeMethodReferenceExpression(new CodeBaseReferenceExpression(), "PopulateMatchedHeaders");
     CodeMethodInvokeExpression expression3 = new CodeMethodInvokeExpression(expression2, new CodeExpression[] { this._dictionaryRefExpr });
     method.Statements.Add(expression3);
     foreach (string str in (IEnumerable) this._headers)
     {
         CodeAssignStatement statement = new CodeAssignStatement {
             Left = new CodeIndexerExpression(this._dictionaryRefExpr, new CodeExpression[] { new CodePrimitiveExpression(str) }),
             Right = new CodePrimitiveExpression(null)
         };
         method.Statements.Add(statement);
     }
 }
 internal void GenerateOverrideBrowserElements(CodeTypeDeclaration typeDeclaration)
 {
     if (this._browserDefinitionCollection != null)
     {
         CodeMemberMethod method = new CodeMemberMethod {
             Name = "PopulateBrowserElements",
             Attributes = MemberAttributes.Family | MemberAttributes.Override,
             ReturnType = new CodeTypeReference(typeof(void))
         };
         CodeParameterDeclarationExpression expression = new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(IDictionary)), "dictionary");
         method.Parameters.Add(expression);
         typeDeclaration.Members.Add(method);
         CodeMethodReferenceExpression expression2 = new CodeMethodReferenceExpression(new CodeBaseReferenceExpression(), "PopulateBrowserElements");
         CodeMethodInvokeExpression expression3 = new CodeMethodInvokeExpression(expression2, new CodeExpression[] { this._dictionaryRefExpr });
         method.Statements.Add(expression3);
         foreach (BrowserDefinition definition in this._browserDefinitionCollection)
         {
             if (definition.IsDeviceNode)
             {
                 CodeAssignStatement statement = new CodeAssignStatement {
                     Left = new CodeIndexerExpression(this._dictionaryRefExpr, new CodeExpression[] { new CodePrimitiveExpression(definition.ID) }),
                     Right = new CodeObjectCreateExpression(typeof(Triplet), new CodeExpression[] { new CodePrimitiveExpression(definition.ParentName), new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(typeof(string)), "Empty"), new CodePrimitiveExpression(definition.Depth) })
                 };
                 method.Statements.Add(statement);
             }
         }
         for (int i = 0; i < this._customTreeNames.Count; i++)
         {
             foreach (BrowserDefinition definition2 in (BrowserDefinitionCollection) this._customBrowserDefinitionCollections[i])
             {
                 if (definition2.IsDeviceNode)
                 {
                     CodeAssignStatement statement2 = new CodeAssignStatement {
                         Left = new CodeIndexerExpression(this._dictionaryRefExpr, new CodeExpression[] { new CodePrimitiveExpression(definition2.ID) }),
                         Right = new CodeObjectCreateExpression(typeof(Triplet), new CodeExpression[] { new CodePrimitiveExpression(definition2.ParentName), new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(typeof(string)), "Empty"), new CodePrimitiveExpression(definition2.Depth) })
                     };
                     method.Statements.Add(statement2);
                 }
             }
         }
     }
 }
 private void ReturnIfHeaderValueEmpty(CodeMemberMethod cmm, CodeVariableReferenceExpression varExpr)
 {
     CodeConditionStatement statement = new CodeConditionStatement();
     CodeMethodReferenceExpression method = new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(string)), "IsNullOrEmpty");
     CodeMethodInvokeExpression expression2 = new CodeMethodInvokeExpression(method, new CodeExpression[] { varExpr });
     statement.Condition = expression2;
     statement.TrueStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(false)));
     cmm.Statements.Add(statement);
 }
Exemplo n.º 24
0
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public CodeMethodInvokeExpression(CodeExpression targetObject, string methodName, params CodeExpression[] parameters)
 {
     this.method = new CodeMethodReferenceExpression(targetObject, methodName);
     Parameters.AddRange(parameters);
 }
Exemplo n.º 25
0
 /// <devdoc>
 ///    <para>
 ///       Initializes a new instance of <see cref='System.CodeDom.CodeMethodInvokeExpression'/> using the specified target object, method name
 ///       and parameters.
 ///    </para>
 /// </devdoc>
 public CodeMethodInvokeExpression(CodeMethodReferenceExpression method, params CodeExpression[] parameters)
 {
     this.method = method;
     Parameters.AddRange(parameters);
 }
		protected override void GenerateMethodReferenceExpression(CodeMethodReferenceExpression e)
		{
			Output.Write("[CodeMethodReferenceExpression: Name={0}, Target=", e.MethodName);
			this.GenerateExpression(e.TargetObject);
			Output.Write("]");
		}
Exemplo n.º 27
0
 private CodeMethodInvokeExpression GenerateInvokeCallOnJavaClass(CodeVariableReferenceExpression javaClassReference)
 {
     CodeMethodInvokeExpression invokeCall = new CodeMethodInvokeExpression();
     invokeCall.Parameters.AddRange(new CodeExpression[0]);
     CodeMethodReferenceExpression invokeMethod = new CodeMethodReferenceExpression();
     invokeMethod.MethodName = InvokeMethodName;
     invokeMethod.TargetObject = javaClassReference;
     invokeCall.Method = invokeMethod;
     return invokeCall;
 }
Exemplo n.º 28
0
 public CodeMethodInvokeExpression(CodeMethodReferenceExpression method, params CodeExpression[] parameters)
 {
     this.parameters = new CodeExpressionCollection();
     this.method     = method;
     this.Parameters.AddRange(parameters);
 }
Exemplo n.º 29
0
 public CodeMethodInvokeExpression(ILInstruction inline, CodeExpression targetObject, string methodName, params CodeExpression[] parameters) : base(inline)
 {
     _method = new CodeMethodReferenceExpression(inline, targetObject, methodName);
     Parameters.AddRange(parameters);
 }
Exemplo n.º 30
0
		protected override void AddStatementsToFrameworkInitialize (CodeMemberMethod method)
		{
			string responseEncoding = pageParser.ResponseEncoding;
			if (responseEncoding != null)
				method.Statements.Add (CreatePropertyAssign ("ResponseEncoding", responseEncoding));
			
			int codepage = pageParser.CodePage;
			if (codepage != -1)
				method.Statements.Add (CreatePropertyAssign ("CodePage", codepage));

			string contentType = pageParser.ContentType;
			if (contentType != null)
				method.Statements.Add (CreatePropertyAssign ("ContentType", contentType));

			if (pageParser.OutputCache) {
				CodeMethodReferenceExpression init = new CodeMethodReferenceExpression (null,
						"InitOutputCache");
				CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (init,
						OutputCacheParams ());
				method.Statements.Add (invoke);
			}
			
			int lcid = pageParser.LCID;
			if (lcid != -1)
				method.Statements.Add (CreatePropertyAssign ("LCID", lcid));

			string culture = pageParser.Culture;
			if (culture != null)
				method.Statements.Add (CreatePropertyAssign ("Culture", culture));

			culture = pageParser.UICulture;
			if (culture != null)
				method.Statements.Add (CreatePropertyAssign ("UICulture", culture));

			string errorPage = pageParser.ErrorPage;
			if (errorPage != null)
				method.Statements.Add (CreatePropertyAssign ("ErrorPage", errorPage));

                        if (pageParser.HaveTrace) {
                                CodeAssignStatement stmt = new CodeAssignStatement ();
                                stmt.Left = new CodePropertyReferenceExpression (thisRef, "TraceEnabled");
                                stmt.Right = new CodePrimitiveExpression (pageParser.Trace);
                                method.Statements.Add (stmt);
                        }

                        if (pageParser.TraceMode != TraceMode.Default) {
                                CodeAssignStatement stmt = new CodeAssignStatement ();
                                CodeTypeReferenceExpression tm = new CodeTypeReferenceExpression ("System.Web.TraceMode");
                                stmt.Left = new CodePropertyReferenceExpression (thisRef, "TraceModeValue");
                                stmt.Right = new CodeFieldReferenceExpression (tm, pageParser.TraceMode.ToString ());
                                method.Statements.Add (stmt);
                        }

                        if (pageParser.NotBuffer) {
                                CodeAssignStatement stmt = new CodeAssignStatement ();
                                stmt.Left = new CodePropertyReferenceExpression (thisRef, "Buffer");
                                stmt.Right = new CodePrimitiveExpression (false);
                                method.Statements.Add (stmt);
                        }

#if NET_1_1
			if (pageParser.ValidateRequest) {
				CodeMethodInvokeExpression expr = new CodeMethodInvokeExpression ();
                                CodePropertyReferenceExpression prop;
                                prop = new CodePropertyReferenceExpression (thisRef, "Request");
				expr.Method = new CodeMethodReferenceExpression (prop, "ValidateInput");
				method.Statements.Add (expr);
			}
#endif
                        
			base.AddStatementsToFrameworkInitialize (method);
		}
        private static void AddEntityOptionSetEnumDeclaration(CodeTypeDeclarationCollection types)
        {
            var enumClass = new CodeTypeDeclaration("EntityOptionSetEnum")
            {
                IsClass = true,
                TypeAttributes = TypeAttributes.Sealed | TypeAttributes.NotPublic,
            };

            // public static int? GetEnum(Microsoft.Xrm.Sdk.Entity entity, string attributeLogicalName)
            var get = new CodeMemberMethod
            {
                Name = "GetEnum",
                ReturnType = new CodeTypeReference(typeof(int?)),
                // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
                Attributes = System.CodeDom.MemberAttributes.Static | System.CodeDom.MemberAttributes.Public,
            };
            get.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Microsoft.Xrm.Sdk.Entity), "entity"));
            get.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "attributeLogicalName"));

            // entity.Attributes.ContainsKey(attributeLogicalName)
            var entityAttributesContainsKey =
                new CodeMethodReferenceExpression(
                    new CodePropertyReferenceExpression(
                        new CodeArgumentReferenceExpression("entity"),
                        "Attributes"),
                    "ContainsKey");
            var invokeContainsKey = new CodeMethodInvokeExpression(entityAttributesContainsKey, new CodeArgumentReferenceExpression("attributeLogicalName"));

            // Microsoft.Xrm.Sdk.OptionSetValue value = entity.GetAttributeValue<Microsoft.Xrm.Sdk.OptionSetValue>(attributeLogicalName).Value;
            var declareAndSetValue =
                new CodeVariableDeclarationStatement
                {
                    Type = new CodeTypeReference(typeof(OptionSetValue)),
                    Name = "value",
                    InitExpression = new CodeMethodInvokeExpression(
                        new CodeMethodReferenceExpression(
                            new CodeArgumentReferenceExpression("entity"), "GetAttributeValue", new CodeTypeReference(typeof(OptionSetValue))),
                            new CodeArgumentReferenceExpression("attributeLogicalName"))
                };

            // value != null
            var valueNeNull = new CodeSnippetExpression("value != null");

            // value.Value
            var invokeValueGetValue = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("value"), "Value");

            // if(invokeContainsKey){return invokeGetAttributeValue;}else{return null}
            get.Statements.Add(new CodeConditionStatement(invokeContainsKey, declareAndSetValue, 
                new CodeConditionStatement(valueNeNull, new CodeMethodReturnStatement(invokeValueGetValue))));

            // return null;
            get.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null)));

            enumClass.Members.Add(get);

            types.Add(enumClass);
        }
Exemplo n.º 32
0
        private CodeStatementCollection GenerateInputCallOnJavaClass(JavaActivity javaActivity, CodeVariableReferenceExpression javaClassReference)
        {
            var invocationCodeCollection = new CodeStatementCollection();
            foreach (var parameter in javaActivity.Parameters)
            {
                CodeMethodInvokeExpression setterCall = new CodeMethodInvokeExpression();
                setterCall.Parameters.AddRange(new List<CodeExpression> {
                    new CodeSnippetExpression(parameter.Name)
                }.ToArray());
                CodeMethodReferenceExpression setterMethod = new CodeMethodReferenceExpression();
                setterMethod.MethodName = "set" + parameter.Name;
                setterMethod.TargetObject = javaClassReference;
                setterCall.Method = setterMethod;
                invocationCodeCollection.Add(setterCall);
            }

            return invocationCodeCollection;
        }
 public CodeMethodInvokeExpression(CodeMethodReferenceExpression method, params CodeExpression[] parameters)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 34
0
        private CodeStatementCollection GenerateOutputCallOnJavaClass(JavaActivity javaActivity, CodeVariableReferenceExpression javaClassReference, CodeVariableReferenceExpression activityClassReference)
        {
            var invocationCodeCollection = new CodeStatementCollection();
            foreach (var parameter in javaActivity.OutputData)
            {
                CodeAssignStatement _assign1 = new CodeAssignStatement();

                CodePropertyReferenceExpression _prop1 = new CodePropertyReferenceExpression();
                _prop1.PropertyName = parameter.Name;
                _prop1.TargetObject = activityClassReference;
                _assign1.Left = _prop1;
             //           CodePrimitiveExpression _value1 = new CodePrimitiveExpression();
              //          _value1.Value = "testvalue";
               //         _assign1.Right = _value1;
            //        __ctor_ctor1.Statements.Add(_assign1);

                CodeMethodInvokeExpression getterCall = new CodeMethodInvokeExpression();
                getterCall.Parameters.AddRange(new CodeExpression[0]);
                CodeMethodReferenceExpression getterMethod = new CodeMethodReferenceExpression();
                getterMethod.MethodName = "get" + parameter.Name;
                getterMethod.TargetObject = javaClassReference;
                getterCall.Method = getterMethod;
                _assign1.Right = getterCall;
                invocationCodeCollection.Add(_assign1);
            }

            return invocationCodeCollection;
        }
Exemplo n.º 35
0
 protected override void GenerateMethodReferenceExpression(System.CodeDom.CodeMethodReferenceExpression e)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Exemplo n.º 36
0
        public override void WriteCode(TemplateContext ctx, ActionNode node)
        {
            var codeMethodReferenceExpression = new CodeMethodReferenceExpression(
                new CodeSnippetExpression(SystemType.FullName),
                Method.Name);
            if (this.InstanceInfo != null)
            {
                var instanceVar = node.InputVars.FirstOrDefault(p => p.ActionFieldInfo == this.InstanceInfo);
                if (instanceVar != null)
                {
                    codeMethodReferenceExpression = new CodeMethodReferenceExpression(new CodeSnippetExpression(instanceVar.VariableName),Method.Name);
                }
                
            }
            var _currentActionInvoker =
                new CodeMethodInvokeExpression(
                    codeMethodReferenceExpression);
           
            foreach (var x in Method.GetParameters())
            {
                var item = node.GraphItems.OfType<IActionItem>().FirstOrDefault(p => p.Name == x.Name);
                var input = item as IActionIn;
                if (input != null)
                {
                    if (input.ActionFieldInfo == InstanceInfo) continue;

                    if (input.ActionFieldInfo.IsGenericArgument)
                    {
                    }
                    else
                    {
                        _currentActionInvoker.Parameters.Add(
                            new CodeSnippetExpression((input.ActionFieldInfo.IsByRef ? "ref " : string.Empty) +
                                                      string.Format("{0}", input.VariableName)));
                    }
                }
                var @out = item as ActionOut;
                if (@out != null)
                {
                    if (@out.ActionFieldInfo != null && @out.ActionFieldInfo.IsReturn)
                    {
                 
                        continue;
                    }
                    _currentActionInvoker.Parameters.Add(
                        new CodeSnippetExpression(string.Format("out {0}", @out.VariableName)));
                }
                var branch = item as ActionBranch;
                if (branch != null)
                {
                    if (DebugSystem.IsDebugMode)
                    {
                        _currentActionInvoker.Parameters.Add(
                            new CodeSnippetExpression(string.Format("()=> {{ System.StartCoroutine({0}()); }}",
                                branch.VariableName)));
                    }
                    else
                    {
                        _currentActionInvoker.Parameters.Add(
                            new CodeSnippetExpression(string.Format("{0}", branch.VariableName)));
                    }
                }
            }

            var resultOut = node.GraphItems.OfType<IActionItem>().FirstOrDefault(p => p.ActionFieldInfo != null && p.ActionFieldInfo.IsReturn);
            if (resultOut == null)
            {
                ctx.CurrentStatements.Add(_currentActionInvoker);
            }
            else
            {
                var assignResult = new CodeAssignStatement(
                    new CodeSnippetExpression(resultOut.VariableName), _currentActionInvoker);
                ctx.CurrentStatements.Add(assignResult);
            }
        }
Exemplo n.º 37
0
 public CodeMethodInvokeExpression(ILInstruction inline, CodeMethodReferenceExpression method, params CodeExpression[] parameters) : base(inline)
 {
     _method = method;
     Parameters.AddRange(parameters);
 }
        public override bool AddEventHandler(EventDescription eventDescription, string objectName, string methodName)
        {
            const string Init = "__init__";
            //This is not the most optimal solution for WPF since we will call FindLogicalNode for each event handler,
            //but it simplifies the code generation for now.

            CodeDomDocDataAdapter adapter = GetDocDataAdapterForPyFile();

            //Find the __init__ method
            CodeMemberMethod method = null;
            foreach(CodeTypeMember ctMember in adapter.TypeDeclaration.Members)
            {
                if (ctMember is CodeConstructor)
                {
                    if (ctMember.Name == Init)
                    {
                        method = ctMember as CodeMemberMethod;
                        break;
                    }
                }
            }
            if (method == null)
            {
                method = new CodeConstructor();
                method.Name = Init;
            }

            //Create a code statement which looks like: LogicalTreeHelper.FindLogicalNode(self.Root, "button1").Click += self.button1_Click
            CodeTypeReferenceExpression logicalTreeHelper = new CodeTypeReferenceExpression("LogicalTreeHelper");
            CodeMethodReferenceExpression findLogicalNodeMethod = new CodeMethodReferenceExpression(logicalTreeHelper, "FindLogicalNode");
            CodeFieldReferenceExpression selfWindow = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "Root");
            CodeMethodInvokeExpression findLogicalNodeInvoke = new CodeMethodInvokeExpression( findLogicalNodeMethod, selfWindow, new CodeSnippetExpression("\'" + objectName + "\'"));
            CodeDelegateCreateExpression createDelegateExpression = new CodeDelegateCreateExpression(new CodeTypeReference("System.EventHandler"), new CodeThisReferenceExpression(), methodName);
            CodeAttachEventStatement attachEvent = new CodeAttachEventStatement(findLogicalNodeInvoke, eventDescription.Name, createDelegateExpression);
            method.Statements.Add(attachEvent);
            adapter.Generate();
            return true;
        }
Exemplo n.º 39
0
 public CodeMethodInvokeExpression(CodeMethodReferenceExpression method, CodeExpression[] parameters)
 {
 }