public Add ( System.CodeDom.CodeExpression value ) : int | ||
value | System.CodeDom.CodeExpression | |
Результат | int |
public static CodeExpressionCollection Clone(this CodeExpressionCollection collection) { if (collection == null) return null; CodeExpressionCollection c = new CodeExpressionCollection(); foreach (CodeExpression expression in collection) c.Add(expression.Clone()); return c; }
internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier) { CodeBinaryOperatorExpression expression2 = (CodeBinaryOperatorExpression) expression; RuleBinaryExpressionInfo info = analysis.Validation.ExpressionInfo(expression2) as RuleBinaryExpressionInfo; if (info != null) { MethodInfo methodInfo = info.MethodInfo; if (methodInfo != null) { List<CodeExpression> attributedExprs = new List<CodeExpression>(); CodeExpressionCollection argExprs = new CodeExpressionCollection(); argExprs.Add(expression2.Left); argExprs.Add(expression2.Right); CodeExpression targetExpr = new CodeTypeReferenceExpression(methodInfo.DeclaringType); analysis.AnalyzeRuleAttributes(methodInfo, targetExpr, qualifier, argExprs, methodInfo.GetParameters(), attributedExprs); } } RuleExpressionWalker.AnalyzeUsage(analysis, expression2.Left, true, false, null); RuleExpressionWalker.AnalyzeUsage(analysis, expression2.Right, true, false, null); }
public void Constructor1_Deny_Unrestricted () { CodeExpressionCollection coll = new CodeExpressionCollection (array); coll.CopyTo (array, 0); Assert.AreEqual (1, coll.Add (ce), "Add"); Assert.AreSame (ce, coll[0], "this[int]"); coll.AddRange (array); coll.AddRange (coll); Assert.IsTrue (coll.Contains (ce), "Contains"); Assert.AreEqual (0, coll.IndexOf (ce), "IndexOf"); coll.Insert (0, ce); coll.Remove (ce); }
private static void AddTypes(string prepend, bool nested, CodeTypeDeclarationCollection types, CodeExpressionCollection into) { foreach (CodeTypeDeclaration t in types) { into.Add(new CodeTypeOfExpression( ((prepend == null || prepend == "") ? "" : (prepend + (nested ? "+" : "."))) + t.Name)); CodeTypeDeclarationCollection ctd = new CodeTypeDeclarationCollection(); foreach (CodeTypeMember m in t.Members) { if (m is CodeTypeDeclaration) ctd.Add((CodeTypeDeclaration)m); } AddTypes( ((prepend == null || prepend == "") ? "" : (prepend + (nested ? "+" : "."))) + t.Name, true, ctd, into); } }
public override void GenerateMethods(IDLInterface idlIntf) { if (idlIntf.Methods != null) // If got methods { bAddNamespace = idlIntf.Methods.Count > 0; foreach (IDLMethod idlMethod in idlIntf.Methods) { // Structs for capturing input/output from method. Udbus.Parsing.CodeTypeDeferredStructHolder paramsHolder = new Udbus.Parsing.CodeTypeDeferredStructHolder(idlMethod.Name + "AsyncParams"); Udbus.Parsing.CodeTypeDeferredStructHolder resultHolder = new Udbus.Parsing.CodeTypeDeferredStructHolder(idlMethod.Name + "AsyncResult"); CodeConstructor constructorResults = new CodeConstructor(); CodeConstructor constructorParams = new CodeConstructor(); constructorResults.Attributes = constructorParams.Attributes = MemberAttributes.Public; // Create Call method. CodeMemberMethod methodCall = new CodeMemberMethod(); methodCall.Name = "Call" + idlMethod.Name; // Actual call to proxy arguments will be added to as we parse IDL arguments. CodeExpressionCollection callParameters = new CodeExpressionCollection(); CodeExpressionCollection callResultArgs = new CodeExpressionCollection(); CodeExpressionCollection interfaceCallArgs = new CodeExpressionCollection(); CodeArgumentReferenceExpression argrefCallData = new CodeArgumentReferenceExpression(dataName); // Event Args string eventName = idlMethod.Name + "EventArgs"; CodeTypeDeclaration typeEvent = new CodeTypeDeclaration(eventName); typeEvent.IsClass = true; typeEvent.TypeAttributes = TypeAttributes.Public; typeEvent.BaseTypes.Add(new CodeTypeReference(typeof(AsyncCompletedEventArgs))); CodeConstructor constructorEventArgs = new CodeConstructor(); eventsDeclarationHolder.Add(typeEvent); CodeExpressionCollection makeEventArgs = new CodeExpressionCollection(); // Event Raiser... string raiserName = "raiser" + idlMethod.Name; CodeTypeReference raiserRef = new CodeTypeReference("AsyncOperationEventRaiser", new CodeTypeReference(eventName)); CodeMemberField fieldRaiser = new CodeMemberField(raiserRef, raiserName); fieldRaiser.InitExpression = new CodeObjectCreateExpression(raiserRef); fieldRaiser.Attributes = MemberAttributes.Private; typeProxy.Members.Add(fieldRaiser); // Event raiser EventCompleted Property - unfortunately CodeMemberEvent is useless here since can't add custom add/remove. // So anything other than CSharp is now a bust. Brilliant. CodeSnippetTypeMember eventRaiser = new CodeSnippetTypeMember(); eventRaiser.Text = string.Format(@" public event System.EventHandler<{0}> {1}Completed {{ add {{ this.{2}.CompletedEvent += value; }} remove {{ this.{2}.CompletedEvent -= value; }} }} ", eventName, idlMethod.Name, raiserName ); // Adding text here. //CodeMemberEvent eventRaiser = new CodeMemberEvent(); //eventRaiser.Attributes = MemberAttributes.Public; //CodeParamDeclaredType declaredType = new CodeParamDeclaredType(typeEvent); //eventRaiser.Type = new CodeTypeReference(CodeBuilderCommon.EventHandlerType.Name, declaredType.CodeType); //eventRaiser.Name = idlMethod.Name + "Completed"; typeProxy.Members.Add(eventRaiser); // Async method. CodeMemberMethod methodAsync = new CodeMemberMethod(); methodAsync.Name = idlMethod.Name + "Async"; methodAsync.Attributes = MemberAttributes.Public; // Straight-forward interface method. CodeMemberMethod methodInterface = new CodeMemberMethod(); methodInterface.Name = idlMethod.Name; methodInterface.Attributes = MemberAttributes.Public; // CodeComment commentMethod = new CodeComment(idlMethod.Name); // method.Comments.Add(new CodeCommentStatement(idlMethod.Name)); CodeExpressionCollection asyncArgs = new CodeExpressionCollection(); Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(contextDeclarationHolder); foreach (IDLMethodArgument idlMethodArg in idlMethod.Arguments) { CodeCommentStatement commentMethod = new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArg.Direction, idlMethodArg.Name, idlMethodArg.Type)); methodAsync.Comments.Add(commentMethod); methodInterface.Comments.Add(commentMethod); // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument. Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethod); ParamCodeTypeFactory paramtypeHolder = new ParamCodeTypeFactory(CodeTypeFactory.Default, idlMethodArg.Direction == "out" ? FieldDirection.Out : FieldDirection.In); Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArg.Type, context); Udbus.Parsing.ICodeParamType paramtype = paramtypeHolder.paramtype; // Arguments. CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name); CodeVariableReferenceExpression varrefMethodArg = new CodeVariableReferenceExpression(idlMethodArg.Name); if (idlMethodArg.Direction == "out") // If out argument { // Add to interface parameters. interfaceCallArgs.Add(new CodeDirectionExpression(FieldDirection.Out, varrefMethodArg)); // Put into result holding struct... param.Direction = FieldDirection.Out; methodInterface.Parameters.Add(param); CodeTypeReference argType = CodeBuilderCommon.GetReadOnlyCodeReference(paramtypeHolder.paramtype.CodeType); CodeMemberField fieldResultArg = new CodeMemberField(argType, idlMethodArg.Name); fieldResultArg.Attributes = MemberAttributes.Public; resultHolder.CodeType.Members.Add(fieldResultArg); constructorResults.Parameters.Add(new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name)); CodeFieldReferenceExpression thisArg = new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), idlMethodArg.Name ); constructorResults.Statements.Add(new CodeAssignStatement(thisArg, new CodeArgumentReferenceExpression(idlMethodArg.Name))); // Add placeholder variables to call method. methodCall.Statements.Add(new CodeVariableDeclarationStatement(paramtype.CodeType, idlMethodArg.Name)); // Add appropriate parameter in actual call to interface. callParameters.Add(new CodeDirectionExpression(FieldDirection.Out, varrefMethodArg)); // Add appropriate parameter in call to result constructor. callResultArgs.Add(new CodeArgumentReferenceExpression(idlMethodArg.Name)); // Put into event args class... string fieldEventArgName = idlMethodArg.Name + "_"; CodeMemberField fieldEventArg = new CodeMemberField(paramtype.CodeType, fieldEventArgName); fieldEventArg.Attributes = MemberAttributes.Private; typeEvent.Members.Add(fieldEventArg); // Add argument property to EventArgs. CodeMemberProperty propEventArg = new CodeMemberProperty(); propEventArg.Attributes = MemberAttributes.Public | MemberAttributes.Final; propEventArg.Name = idlMethodArg.Name; propEventArg.HasGet = true; propEventArg.Type = paramtype.CodeType; propEventArg.GetStatements.Add(new CodeMethodInvokeExpression(null, "RaiseExceptionIfNecessary")); propEventArg.GetStatements.Add(new CodeMethodReturnStatement(new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), fieldEventArgName))); typeEvent.Members.Add(propEventArg); // Add constructor parameter and statement to EventArgs. constructorEventArgs.Parameters.Add(new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name)); constructorEventArgs.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldEventArgName), new CodeArgumentReferenceExpression(idlMethodArg.Name) )); // Add as parameter in call to EventArgs constructor. makeEventArgs.Add(new CodeFieldReferenceExpression(new CodeArgumentReferenceExpression(resultName), idlMethodArg.Name)); } // Ends if out argument else // Else in argument { // Add to interface parameters. interfaceCallArgs.Add(varrefMethodArg); // Put into parameter holding struct. CodeMemberField fieldArg = new CodeMemberField(CodeBuilderCommon.GetReadOnlyCodeReference(paramtype.CodeType), idlMethodArg.Name); fieldArg.Attributes = MemberAttributes.Public; paramsHolder.CodeType.Members.Add(fieldArg); constructorParams.Parameters.Add(new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name)); CodeFieldReferenceExpression thisArg = new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), idlMethodArg.Name ); constructorParams.Statements.Add(new CodeAssignStatement(thisArg, new CodeArgumentReferenceExpression(idlMethodArg.Name))); // Add appropriate parameter in actual call to interface. callParameters.Add(new CodeFieldReferenceExpression(argrefCallData, idlMethodArg.Name)); // Add appropriate parameter to async method parameters constructor call. asyncArgs.Add(new CodeArgumentReferenceExpression(idlMethodArg.Name)); // Add parameter to async method. methodAsync.Parameters.Add(param); // Add parameter to interface method. methodInterface.Parameters.Add(param); } // Ends else in argument } // Ends loop over method arguments methodAsync.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "userState")); // Add method body, then sort out arguments code... CodeFieldReferenceExpression thisRaiser = new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), raiserName ); CodeTypeReference typerefResult = null; if (idlMethod.Return != null) // If method has return type { // Add result to Result type. // TODO replace typeof(string) with actual return type. typerefResult = new CodeTypeReference("???"); } CodeTypeReference typerefResults = null; CodeTypeReference typerefParams = null; CodeExpression exprAsyncParamValue = null; string asyncMethodName = "AsyncFuncImpl"; // Default is assuming that function returns something. if (paramsHolder.QuType()) // If got params type { typerefParams = new CodeTypeReference(paramsHolder.CodeType.Name); // Add proxy field to params struct. CodeMemberField memberParamsProxy = new CodeMemberField(new CodeTypeReference("readonly " + genInterfaceName), proxyName); memberParamsProxy.Attributes = MemberAttributes.Public; paramsHolder.CodeType.Members.Insert(0, memberParamsProxy); // TODO: Going to need a using or a fully qualified name. // Add initialisation to constructor constructorParams.Parameters.Insert(0, paramProxy); // Constructor will take proxy as first argument. constructorParams.Statements.Insert(0, assignProxy); paramsHolder.CodeType.TypeAttributes = TypeAttributes.NestedPrivate; paramsHolder.CodeType.IsStruct = true; constructorParams.Attributes = MemberAttributes.Public; paramsHolder.CodeType.Members.Add(constructorParams); typeProxy.Members.Add(paramsHolder.CodeType); asyncArgs.Insert(0, thisProxyFieldRef); exprAsyncParamValue = new CodeObjectCreateExpression(typerefParams, asyncArgs.Cast<CodeExpression>().ToArray()); } // Ends if got params type if (resultHolder.QuType()) // If got results type { typerefResults = new CodeTypeReference(resultHolder.CodeType.Name); methodCall.ReturnType = typerefResults; // Setup call method parameters. if (idlMethod.Return != null) { // Add result field to EventArgs. CodeMemberField fieldResult = new CodeMemberField(typerefResult, resultName); fieldResult.Attributes = MemberAttributes.Private; typeEvent.Members.Insert(0, fieldResult); // Add result property to EventArgs. CodeMemberProperty propResult = new CodeMemberProperty(); propResult.Attributes = MemberAttributes.Public; propResult.Name = resultName; propResult.HasGet = true; propResult.Type = typerefResult; propResult.GetStatements.Add(new CodeMethodInvokeExpression(null, "RaiseExceptionIfNecessary")); propResult.GetStatements.Add(new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), resultName)); typeEvent.Members.Add(propResult); // Add suitable parameter as first EventArgs constructor argument. constructorEventArgs.Parameters.Insert(0, new CodeParameterDeclarationExpression(typerefResult, resultName)); // Add statement to initialise result member. CodeFieldReferenceExpression thisArg = new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), resultName ); // Include result in parameters to EventArgs in MakeEventArgs statements. makeEventArgs.Insert(0, new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), resultName)); // Add result to Result type. CodeTypeReference typerefReadOnlyResult = CodeBuilderCommon.GetReadOnlyCodeReference(typerefResult); CodeMemberField fieldReadOnlyResult = new CodeMemberField(typerefReadOnlyResult, resultName); fieldResult.Attributes = MemberAttributes.Public; resultHolder.CodeType.Members.Insert(0, fieldReadOnlyResult); // Add suitable parameter as first constructor argument. constructorResults.Parameters.Insert(0, new CodeParameterDeclarationExpression(typerefResult, resultName)); // Add statement to initialise result member. constructorResults.Statements.Insert(0, new CodeAssignStatement(thisArg, new CodeArgumentReferenceExpression(resultName))); } // End if there is a return statement resultHolder.CodeType.TypeAttributes = TypeAttributes.NestedPrivate; resultHolder.CodeType.IsStruct = true; resultHolder.CodeType.Members.Add(constructorResults); typeProxy.Members.Add(resultHolder.CodeType); } // Ends if got results type else // Else no results type { // Absolutely no results (including out parameters) means it's an Action. asyncMethodName = "AsyncActionImpl"; } // Ends else no results type // Time to bite the bullet. CodeTypeReference typerefEvent = new CodeTypeReference(typeEvent.Name); CodeMemberMethod methodMakeEventArgs = new CodeMemberMethod(); methodMakeEventArgs.Name = "Make" + idlMethod.Name + "AsyncEventArgs"; // Add missing parameters to EventArgs... constructorEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclException); constructorEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclCancelled); constructorEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclUserState); // Pass through to base class. constructorEventArgs.BaseConstructorArgs.Add(CodeBuilderCommon.argrefException); constructorEventArgs.BaseConstructorArgs.Add(CodeBuilderCommon.argrefCancelled); constructorEventArgs.BaseConstructorArgs.Add(CodeBuilderCommon.argrefUserState); // Add MakeEventArgs method... // Create MakeEventArgs method. methodMakeEventArgs.Attributes = MemberAttributes.Private | MemberAttributes.Static; if (typerefParams != null) // If got params type { methodMakeEventArgs.Parameters.Add(new CodeParameterDeclarationExpression(typerefParams, dataName)); } else // Else no params type { // The interface will be passed as the first parameter. methodMakeEventArgs.Parameters.Add(paramProxy); } // Ends else no params type if (typerefResults != null) // If got results type { methodMakeEventArgs.Parameters.Add(new CodeParameterDeclarationExpression(typerefResults, resultName)); } methodMakeEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclException); methodMakeEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclCancelled); methodMakeEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclUserState); makeEventArgs.Add(CodeBuilderCommon.argrefException); makeEventArgs.Add(CodeBuilderCommon.argrefCancelled); makeEventArgs.Add(CodeBuilderCommon.argrefUserState); methodMakeEventArgs.Statements.Add(new CodeMethodReturnStatement( new CodeObjectCreateExpression( typerefEvent, makeEventArgs.Cast<CodeExpression>().ToArray() ) )); methodMakeEventArgs.ReturnType = typerefEvent; typeProxy.Members.Add(methodMakeEventArgs); // Setup call method parameters. methodCall.Attributes = MemberAttributes.Private | MemberAttributes.Static; CodeExpression exprProxyRef; //methodCall.ReturnType = new CodeTypeReference(resultHolder.CodeType.Name); if (typerefParams != null) // If passing parameters { methodCall.Parameters.Add(new CodeParameterDeclarationExpression(typerefParams, dataName)); exprProxyRef = new CodeFieldReferenceExpression(argrefCallData, proxyName); } // Ends if passing parameters else // Else just passing proxy { methodCall.Parameters.Add(new CodeParameterDeclarationExpression(genInterfaceName, proxyName)); exprProxyRef = new CodeArgumentReferenceExpression(proxyName); } // Ends else just passing proxy // Add call method body... // Invocation to proxy. CodeMethodReferenceExpression methodProxy = new CodeMethodReferenceExpression(exprProxyRef, idlMethod.Name); CodeMethodInvokeExpression invokeProxy = new CodeMethodInvokeExpression(methodProxy, callParameters.Cast<CodeExpression>().ToArray()); if (idlMethod.Return != null) // If got return type { // TODO - return values. // Add invocation of actual interface method and store result. CodeVariableDeclarationStatement exprResult = new CodeVariableDeclarationStatement(typerefResult, resultName, invokeProxy); methodCall.Statements.Add(exprResult); // Initialise result parameter in Result struct. callResultArgs.Insert(0, new CodeArgumentReferenceExpression(resultName)); } // Ends if got return type else // Else no return type { // Add invocation of actual interface method and ignore result. methodCall.Statements.Add(invokeProxy); } // Ends else no return type if (typerefResults != null) // If got result type { // Create Call return statement. CodeMethodReturnStatement retCall = new CodeMethodReturnStatement( new CodeObjectCreateExpression(typerefResults, callResultArgs.Cast<CodeExpression>().ToArray()) ); methodCall.Statements.Add(retCall); } // Ends if got result type // Add call method to type. typeProxy.Members.Add(methodCall); // Add async method implementation... if (exprAsyncParamValue == null) // If no params { // Just pass the proxy. exprAsyncParamValue = thisProxyFieldRef; } // Ends if no params methodAsync.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(thisRaiser, asyncMethodName) , new CodeArgumentReferenceExpression("userState") , exprAsyncParamValue , new CodeMethodReferenceExpression(null, methodCall.Name) , new CodeMethodReferenceExpression(null, methodMakeEventArgs.Name) )); methodInterface.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(thisProxyFieldRef, idlMethod.Name) , interfaceCallArgs.Cast<CodeExpression>().ToArray() )); // Finish up. typeEvent.Members.Add(constructorEventArgs); constructorEventArgs.Attributes = MemberAttributes.Public; ns.Types.Add(typeEvent); typeProxy.Members.Add(methodAsync); typeProxy.Members.Add(methodInterface); } // Ends loop over methods } // Ends if got methods }
private void AddParam(CodeExpressionCollection @params, Expression par) { try { object v = CodeDom.Eval(par); if (v == null && par != null) @params.Add(_Visit(par)); else @params.Add(GetFromPrimitive(v)); } catch (Exception) { @params.Add(_Visit(par)); } }
//public CodeExpressionCollection VisitExpressionList(System.Collections.ObjectModel.ReadOnlyCollection<Expression> original) public CodeExpressionCollection VisitExpressionList(IEnumerable<Expression> original) { CodeExpressionCollection list = new CodeExpressionCollection(); foreach (Expression e in original) { list.Add(_Visit(e)); } return list; }
private void GenerateEntityQueryMethod(DomainOperationEntry domainOperationEntry) { string queryMethodName = domainOperationEntry.Name + QuerySuffix; Type entityType = TypeUtility.GetElementType(domainOperationEntry.ReturnType); CodeMemberMethod queryMethod = new CodeMemberMethod(); queryMethod.Name = queryMethodName; queryMethod.Attributes = MemberAttributes.Public | MemberAttributes.Final; // Final needed, else becomes virtual queryMethod.ReturnType = CodeGenUtilities.GetTypeReference(TypeConstants.EntityQueryTypeFullName, this._domainServiceDescription.DomainServiceType.Namespace, false); queryMethod.ReturnType.TypeArguments.Add(CodeGenUtilities.GetTypeReference(entityType.FullName, this._domainServiceDescription.DomainServiceType.Namespace, true)); DomainOperationParameter[] domainOperationEntryParameters = domainOperationEntry.Parameters.ToArray(); // Generate <summary> doc comment string comment = string.Format(CultureInfo.CurrentCulture, Resource.EntityCodeGen_ConstructorComments_Summary_DomainContext, entityType.Name, domainOperationEntry.Name); queryMethod.Comments.AddRange(CodeGenUtilities.GenerateSummaryCodeComment(comment, this.ClientProxyGenerator.IsCSharp)); // Generate <param> doc comments foreach (DomainOperationParameter paramInfo in domainOperationEntryParameters) { comment = string.Format(CultureInfo.CurrentCulture, Resource.CodeGen_Query_Method_Parameter_Comment, paramInfo.Name); queryMethod.Comments.AddRange(CodeGenUtilities.GenerateParamCodeComment(paramInfo.Name, comment, this.ClientProxyGenerator.IsCSharp)); } // Generate <returns> doc comments comment = string.Format(CultureInfo.CurrentCulture, Resource.CodeGen_Query_Method_Returns_Comment, domainOperationEntry.AssociatedType.Name); queryMethod.Comments.AddRange(CodeGenUtilities.GenerateReturnsCodeComment(comment, this.ClientProxyGenerator.IsCSharp)); // Propagate custom validation attributes IEnumerable<Attribute> methodAttributes = domainOperationEntry.Attributes.Cast<Attribute>(); CustomAttributeGenerator.GenerateCustomAttributes( this.ClientProxyGenerator, this._proxyClass, ex => string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Attribute_ThrewException_CodeMethod, ex.Message, queryMethod.Name, this._proxyClass.Name, ex.InnerException.Message), methodAttributes, queryMethod.CustomAttributes, queryMethod.Comments); // add any domain operation entry parameters first CodeVariableReferenceExpression paramsRef = new CodeVariableReferenceExpression("parameters"); if (domainOperationEntryParameters.Length > 0) { // need to generate the user parameters dictionary CodeTypeReference dictionaryTypeReference = CodeGenUtilities.GetTypeReference( typeof(Dictionary<string, object>), this.ClientProxyGenerator, this._proxyClass); CodeVariableDeclarationStatement paramsDef = new CodeVariableDeclarationStatement( dictionaryTypeReference, "parameters", new CodeObjectCreateExpression(dictionaryTypeReference, new CodeExpression[0])); queryMethod.Statements.Add(paramsDef); } foreach (DomainOperationParameter paramInfo in domainOperationEntryParameters) { CodeParameterDeclarationExpression paramDecl = new CodeParameterDeclarationExpression( CodeGenUtilities.GetTypeReference( CodeGenUtilities.TranslateType(paramInfo.ParameterType), this.ClientProxyGenerator, this._proxyClass), paramInfo.Name); // Propagate parameter level validation attributes IEnumerable<Attribute> paramAttributes = paramInfo.Attributes.Cast<Attribute>(); string commentHeader = string.Format( CultureInfo.CurrentCulture, Resource.ClientCodeGen_Attribute_Parameter_FailedToGenerate, paramInfo.Name); CustomAttributeGenerator.GenerateCustomAttributes( this.ClientProxyGenerator, this._proxyClass, ex => string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Attribute_ThrewException_CodeMethodParameter, ex.Message, paramDecl.Name, queryMethod.Name, this._proxyClass.Name, ex.InnerException.Message), paramAttributes, paramDecl.CustomAttributes, queryMethod.Comments, commentHeader); // add the parameter to the query method queryMethod.Parameters.Add(paramDecl); // add the parameter and value to the params dictionary queryMethod.Statements.Add(new CodeMethodInvokeExpression( new CodeMethodReferenceExpression(paramsRef, "Add"), new CodePrimitiveExpression(paramInfo.Name), new CodeVariableReferenceExpression(paramInfo.Name))); } // add argument for queryName CodeExpressionCollection arguments = new CodeExpressionCollection(); arguments.Add(new CodePrimitiveExpression(domainOperationEntry.Name)); // add argument for parameters if (domainOperationEntryParameters.Length > 0) { arguments.Add(paramsRef); } else { arguments.Add(new CodePrimitiveExpression(null)); } // add argument for hasSideEffects QueryAttribute queryAttribute = (QueryAttribute)domainOperationEntry.OperationAttribute; arguments.Add(new CodePrimitiveExpression(queryAttribute.HasSideEffects)); // add argument for isComposable arguments.Add(new CodePrimitiveExpression(queryAttribute.IsComposable)); // this.ValidateMethod("methodName", parameters); CodeExpression paramsExpr = new CodePrimitiveExpression(null); if (domainOperationEntryParameters.Length > 0) { paramsExpr = paramsRef; } CodeExpressionStatement validateMethodCall = new CodeExpressionStatement( new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "ValidateMethod", new CodeExpression[] { new CodePrimitiveExpression(queryMethodName), paramsExpr })); queryMethod.Statements.Add(validateMethodCall); // ---------------------------------------------------------------- // method call: base.CreateQuery(arguments...) // ---------------------------------------------------------------- CodeTypeReference entityTypeRef = CodeGenUtilities.GetTypeReference(entityType.FullName, this._domainServiceDescription.DomainServiceType.Namespace, true); CodeMethodReferenceExpression createQueryMethod = new CodeMethodReferenceExpression(new CodeBaseReferenceExpression(), "CreateQuery", entityTypeRef); CodeMethodReturnStatement createQueryCall = new CodeMethodReturnStatement(new CodeMethodInvokeExpression(createQueryMethod, arguments.Cast<CodeExpression>().ToArray())); queryMethod.Statements.Add(createQueryCall); this._proxyClass.Members.Add(queryMethod); }
public void Remove () { CodeExpression ce1 = new CodeExpression (); CodeExpression ce2 = new CodeExpression (); CodeExpressionCollection coll = new CodeExpressionCollection (); coll.Add (ce1); coll.Add (ce2); Assert.AreEqual (2, coll.Count, "#1"); Assert.AreEqual (0, coll.IndexOf (ce1), "#2"); Assert.AreEqual (1, coll.IndexOf (ce2), "#3"); coll.Remove (ce1); Assert.AreEqual (1, coll.Count, "#4"); Assert.AreEqual (-1, coll.IndexOf (ce1), "#5"); Assert.AreEqual (0, coll.IndexOf (ce2), "#6"); }
private string WriteEventMulticaster(CodeNamespace ns) { string clsName = this.axctl + "EventMulticaster"; if (!this.ClassAlreadyExistsInNamespace(ns, clsName)) { CodeTypeDeclaration cls = new CodeTypeDeclaration { Name = clsName }; cls.BaseTypes.Add(this.axctlEvents); CodeAttributeDeclarationCollection declarations = new CodeAttributeDeclarationCollection(); CodeAttributeDeclaration declaration2 = new CodeAttributeDeclaration("System.Runtime.InteropServices.ClassInterface", new CodeAttributeArgument[] { new CodeAttributeArgument(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(null, "System.Runtime.InteropServices.ClassInterfaceType"), "None")) }); declarations.Add(declaration2); cls.CustomAttributes = declarations; CodeMemberField field = new CodeMemberField(this.axctl, "parent") { Attributes = MemberAttributes.Private | MemberAttributes.Final }; cls.Members.Add(field); CodeConstructor constructor = new CodeConstructor { Attributes = MemberAttributes.Public }; constructor.Parameters.Add(this.CreateParamDecl(this.axctl, "parent", false)); CodeFieldReferenceExpression left = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "parent"); CodeFieldReferenceExpression right = new CodeFieldReferenceExpression(null, "parent"); constructor.Statements.Add(new CodeAssignStatement(left, right)); cls.Members.Add(constructor); MethodInfo[] methods = this.axctlEventsType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); int num = 0; for (int i = 0; i < methods.Length; i++) { AxParameterData[] dataArray = AxParameterData.Convert(methods[i].GetParameters()); CodeMemberMethod method = new CodeMemberMethod { Name = methods[i].Name, Attributes = MemberAttributes.Public, ReturnType = new CodeTypeReference(MapTypeName(methods[i].ReturnType)) }; for (int j = 0; j < dataArray.Length; j++) { CodeParameterDeclarationExpression expression3 = this.CreateParamDecl(MapTypeName(dataArray[j].ParameterType), dataArray[j].Name, dataArray[j].IsOptional); expression3.Direction = dataArray[j].Direction; method.Parameters.Add(expression3); } CodeFieldReferenceExpression expression4 = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "parent"); if (!this.IsEventPresent(methods[i])) { EventEntry entry = (EventEntry) this.events[num++]; CodeExpressionCollection expressions = new CodeExpressionCollection(); expressions.Add(expression4); if (entry.eventCls.Equals("EventArgs")) { expressions.Add(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(null, "EventArgs"), "Empty")); CodeExpression[] array = new CodeExpression[expressions.Count]; ((ICollection) expressions).CopyTo(array, 0); CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(expression4, entry.invokeMethodName, array); if (methods[i].ReturnType == typeof(void)) { method.Statements.Add(new CodeExpressionStatement(expression)); } else { method.Statements.Add(new CodeMethodReturnStatement(expression)); } } else { CodeObjectCreateExpression expression6 = new CodeObjectCreateExpression(entry.eventCls, new CodeExpression[0]); for (int k = 0; k < entry.parameters.Length; k++) { if (!entry.parameters[k].IsOut) { expression6.Parameters.Add(new CodeFieldReferenceExpression(null, entry.parameters[k].Name)); } } CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(entry.eventCls, entry.eventParam) { InitExpression = expression6 }; method.Statements.Add(statement); expressions.Add(new CodeFieldReferenceExpression(null, entry.eventParam)); CodeExpression[] expressionArray2 = new CodeExpression[expressions.Count]; ((ICollection) expressions).CopyTo(expressionArray2, 0); CodeMethodInvokeExpression expression7 = new CodeMethodInvokeExpression(expression4, entry.invokeMethodName, expressionArray2); if (methods[i].ReturnType == typeof(void)) { method.Statements.Add(new CodeExpressionStatement(expression7)); } else { CodeVariableDeclarationStatement statement2 = new CodeVariableDeclarationStatement(entry.retType, entry.invokeMethodName); method.Statements.Add(statement2); method.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(null, statement2.Name), expression7)); } for (int m = 0; m < dataArray.Length; m++) { if (dataArray[m].IsByRef) { method.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(null, dataArray[m].Name), new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(null, statement.Name), dataArray[m].Name))); } } if (methods[i].ReturnType != typeof(void)) { method.Statements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(null, entry.invokeMethodName))); } } } else { CodeExpressionCollection expressions2 = new CodeExpressionCollection(); for (int n = 0; n < dataArray.Length; n++) { expressions2.Add(new CodeFieldReferenceExpression(null, dataArray[n].Name)); } CodeExpression[] expressionArray3 = new CodeExpression[expressions2.Count]; ((ICollection) expressions2).CopyTo(expressionArray3, 0); CodeMethodInvokeExpression expression8 = new CodeMethodInvokeExpression(expression4, "RaiseOn" + methods[i].Name, expressionArray3); if (methods[i].ReturnType == typeof(void)) { method.Statements.Add(new CodeExpressionStatement(expression8)); } else { method.Statements.Add(new CodeMethodReturnStatement(expression8)); } } cls.Members.Add(method); } this.AddClassToNamespace(ns, cls); } return clsName; }
/// <summary> /// Generates code for the specified assignment statement. /// </summary> /// <remarks><c>LEFT = RIGHT</c> or <c>LEFT.TARGET->set_Item(LEFT.INDICES, RIGHT)</c></remarks> protected override void GenerateAssignStatement(CodeAssignStatement e) { // indexer "set" hack CodeIndexerExpression indexer_exp = e.Left as CodeIndexerExpression; if (indexer_exp != null) { CodeExpressionCollection setter_args = new CodeExpressionCollection(); foreach (CodeExpression exp in indexer_exp.Indices) setter_args.Add(exp); setter_args.Add(e.Right); OutputInvocation(new CodeMethodReferenceExpression(indexer_exp.TargetObject, SpecialWords.IndexerSet), setter_args); } else { GenerateExpression(e.Left); Output.Write(WhiteSpace.Space + Tokens.Assignment + WhiteSpace.Space); GenerateExpression(e.Right); } Output.WriteLine(Tokens.Semicolon); }
private void BuildParameters(CodeStatementCollection statements, MethodInfo method, object[] paramValues, CodeExpressionCollection parameters) { ParameterInfo[] infoArray1 = method.GetParameters(); for (int num1 = 0; num1 < infoArray1.Length; num1++) { ParameterInfo info1 = infoArray1[num1]; Type type1 = infoArray1[num1].ParameterType; FieldDirection direction1 = FieldDirection.In; if (type1.IsByRef) { direction1 = FieldDirection.Ref; type1 = type1.GetElementType(); } CodeExpression expression1 = null; if (!info1.IsOut) { expression1 = BuildObject(statements, info1.Name, paramValues[num1]); } else { direction1 = FieldDirection.Out; } if (direction1 != FieldDirection.In) { if ((expression1 == null) || !(expression1 is CodeVariableReferenceExpression)) { CodeVariableDeclarationStatement statement1 = new CodeVariableDeclarationStatement(type1.FullName, info1.Name); if (expression1 != null) { statement1.InitExpression = expression1; } statements.Add(statement1); expression1 = new CodeVariableReferenceExpression(statement1.Name); } expression1 = new CodeDirectionExpression(direction1, expression1); } parameters.Add(expression1); } }
private void GenerateMethod(IDLInterface idlIntf, IDLMethod idlMethod , Udbus.Parsing.ICodeTypeDeclarationHolder contextDeclarationHolder , CodeTypeReference typerefDbusInterface , CodeTypeReference typerefDbusMarshal , CodeTypeDeclaration typeProxy) { // Straight-forward interface method. CodeMemberMethod methodInterface = new CodeMemberMethod(); CodeExpressionCollection interfaceCallArgs = new CodeExpressionCollection(); methodInterface.Name = idlMethod.Name; methodInterface.Attributes = MemberAttributes.Public; Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(contextDeclarationHolder); #region Methods args foreach (IDLMethodArgument idlMethodArg in idlMethod.Arguments) { CodeCommentStatement commentMethod = new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArg.Direction, idlMethodArg.Name, idlMethodArg.Type)); methodInterface.Comments.Add(commentMethod); // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument. Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethod); ParamCodeTypeFactory paramtypeHolder = new ParamCodeTypeFactory(CodeTypeFactory.Default, idlMethodArg.Direction == "out" ? FieldDirection.Out : FieldDirection.In); Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArg.Type, context); Udbus.Parsing.ICodeParamType paramtype = paramtypeHolder.paramtype; // Arguments. CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name); CodeVariableReferenceExpression varrefMethodArg = new CodeVariableReferenceExpression(idlMethodArg.Name); if (idlMethodArg.Direction == "out") { // Add to interface parameters. interfaceCallArgs.Add(new CodeDirectionExpression(FieldDirection.Out, varrefMethodArg)); // Add parameter to interface method. param.Direction = FieldDirection.Out; } else { interfaceCallArgs.Add(varrefMethodArg); } methodInterface.Parameters.Add(param); } // Ends loop over method arguments #endregion methodInterface.Statements.Add(this.DeclareTargetVariable(typerefDbusInterface, typerefDbusMarshal)); methodInterface.Statements.Add(new CodeMethodInvokeExpression(varrefTarget, idlMethod.Name, interfaceCallArgs.Cast<CodeExpression>().ToArray())); //methodInterface.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(thisProxyFieldRef, idlMethod.Name) // , interfaceCallArgs.Cast<CodeExpression>().ToArray() //)); // Finish up. typeProxy.Members.Add(methodInterface); }
internal void AddDeclaredParameters(CodeTypeDeclaration classDeclaration, IMethod method, CodeMemberMethod member, CodeExpressionCollection constructorParameters, bool addOptionalParameters) { if (method.Parameters == null) { return; } // Add all parameters to the method. foreach (var param in method.GetAllParametersSorted()) { if (!addOptionalParameters && !param.IsRequired) { continue; } // Generate a safe parameter name which was not yet used. // Also exclude method name as VB can not have parameterName the same as method name. string parameterName = GeneratorUtils.GetParameterName( param, method.Parameters.Keys.Without(param.Name).Concat(method.Name)); // Declare the parameter, and add it to the list of constructor parameters of the request class. member.Parameters.Add(DeclareInputParameter(classDeclaration, param, method)); constructorParameters.Add(new CodeVariableReferenceExpression(parameterName)); AddParameterComment(commentCreator, member, param, parameterName); } }
public CodeMemberMethod CreateMethod(CodeTypeDeclaration classDeclaration, IResource resource, IMethod method, bool addOptionalParameters, MethodType methodType) { // Create a new method and make it public. var member = new CodeMemberMethod(); member.Name = GeneratorUtils.GetMethodName(method, resource.Methods.Keys.Without(method.Name)); member.Attributes = MemberAttributes.Public; if (commentCreator != null) { member.Comments.AddRange(commentCreator.CreateMethodComment(method)); } // Check if this method has a body. CodeExpressionCollection constructorParameters = new CodeExpressionCollection(); constructorParameters.Add(new CodeVariableReferenceExpression(ServiceFieldName)); if (method.HasBody) { // If so, add a body parameter. ResourceCallAddBodyDeclaration(method, member, GetBodyType(method), false); } // If a body parameter or similar parameters were added, also add them to the constructor. foreach (CodeParameterDeclarationExpression existingParameter in member.Parameters) { constructorParameters.Add(new CodeVariableReferenceExpression(existingParameter.Name)); } // Add all request parameters to this method. AddDeclaredParameters( classDeclaration, method, member, constructorParameters, addOptionalParameters); string requestClassNamingScheme = RequestClassGenerator.RequestClassNamingScheme; // If this is the media-upload convenience method, add the stream and content-type // parameters. if (methodType == MethodType.Media) { member.Parameters.Add(new CodeParameterDeclarationExpression( typeof(System.IO.Stream), StreamParameterName)); member.Parameters.Add(new CodeParameterDeclarationExpression( typeof(System.String), ContentTypeParameterName)); constructorParameters.Add(new CodeVariableReferenceExpression(StreamParameterName)); constructorParameters.Add(new CodeVariableReferenceExpression(ContentTypeParameterName)); requestClassNamingScheme = RequestClassGenerator.MediaUploadClassNamingScheme; } // new ...Request(paramOne, paramTwo, paramThree) // TODO(mlinder): add method signature collision checking here. CodeTypeReference requestType = new CodeTypeReference( RequestClassGenerator.GetProposedName( method, requestClassNamingScheme)); member.ReturnType = requestType; var newRequest = new CodeObjectCreateExpression(requestType); newRequest.Parameters.AddRange(constructorParameters); // return ...; var returnStatment = new CodeMethodReturnStatement(newRequest); member.Statements.Add(returnStatment); return member; }
internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier) { CodeBinaryOperatorExpression binaryExpr = (CodeBinaryOperatorExpression)expression; // Get the method info from the validation so we can look for [RuleRead] and [RuleWrite] attributes. RuleBinaryExpressionInfo expressionInfo = analysis.Validation.ExpressionInfo(binaryExpr) as RuleBinaryExpressionInfo; if (expressionInfo != null) { // we may be calling a method, not a default operator MethodInfo method = expressionInfo.MethodInfo; if (method != null) { List<CodeExpression> attributedExprs = new List<CodeExpression>(); CodeExpressionCollection arguments = new CodeExpressionCollection(); arguments.Add(binaryExpr.Left); arguments.Add(binaryExpr.Right); CodeExpression targetObject = new CodeTypeReferenceExpression(method.DeclaringType); analysis.AnalyzeRuleAttributes(method, targetObject, qualifier, arguments, method.GetParameters(), attributedExprs); } } // Analyze the left & right children. RuleExpressionWalker.AnalyzeUsage(analysis, binaryExpr.Left, true, false, null); RuleExpressionWalker.AnalyzeUsage(analysis, binaryExpr.Right, true, false, null); }
protected void CreateRegistrationParameters(CodeExpressionCollection methodParameters, XmlNodeList scriptParameters) { CodeExpression[] initializers = new CodeExpression[scriptParameters.Count]; for (int i = 0; i < scriptParameters.Count; i++) { XmlElement element = scriptParameters.Item(i) as XmlElement; if (PARAMETER.Equals(element.Name)) { string key = element.GetAttribute(KEY); if (key != string.Empty) { initializers[i] = new CodeObjectCreateExpression( typeof (ComponentParameter), new CodeExpression[] {new CodePrimitiveExpression(key)}); } else if (element.InnerText != string.Empty) { initializers[i] = new CodeObjectCreateExpression( typeof (ConstantParameter), new CodeExpression[] {new CodeSnippetExpression(element.InnerText)}); } else { throw new PicoCompositionException("Parameter not set"); } } } methodParameters.Add(new CodeArrayCreateExpression( "IParameter", initializers)); }
public void Constructor2 () { CodeExpression exp1 = new CodeExpression (); CodeExpression exp2 = new CodeExpression (); CodeExpressionCollection c = new CodeExpressionCollection (); c.Add (exp1); c.Add (exp2); CodeExpressionCollection coll = new CodeExpressionCollection (c); Assert.AreEqual (2, coll.Count, "#1"); Assert.AreEqual (0, coll.IndexOf (exp1), "#2"); Assert.AreEqual (1, coll.IndexOf (exp2), "#3"); }
private void BuildParameters(CodeStatementCollection statements, MethodInfo method, object[] paramValues, CodeExpressionCollection parameters) { ParameterInfo[] infoArray = method.GetParameters(); for (int i = 0; i < infoArray.Length; i++) { ParameterInfo info = infoArray[i]; Type parameterType = infoArray[i].ParameterType; FieldDirection @in = FieldDirection.In; if (parameterType.IsByRef) { @in = FieldDirection.Ref; parameterType = parameterType.GetElementType(); } CodeExpression expression = null; if (!info.IsOut) { expression = this.BuildObject(statements, info.Name, paramValues[i]); } else { @in = FieldDirection.Out; } if (@in != FieldDirection.In) { if ((expression == null) || !(expression is CodeVariableReferenceExpression)) { CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(parameterType.FullName, info.Name); if (expression != null) { statement.InitExpression = expression; } statements.Add(statement); expression = new CodeVariableReferenceExpression(statement.Name); } expression = new CodeDirectionExpression(@in, expression); } parameters.Add(expression); } }
public static void GetCreateValueExpression( object value, ClrSimpleTypeInfo typeDef, CodeExpressionCollection collection) { if (value == null) { collection.Add(new CodePrimitiveExpression(value)); return; } switch(typeDef.Variety) { case XmlSchemaDatatypeVariety.List: string str = ListSimpleTypeValidator.ToString(value); collection.Add(new CodePrimitiveExpression(str)); break; case XmlSchemaDatatypeVariety.Atomic: if (value is string) { collection.Add(new CodePrimitiveExpression(value)); } else { collection.Add(CreateTypedValueExpression( typeDef.InnerType.Datatype, value)); } break; case XmlSchemaDatatypeVariety.Union: GetCreateUnionValueExpression( value, typeDef as UnionSimpleTypeInfo, collection); break; default: break; } }
public void AddRange () { CodeExpression exp1 = new CodeExpression (); CodeExpression exp2 = new CodeExpression (); CodeExpression exp3 = new CodeExpression (); CodeExpressionCollection coll1 = new CodeExpressionCollection (); coll1.Add (exp1); coll1.Add (exp2); CodeExpressionCollection coll2 = new CodeExpressionCollection (); coll2.Add (exp3); coll2.AddRange (coll1); Assert.AreEqual (3, coll2.Count, "#1"); Assert.AreEqual (1, coll2.IndexOf (exp1), "#2"); Assert.AreEqual (2, coll2.IndexOf (exp2), "#3"); Assert.AreEqual (0, coll2.IndexOf (exp3), "#4"); CodeExpressionCollection coll3 = new CodeExpressionCollection (); coll3.Add (exp3); coll3.AddRange (new CodeExpression[] { exp1, exp2 }); Assert.AreEqual (3, coll2.Count, "#5"); Assert.AreEqual (1, coll2.IndexOf (exp1), "#6"); Assert.AreEqual (2, coll2.IndexOf (exp2), "#7"); Assert.AreEqual (0, coll2.IndexOf (exp3), "#8"); }
private void WriteEvents(CodeNamespace ns, CodeTypeDeclaration cls) { for (int i = 0; (this.events != null) && (i < this.events.Count); i++) { EventEntry entry = (EventEntry) this.events[i]; CodeMemberEvent event2 = new CodeMemberEvent { Name = entry.resovledEventName, Attributes = entry.eventFlags, Type = new CodeTypeReference(entry.eventHandlerCls) }; cls.Members.Add(event2); CodeMemberMethod method = new CodeMemberMethod { Name = entry.invokeMethodName, ReturnType = new CodeTypeReference(entry.retType), Attributes = MemberAttributes.Assembly | MemberAttributes.Final }; method.Parameters.Add(this.CreateParamDecl(MapTypeName(typeof(object)), "sender", false)); method.Parameters.Add(this.CreateParamDecl(entry.eventCls, "e", false)); CodeFieldReferenceExpression left = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), entry.resovledEventName); CodeBinaryOperatorExpression expression2 = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)); CodeConditionStatement statement = new CodeConditionStatement { Condition = expression2 }; CodeExpressionCollection expressions = new CodeExpressionCollection(); expressions.Add(new CodeFieldReferenceExpression(null, "sender")); expressions.Add(new CodeFieldReferenceExpression(null, "e")); CodeExpression[] array = new CodeExpression[expressions.Count]; ((ICollection) expressions).CopyTo(array, 0); CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), entry.resovledEventName, array); if (entry.retType == typeof(void)) { statement.TrueStatements.Add(new CodeExpressionStatement(expression)); } else { statement.TrueStatements.Add(new CodeMethodReturnStatement(expression)); statement.FalseStatements.Add(new CodeMethodReturnStatement(this.GetInitializer(entry.retType))); } method.Statements.Add(statement); cls.Members.Add(method); } this.WriteEventMulticaster(ns); }
private void SerializeResumeLayout(IDesignerSerializationManager manager, CodeStatementCollection statements, object control) { CodeExpressionCollection parameters = new CodeExpressionCollection(); parameters.Add(new CodePrimitiveExpression(false)); System.Type[] paramTypes = new System.Type[] { typeof(bool) }; this.SerializeMethodInvocation(manager, statements, control, "ResumeLayout", parameters, paramTypes, StatementOrdering.Append); }
public void Insert () { CodeExpression exp1 = new CodeExpression (); CodeExpression exp2 = new CodeExpression (); CodeExpressionCollection coll = new CodeExpressionCollection (); coll.Add (exp1); Assert.AreEqual (1, coll.Count, "#1"); Assert.AreEqual (0, coll.IndexOf (exp1), "#2"); coll.Insert (0, exp2); Assert.AreEqual (2, coll.Count, "#3"); Assert.AreEqual (1, coll.IndexOf (exp1), "#4"); Assert.AreEqual (0, coll.IndexOf (exp2), "#5"); }
public void AddRange_Self () { CodeExpressionCollection coll = new CodeExpressionCollection (); coll.Add (new CodeExpression ()); Assert.AreEqual (1, coll.Count, "#1"); coll.AddRange (coll); Assert.AreEqual (2, coll.Count, "#2"); }
private void CreateRegistrationParameters(CodeExpressionCollection methodParameters, XmlNodeList scriptParameters) { CodeExpression[] initializers = new CodeExpression[scriptParameters.Count]; for (int i = 0; i < scriptParameters.Count; i++) { if (scriptParameters.Item(i) is XmlElement) { XmlElement element = (XmlElement) scriptParameters.Item(i); if (PARAMETER.Equals(element.Name)) { string key = element.GetAttribute(KEY); if (key != null && key.Length != 0) { initializers[i] = new CodeObjectCreateExpression( typeof (ComponentParameter), new CodeExpression[] {new CodePrimitiveExpression(key)}); } else if (element.Value != null && element.Value.Length != 0) { initializers[i] = new CodeObjectCreateExpression( typeof (ConstantParameter), new CodeExpression[] {new CodeTypeOfExpression(element.Value)}); } else { throw new PicoCompositionException("Parameter not set"); } } } } methodParameters.Add(new CodeArrayCreateExpression( "IParameter", initializers)); }
/// <summary>Converts a list of expressions to CodeDom expressions.</summary> void ConvertExpressions(CodeExpressionCollection args, ExpressionCollection expressions) { foreach (Expression e in expressions) { _expression = null; e.Accept(this); args.Add(_expression); } }
protected void Rewrite(CodeExpressionCollection target, CodeExpressionCollection source, ref bool didRewrite) { foreach (CodeExpression item in source) { target.Add(this.Rewrite(item, ref didRewrite)); } }
public void Add_Null () { CodeExpressionCollection coll = new CodeExpressionCollection (); coll.Add ((CodeExpression) null); }