本文整理汇总了C#中SyntaxGenerator.DottedName方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxGenerator.DottedName方法的具体用法?C# SyntaxGenerator.DottedName怎么用?C# SyntaxGenerator.DottedName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxGenerator
的用法示例。
在下文中一共展示了SyntaxGenerator.DottedName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateEnsureProxyMethod
private SyntaxNode CreateEnsureProxyMethod(Compilation compilation, SyntaxGenerator g, GenerationNameTable nameTable, bool asAsync)
{
/*
private async System.Threading.Tasks.Task EnsureProxyAsync()
{
if (m_cachedProxy != null && (
((System.ServiceModel.ICommunicationObject)m_cachedProxy).State == System.ServiceModel.CommunicationState.Faulted ||
((System.ServiceModel.ICommunicationObject)m_cachedProxy).State == System.ServiceModel.CommunicationState.Closed))
{
await CloseProxyAsync().ConfigureAwait(false);
}
if (m_cachedProxy == null)
{
var proxy = m_proxyFactory();
await System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)proxy).BeginOpen, ((System.ServiceModel.ICommunicationObject)proxy).EndOpen, null).ConfigureAwait(false);
m_cachedProxy = proxy;
}
}
*/
return
g.MethodDeclaration(
asAsync ? nameTable[MemberNames.EnsureProxyAsyncMethod] : nameTable[MemberNames.EnsureProxyMethod],
returnType: asAsync ? g.TypeExpression(compilation.RequireType<Task>()) : null,
accessibility: Accessibility.Private,
modifiers: asAsync ? DeclarationModifiers.Async : DeclarationModifiers.None,
statements: new SyntaxNode[]
{
//if (m_cachedProxy != null && (
// ((System.ServiceModel.ICommunicationObject)m_cachedProxy).State == System.ServiceModel.CommunicationState.Faulted ||
// ((System.ServiceModel.ICommunicationObject)m_cachedProxy).State == System.ServiceModel.CommunicationState.Closed))
g.IfStatement(
g.LogicalAndExpression(
// m_cachedProxy != null
g.ReferenceNotEqualsExpression(
g.MemberAccessExpression(
g.ThisExpression(),
nameTable[MemberNames.CachedProxyField]
),
g.NullLiteralExpression()
),
g.LogicalOrExpression(
// ((System.ServiceModel.ICommunicationObject)m_cachedProxy).State == System.ServiceModel.CommunicationState.Faulted
g.ValueEqualsExpression(
g.MemberAccessExpression(
g.CastExpression(
compilation.RequireTypeByMetadataName("System.ServiceModel.ICommunicationObject"),
g.MemberAccessExpression(
g.ThisExpression(),
nameTable[MemberNames.CachedProxyField]
)
),
"State"
),
g.DottedName("System.ServiceModel.CommunicationState.Faulted")
),
// ((System.ServiceModel.ICommunicationObject)m_cachedProxy).State == System.ServiceModel.CommunicationState.Faulted
g.ValueEqualsExpression(
g.MemberAccessExpression(
g.CastExpression(
compilation.RequireTypeByMetadataName("System.ServiceModel.ICommunicationObject"),
g.MemberAccessExpression(
g.ThisExpression(),
nameTable[MemberNames.CachedProxyField]
)
),
"State"
),
g.DottedName("System.ServiceModel.CommunicationState.Closed")
)
)
),
new SyntaxNode[]
{
// await CloseProxyAsync(false).ConfigureAwait(false);
// or
// CloseProxy(false);
AwaitExpressionIfAsync(g, asAsync,
g.InvocationExpression(
g.MemberAccessExpression(
g.ThisExpression(),
asAsync ? nameTable[MemberNames.CloseProxyAsyncMethod] : nameTable[MemberNames.CloseProxyMethod]
),
g.FalseLiteralExpression()
)
)
}
),
g.IfStatement(
g.ReferenceEqualsExpression(
g.MemberAccessExpression(
g.ThisExpression(),
nameTable[MemberNames.CachedProxyField]
),
g.NullLiteralExpression()
),
new SyntaxNode[]
{
g.LocalDeclarationStatement(
"proxy",
//.........这里部分代码省略.........
示例2: CreateNewMethod
private static SyntaxNode CreateNewMethod(
SyntaxGenerator generator, IMethodSymbol methodSymbol, int parameterIndex, Compilation compilation)
{
// create original parameter decl
var originalParameter = generator.ParameterDeclaration(methodSymbol.Parameters[parameterIndex]);
// replace original parameter type to System.Uri
var newParameter = generator.ReplaceNode(originalParameter, generator.GetType(originalParameter), generator.DottedName("System.Uri"));
// create original method decl
var original = generator.MethodDeclaration(methodSymbol, generator.DefaultMethodBody(compilation));
// get parameters from original method decl
var originalParameters = generator.GetParameters(original);
// replace one of parameter to new one
return generator.ReplaceNode(original, originalParameters[parameterIndex], newParameter);
}
示例3: CreateStaticCloseProxyMethod
private SyntaxNode CreateStaticCloseProxyMethod(Compilation compilation, SyntaxGenerator g, GenerationNameTable nameTable, bool asAsync)
{
//private static void CloseProxy(System.ServiceModel.ICommunicationObject proxy, bool alwaysAbort)
//{
// try
// {
// if (proxy != null && proxy.State != System.ServiceModel.CommunicationState.Closed)
// {
// if (!alwaysAbort && proxy.State != System.ServiceModel.CommunicationState.Faulted)
// {
// proxy.Close();
// }
// else
// {
// proxy.Abort();
// }
// }
// }
// catch (System.ServiceModel.CommunicationException)
// {
// proxy.Abort();
// }
// catch (System.TimeoutException)
// {
// proxy.Abort();
// }
// catch
// {
// proxy.Abort();
// throw;
// }
//}
return g.MethodDeclaration(
asAsync ? nameTable[MemberNames.CloseProxyAsyncMethod] : nameTable[MemberNames.CloseProxyMethod],
accessibility: Accessibility.Private,
returnType: asAsync ? g.TypeExpression(compilation.RequireType<Task>()) : null,
modifiers: (asAsync ? DeclarationModifiers.Async : DeclarationModifiers.None) | DeclarationModifiers.Static,
parameters: new SyntaxNode[]
{
g.ParameterDeclaration("proxy", g.TypeExpression(compilation.RequireTypeByMetadataName("System.ServiceModel.ICommunicationObject"))),
g.ParameterDeclaration("alwaysAbort", g.TypeExpression(SpecialType.System_Boolean))
},
statements: new SyntaxNode[]
{
g.TryCatchStatement(
new SyntaxNode[]
{
// if (proxy != null && proxy.State != System.ServiceModel.CommunicationState.Closed)
g.IfStatement(
g.LogicalAndExpression(
g.ReferenceNotEqualsExpression(
g.IdentifierName("proxy"),
g.NullLiteralExpression()
),
g.ValueNotEqualsExpression(
g.MemberAccessExpression(
g.IdentifierName("proxy"),
"State"
),
g.DottedName("System.ServiceModel.CommunicationState.Closed")
)
),
new SyntaxNode[]
{
// if (!alwaysAbort && proxy.State != System.ServiceModel.CommunicationState.Faulted)
g.IfStatement(
g.LogicalAndExpression(
g.LogicalNotExpression(
g.IdentifierName("alwaysAbort")
),
g.ValueNotEqualsExpression(
g.MemberAccessExpression(
g.IdentifierName("proxy"),
"State"
),
g.DottedName("System.ServiceModel.CommunicationState.Faulted")
)
),
new SyntaxNode[]
{
g.ExpressionStatement(
asAsync ?
// await System.Threading.Tasks.Task.Factory.FromAsync(proxy.BeginClose, proxy.EndClose, null).ConfigureAwait(false);
AwaitExpression(g,
g.InvocationExpression(
g.DottedName("System.Threading.Tasks.Task.Factory.FromAsync"),
g.DottedName("proxy.BeginClose"),
g.DottedName("proxy.EndClose"),
g.NullLiteralExpression()
)
)
:
// proxy.Close();
g.InvocationExpression(
g.MemberAccessExpression(
g.IdentifierName("proxy"),
"Close"
)
//.........这里部分代码省略.........