本文整理汇总了C#中System.Reflection.PropertyInfo.GetKeyProperty方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetKeyProperty方法的具体用法?C# PropertyInfo.GetKeyProperty怎么用?C# PropertyInfo.GetKeyProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.GetKeyProperty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: createGetMethod
//.........这里部分代码省略.........
.AddArgumentListArguments()
)
)
).WithLeadingTrivia(Comment("// settings ")),
ExpressionStatement(
InvocationExpression(
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
IdentifierName(settings),
IdentifierName("ServerUri_Get"))
)
.AddArgumentListArguments(
Argument(
ParenthesizedLambdaExpression(
LiteralExpression(SyntaxKind.NullLiteralExpression)
)
)
)
)
);
var httpClient = Identifier("httpClient");
method = method.AddBodyStatements(
LocalDeclarationStatement(
Extensions.VariableDeclaration(httpClient.Text,
EqualsValueClause(
ObjectCreationExpression(ParseTypeName("StubIHttpClient"))
.AddArgumentListArguments()
)
)
).WithLeadingTrivia(Comment("// Http Client"))
);
var k = pi.GetKeyProperty();
var keySy = ParseTypeName(k.PropertyType.Name);
Random rand = new Random();
var serverContext = Identifier("serverContext");
var results = Identifier("results");
method = method.AddBodyStatements(
LocalDeclarationStatement(
Extensions.VariableDeclaration(serverContext.Text,
EqualsValueClause(
ObjectCreationExpression(ParseTypeName("ServerContext"))
.AddArgumentListArguments(
Argument(IdentifierName(settings)),
Argument(IdentifierName(create)),
Argument(IdentifierName(httpClient))
)
)
)
).WithLeadingTrivia(Comment("// Server ")),
LocalDeclarationStatement(
Extensions.VariableDeclaration(key.Text,
EqualsValueClause(keySy.GetRandomValue(rand))
, keySy.GetTypeString()
)
),
LocalDeclarationStatement(
Extensions.VariableDeclaration(
results.Text,
EqualsValueClause(
AwaitExpression(
InvocationExpression(
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
示例2: createCommonResultIfStatments
private StatementSyntax[] createCommonResultIfStatments(Type t, PropertyInfo[] pi, String resultName)
{
var key = pi.GetKeyProperty();
var list = new List<StatementSyntax>();
/* var check = checkCommon();
if(check.Item1 != RequestStatus.Success)
{
return new TemperatureEntryResult(check.Item1, null, default(Guid));
}
var builder = check.Item2;
*/
var check = Identifier("check");
list.Add(
LocalDeclarationStatement(
Extensions.VariableDeclaration(check.Text,
EqualsValueClause(
InvocationExpression(
IdentifierName("checkCommon")
).AddArgumentListArguments()
)
)
)
);
list.Add(
IfStatement(
BinaryExpression(SyntaxKind.NotEqualsExpression,
Extensions.MemberAccess(
IdentifierName(check),
IdentifierName("Item1")
),
Extensions.MemberAccess(
IdentifierName("RequestStatus"),
IdentifierName("Success")
)
),
Block(
ReturnStatement(
ObjectCreationExpression(ParseTypeName(resultName))
.AddArgumentListArguments(
Argument(Extensions.MemberAccess(
IdentifierName(check),
IdentifierName("Item1")
)),
Argument(LiteralExpression(SyntaxKind.NullLiteralExpression)),
Argument(IdentifierName(keyName))
)
)
)
)
);
list.Add(
LocalDeclarationStatement(
Extensions.VariableDeclaration("builder",
EqualsValueClause(
Extensions.MemberAccess(
IdentifierName(check),
IdentifierName("Item2")
)
)
)
)
);
/*
HttpBaseProtocolFilter httpFilter = new HttpBaseProtocolFilter();
httpFilter.CookieManager.SetCookie(cookie);*/
return list.ToArray();
}
示例3: createGetMethod
private MethodDeclarationSyntax createGetMethod(Type t, PropertyInfo[] pi)
{
var key = pi.GetKeyProperty();
var body = new List<StatementSyntax>();
body.AddRange(createCommonResultIfStatments(t, pi, $"{t.Name}Result"));
body.AddRange(createGetCall(t, pi));
var method = taskBuilder.AsyncMethod(
TypeArgumentList().AddArguments(ParseTypeName($"{t.Name}Result")),
$"Get{t.Name}Async",
Block().AddStatements(body.ToArray())
);
method = method.AddParameterListParameters(
Parameter(keyName).WithType(ParseTypeName(key.PropertyType.Name)));
method = method.WithModifiers(method.Modifiers.Insert(0, Token(SyntaxKind.PublicKeyword)));
return method;
}
示例4: createGetCall
private StatementSyntax[] createGetCall(Type t, PropertyInfo[] pi)
{
var result = Identifier("result");
var list = new List<StatementSyntax>();
var key = pi.GetKeyProperty();
list.Add(ExpressionStatement(
AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("builder"),
IdentifierName("Path")
),
InterpolatedStringExpression(Token(SyntaxKind.InterpolatedStringStartToken))
.AddContents(
InterpolatedStringText()
.WithTextToken(
Token(TriviaList(),
SyntaxKind.InterpolatedStringTextToken,
$"/api/{t.Name}/",
$"/api/{t.Name}/",
TriviaList())),
Interpolation(IdentifierName(keyName)))
)
)
);
list.Add(LocalDeclarationStatement(
VariableDeclaration(ParseTypeName("HttpClientResult"))
.AddVariables(
VariableDeclarator(result)
.WithInitializer(
EqualsValueClause(LiteralExpression(SyntaxKind.NullLiteralExpression))
)
)
));
var ce = Identifier("ce");
var tryStatment = TryStatement()
.WithBlock(
Block(
ExpressionStatement(
AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
IdentifierName(result),
AwaitExpression(
InvocationExpression(
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("client"),
IdentifierName("GetAsync")
)
)
.AddArgumentListArguments(
Argument(
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("builder"),
IdentifierName("Uri")
)
)
)
)
)
)));
if(String.Compare(variables.GetValue("IsUWP"), "1") == 0)
{
tryStatment = tryStatment.AddCatches(
CatchClause()
.WithDeclaration(
CatchDeclaration(IdentifierName("COMException"))
.WithIdentifier(ce)
)
.AddBlockStatements(
IfStatement(
BinaryExpression(SyntaxKind.EqualsExpression,
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
IdentifierName(ce),
IdentifierName("HResult")
),
LiteralExpression(SyntaxKind.NumericLiteralExpression,
Literal(-2147012867)
)
),
Block()
.AddStatements(
ReturnStatement(
ObjectCreationExpression(ParseTypeName($"{t.Name}Result"))
.AddArgumentListArguments(
Argument(
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
IdentifierName(ServerSDKStatusConstants.EnumName),
IdentifierName(ServerSDKStatusConstants.UnableToConnectToServer))
),
Argument(
LiteralExpression(SyntaxKind.NullLiteralExpression)
)
,
Argument(
IdentifierName(keyName)
),
Argument(
IdentifierName(ce)
)
)
//.........这里部分代码省略.........