本文整理汇总了C#中System.CodeDom.CodeMemberMethod.SetMethodParams方法的典型用法代码示例。如果您正苦于以下问题:C# CodeMemberMethod.SetMethodParams方法的具体用法?C# CodeMemberMethod.SetMethodParams怎么用?C# CodeMemberMethod.SetMethodParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.CodeDom.CodeMemberMethod
的用法示例。
在下文中一共展示了CodeMemberMethod.SetMethodParams方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMethodsWrapper
public static IEnumerable<CodeTypeMember> CreateMethodsWrapper(
this INamedTypeSymbol typeToWrap,
WrapsAttrNameChangeView methodToWrapNameChangeView,
IList<string> namespaces
)
{
// get all the methods of this name
IEnumerable<IMethodSymbol> wrappedMethodsInfos =
typeToWrap.GetInstanceMethodsOfName(methodToWrapNameChangeView.Name);
List<CodeTypeMember> result = new List<CodeTypeMember>();
foreach(IMethodSymbol methodSymbol in wrappedMethodsInfos)
{
CodeMemberMethod method = new CodeMemberMethod();
method.Attributes = methodSymbol.GetFlags(methodToWrapNameChangeView.TheEncapsulationLevel);
method.Name = methodToWrapNameChangeView.WrapperName;
if (!methodSymbol.ReturnsVoid)
{
ITypeSymbol returnType = methodSymbol.ReturnType;
method.ReturnType = returnType.GetTypeReference(namespaces);
}
List<CodeExpression> passedParameters =
method.SetMethodParams(methodSymbol, namespaces);
string wrappedObjectName = typeToWrap.Name.GetWrappedObjectFieldName();
// invoking the function
CodeMethodInvokeExpression methodInvokeExpression =
new CodeMethodInvokeExpression
(
new CodeTypeReferenceExpression(wrappedObjectName),
methodToWrapNameChangeView.Name,
passedParameters.ToArray()
);
if (!methodSymbol.ReturnsVoid)
{
ITypeSymbol returnType = methodSymbol.ReturnType;
CodeVariableDeclarationStatement variableDeclarationStatement =
new CodeVariableDeclarationStatement
(
returnType.GetTypeReference(namespaces),
"result",
methodInvokeExpression
);
method.Statements.Add(variableDeclarationStatement);
CodeMethodReturnStatement returnStatement =
new CodeMethodReturnStatement(new CodeVariableReferenceExpression("result"));
method.Statements.Add(returnStatement);
}
else
{
method.Statements.Add(methodInvokeExpression);
}
result.Add(method);
}
return result;
}
示例2: CreateHandlerMethod
public static CodeTypeMember CreateHandlerMethod(
this OneWayEventWrapsView oneWayEventWrapsView,
IList<string> namespaces
)
{
string methodName = oneWayEventWrapsView.GetHandlerMethodName();
CodeMemberMethod method = new CodeMemberMethod
{
Attributes = MemberAttributes.Private,
Name = methodName
};
INamedTypeSymbol wrappedType = oneWayEventWrapsView.TheWrappedType;
string wrappedEventName = oneWayEventWrapsView.Name;
string wrapperEventName = oneWayEventWrapsView.WrapperName;
IEventSymbol eventSymbol = wrappedType.GetMembers(wrappedEventName).FirstOrDefault() as IEventSymbol;
ITypeSymbol eventTypeSymbol = eventSymbol.Type;
CodeTypeReference eventTypeReference = eventTypeSymbol.GetTypeReference(namespaces);
IMethodSymbol invokeMethodSymbol = eventTypeSymbol.GetMembers("Invoke").FirstOrDefault() as IMethodSymbol;
List<CodeExpression> passedParameters =
method.SetMethodParams(invokeMethodSymbol, namespaces, oneWayEventWrapsView.ThisArgumentName);
CodeConditionStatement codeConditionStatement = GetNotNullCondition(wrapperEventName);
CodeDelegateInvokeExpression methodInvokeExpression =
new CodeDelegateInvokeExpression
(
new CodeEventReferenceExpression { EventName = wrapperEventName },
passedParameters.ToArray()
);
codeConditionStatement.TrueStatements.Add(methodInvokeExpression);
method.Statements.Add(codeConditionStatement);
return method;
}