本文整理汇总了C#中System.CodeDom.CodeExpressionCollection.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# CodeExpressionCollection.Cast方法的具体用法?C# CodeExpressionCollection.Cast怎么用?C# CodeExpressionCollection.Cast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.CodeDom.CodeExpressionCollection
的用法示例。
在下文中一共展示了CodeExpressionCollection.Cast方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateMethods
//.........这里部分代码省略.........
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
);
示例2: 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);
}
示例3: 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)
//.........这里部分代码省略.........
示例4: VisitCodeExpressionCollection
/// <summary>
/// Visits a <see cref="CodeExpressionCollection"/>.
/// </summary>
/// <param name="codeExpressionCollection">The <see cref="CodeExpressionCollection"/> to visit.</param>
protected virtual void VisitCodeExpressionCollection(CodeExpressionCollection codeExpressionCollection)
{
// Visit all of the CodeExpression items in the collection.
foreach (CodeExpression item in codeExpressionCollection.Cast<CodeExpression>())
{
this.VisitCodeExpression(item);
}
}