本文整理汇总了C#中JsExpression.GetLogicalTarget方法的典型用法代码示例。如果您正苦于以下问题:C# JsExpression.GetLogicalTarget方法的具体用法?C# JsExpression.GetLogicalTarget怎么用?C# JsExpression.GetLogicalTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsExpression
的用法示例。
在下文中一共展示了JsExpression.GetLogicalTarget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryAccessorAssignment
public bool TryAccessorAssignment(SyntaxKind type, ISymbol leftSymbol, ISymbol rightSymbol, JsExpression left, JsExpression right, out JsExpression result)
{
// Special handling for property and event assignments, since those have to be translated to a set/add/remove_PropertyName invocation.
if ((!(leftSymbol is IPropertySymbol) || !IsMinimizedAutoProperty((IPropertySymbol)leftSymbol)) && (type == SyntaxKind.SimpleAssignmentExpression || type == SyntaxKind.AddAssignmentExpression || type == SyntaxKind.SubtractAssignmentExpression))
{
if (leftSymbol is IPropertySymbol || leftSymbol is IEventSymbol)
{
var isExported = leftSymbol.IsExported();
var nameOverride = leftSymbol.GetAttributeValue<string>(Context.Instance.JsAttributeType, "Name");
var target = left.GetLogicalTarget();
var arguments = new List<JsExpression>();
var property = leftSymbol as IPropertySymbol;
var isCall = false;
if (left is JsInvocationExpression)
{
var invocationExpression = (JsInvocationExpression)left;
if (invocationExpression.Target is JsMemberReferenceExpression)
{
var innerMemberReference = (JsMemberReferenceExpression)invocationExpression.Target;
if (innerMemberReference.Name == "call" && target is JsMemberReferenceExpression && ((JsMemberReferenceExpression)target).Name.StartsWith("get_"))
{
isCall = true;
target = target.GetLogicalTarget();
}
}
arguments.AddRange(invocationExpression.Arguments);
}
arguments.Add(right);
if (leftSymbol is IPropertySymbol)
{
var methodSymbol = ((IPropertySymbol)leftSymbol).SetMethod;
JsExpression inline;
if (TryInline(methodSymbol, target, arguments.ToArray(), out inline))
{
result = inline;
return true;
}
}
if (isExported)
{
IMethodSymbol methodSymbol;
if (leftSymbol is IPropertySymbol)
methodSymbol = ((IPropertySymbol)leftSymbol).SetMethod;
else
{
var @event = (IEventSymbol)leftSymbol;
switch (type)
{
case SyntaxKind.AddAssignmentExpression:
methodSymbol = @event.AddMethod;
break;
default:
methodSymbol = @event.RemoveMethod;
break;
}
}
target = target.Member(methodSymbol.Name);
if (isCall)
target = target.Member("call");
result = target.Invoke(arguments.ToArray());
return true;
}
else if (nameOverride != null && property != null && property.SetMethod.Parameters.Count() > 1)
{
result = target.Member(nameOverride).Invoke(arguments.ToArray());
return true;
}
}
}
result = null;
return false;
}