本文整理汇总了C#中System.CodeDom.CodeExpressionCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# CodeExpressionCollection.Add方法的具体用法?C# CodeExpressionCollection.Add怎么用?C# CodeExpressionCollection.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.CodeDom.CodeExpressionCollection
的用法示例。
在下文中一共展示了CodeExpressionCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clone
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;
}
示例2: AnalyzeUsage
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);
}
示例3: Constructor1_Deny_Unrestricted
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);
}
示例4: AddTypes
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);
}
}
示例5: GenerateMethods
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);
//.........这里部分代码省略.........
示例6: AddParam
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));
}
}
示例7: VisitExpressionList
//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;
}
示例8: GenerateEntityQueryMethod
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)
//.........这里部分代码省略.........
示例9: Remove
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");
}
示例10: WriteEventMulticaster
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)));
//.........这里部分代码省略.........
示例11: GenerateAssignStatement
/// <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);
}
示例12: BuildParameters
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);
}
}
示例13: GenerateMethod
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);
}
示例14: AddDeclaredParameters
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);
}
}
示例15: CreateMethod
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;
}