本文整理汇总了C#中PrimitiveExpression类的典型用法代码示例。如果您正苦于以下问题:C# PrimitiveExpression类的具体用法?C# PrimitiveExpression怎么用?C# PrimitiveExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrimitiveExpression类属于命名空间,在下文中一共展示了PrimitiveExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GenerateCode
protected override string GenerateCode(ITypeDefinition currentClass)
{
// string[] fields = listBox.SelectedItems.OfType<PropertyOrFieldWrapper>().Select(f2 => f2.MemberName).ToArray();
string[] fields = parameterList.Where(f => f.IsIncluded).Select(f2 => f2.MemberName).ToArray();
PrimitiveExpression formatString = new PrimitiveExpression(GenerateFormatString(currentClass, editor.Language.CodeGenerator, fields));
List<Expression> param = new List<Expression>() { formatString };
ReturnStatement ret = new ReturnStatement(new InvocationExpression(
new MemberReferenceExpression(new TypeReferenceExpression(ConvertType(KnownTypeCode.String)), "Format"),
param.Concat(fields.Select(f => new IdentifierExpression(f))).ToList()
));
if (baseCallNode != null) {
MethodDeclaration insertedOverrideMethod = refactoringContext.GetNode().PrevSibling as MethodDeclaration;
if (insertedOverrideMethod == null) {
// We are not inside of a method declaration
return null;
}
using (Script script = refactoringContext.StartScript()) {
NewLineNode nextNewLineNode = insertedOverrideMethod.NextSibling as NewLineNode;
// Find base method call and replace it by return statement
script.AddTo(insertedOverrideMethod.Body, ret);
AppendNewLine(script, insertedOverrideMethod, nextNewLineNode);
}
}
return null;
}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:30,代码来源:OverrideToStringMethodDialog.xaml.cs
示例2: VisitPrimitiveExpression
public override object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
{
if (primitiveExpression.Value is bool)
return (bool)primitiveExpression.Value ? SymbolDefined : null;
else
return null;
}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:7,代码来源:ConditionalCompilation.cs
示例3: PrimitiveEmitter
internal PrimitiveEmitter(PrimitiveExpression primitiveExpression, ILGenerator ilGenerator, IOpCodeIndexer instructionsIndexer)
: base(ilGenerator, instructionsIndexer) {
PrimitiveExpression = primitiveExpression;
Type = PrimitiveExpression.Value.GetType();
PrimitiveInstruction = InstructionsIndexer.GetInstruction(PrimitiveExpression);
}
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:7,代码来源:PrimitiveEmitter.cs
示例4: VisitPrimitiveExpression
public override object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
{
if (primitiveExpression.LiteralValue.Contains("\\"))
{
UnlockWith(primitiveExpression);
}
return base.VisitPrimitiveExpression(primitiveExpression, data);
}
开发者ID:vlad2135,项目名称:strokes,代码行数:8,代码来源:DeclareEscapeChar.cs
示例5: VisitPrimitiveExpression
public override object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
{
if(primitiveExpression.LiteralValue.StartsWith("'\\x"))
{
UnlockWith(primitiveExpression);
}
return base.VisitPrimitiveExpression(primitiveExpression, data);
}
开发者ID:clausjoergensen,项目名称:strokes,代码行数:8,代码来源:DeclareHexShorthandChar.cs
示例6: Visit
public override object Visit(PrimitiveExpression primitiveExpression, object data)
{
if (primitiveExpression.Value != null) {
// Console.WriteLine("Visiting " + primitiveExpression.Value);
return new ReturnType(primitiveExpression.Value.GetType().FullName);
}
return null;
}
开发者ID:slluis,项目名称:monodevelop-prehistoric,代码行数:8,代码来源:TypeVisitor.cs
示例7: AddFormatCallToInvocation
void AddFormatCallToInvocation (RefactoringContext context, Script script, PrimitiveExpression pExpr, InvocationExpression invocation)
{
var newInvocation = (InvocationExpression)invocation.Clone ();
newInvocation.Arguments.First ().ReplaceWith (CreateFormatString (context, pExpr, newInvocation.Arguments.Count () - 1));
newInvocation.Arguments.Add (CreateFormatArgument (context));
script.Replace (invocation, newInvocation);
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:9,代码来源:IntroduceFormatItemAction.cs
示例8: GetActions
IEnumerable<CodeAction> GetActions(ObjectCreateExpression objectCreateExpression,
PrimitiveExpression firstParam, PrimitiveExpression secondParam)
{
yield return new CodeAction(context.TranslateString("Swap parameters"), script => {
var newOCE = objectCreateExpression.Clone() as ObjectCreateExpression;
newOCE.Arguments.Clear();
newOCE.Arguments.Add(secondParam.Clone());
newOCE.Arguments.Add(firstParam.Clone());
script.Replace(objectCreateExpression, newOCE);
});
}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:11,代码来源:IncorrectExceptionParameterOrderingIssue.cs
示例9: FindMatching
private IEnumerable<PrimitiveExpression> FindMatching(LanguageElement scope, PrimitiveExpression primitiveExpression)
{
if (scope == null || primitiveExpression == null)
yield break;
ElementEnumerable primitivesEnumerable = new ElementEnumerable(scope, new PrimitiveFilter(primitiveExpression), true);
if (primitivesEnumerable == null)
yield break;
foreach (object element in primitivesEnumerable)
if (element is PrimitiveExpression)
yield return (PrimitiveExpression)element;
}
开发者ID:modulexcite,项目名称:CR_PrimitiveTab,代码行数:13,代码来源:PlugIn1.cs
示例10: GetPrimitiveExpressionAndProperty
/// <summary>
/// Gets a PrimitiveExpression and a parenting property provided the PrimitiveExpression is of type System.String and the caret is inside that string.
/// Returns true if both values are found and the contents of the string matches the name of the property.
/// </summary>
private static bool GetPrimitiveExpressionAndProperty(LanguageElement element, out PrimitiveExpression primitiveExpression, out Property property)
{
property = null;
primitiveExpression = element as PrimitiveExpression;
if (primitiveExpression == null)
return false;
if (primitiveExpression.ExpressionTypeName != "System.String")
return false;
property = primitiveExpression.GetParentProperty();
if (property == null)
return false;
return property.Name == (string)primitiveExpression.PrimitiveValue;
}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:20,代码来源:PlugIn1.cs
示例11: SortFormatTokens_CheckAvailability
private void SortFormatTokens_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)
{
_PrimitiveString = (CodeRush.Source.Active as PrimitiveExpression);
if (_PrimitiveString == null)
return;
if (_PrimitiveString.PrimitiveType != PrimitiveType.String)
return;
LanguageElement Parent = _PrimitiveString.Parent;
if (Parent == null)
return;
MethodCallExpression MCE = (Parent as MethodCallExpression);
if (MCE == null)
return;
if (MCE.Name != "Format")
return;
_tokens = new TokenGatherer().GetTokens(_PrimitiveString.Name);
if (!SequenceRenumberer.RequiresRenumbering(from item in _tokens select item.Index))
return;
ea.Available = true;
}
开发者ID:RoryBecker,项目名称:CR_SortFormatTokens,代码行数:20,代码来源:PlugIn1.cs
示例12: AddArgument
static void AddArgument(InvocationExpression newNode, IParameter parameterToAdd, bool isNextInSequence)
{
Expression defaultValue;
if (parameterToAdd.ConstantValue == null) {
defaultValue = new NullReferenceExpression();
}
else {
defaultValue = new PrimitiveExpression(parameterToAdd.ConstantValue);
}
Expression newArgument;
if (newNode.Arguments.Any(argument => argument is NamedExpression) || !isNextInSequence) {
newArgument = new NamedArgumentExpression(parameterToAdd.Name, defaultValue);
}
else {
newArgument = defaultValue;
}
newNode.Arguments.Add(newArgument);
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:18,代码来源:AddOptionalParameterToInvocationAction.cs
示例13: BuildOperatorArgumentsList
private void BuildOperatorArgumentsList(IList<Expression> arguments, IMethod method)
{
if (method != null)
{
var parameters = method.Parameters;
Expression[] result = new Expression[parameters.Count];
string[] names = new string[result.Length];
int i = 0;
foreach (var arg in arguments)
{
if (arg is NamedArgumentExpression)
{
NamedArgumentExpression namedArg = (NamedArgumentExpression)arg;
var namedParam = parameters.First(p => p.Name == namedArg.Name);
var index = parameters.IndexOf(namedParam);
result[index] = namedArg.Expression;
names[index] = namedArg.Name;
}
else
{
if (i >= result.Length)
{
var list = result.ToList();
list.AddRange(new Expression[arguments.Count - i]);
var strList = names.ToList();
strList.AddRange(new string[arguments.Count - i]);
result = list.ToArray();
names = strList.ToArray();
}
result[i] = arg;
names[i] = parameters[i].Name;
}
i++;
}
for (i = 0; i < result.Length; i++)
{
if (result[i] == null)
{
var p = parameters[i];
if (p.Type.Kind == TypeKind.Enum)
{
result[i] = new PrimitiveExpression(Helpers.GetEnumValue(this.Emitter, p.Type, p.ConstantValue));
}
else
{
result[i] = new PrimitiveExpression(p.ConstantValue);
}
names[i] = parameters[i].Name;
}
}
this.ArgumentsExpressions = result;
this.ArgumentsNames = names;
this.NamedExpressions = this.CreateNamedExpressions(names, result);
}
else
{
this.ArgumentsExpressions = arguments.ToArray();
}
}
开发者ID:RashmiPankaj,项目名称:Bridge,代码行数:69,代码来源:ArgumentsInfo.cs
示例14: BuildArgumentsList
private void BuildArgumentsList(IList<Expression> arguments)
{
Expression paramsArg = null;
string paramArgName = null;
var resolveResult = this.ResolveResult;
if (resolveResult != null)
{
var parameters = resolveResult.Member.Parameters;
var resolvedMethod = resolveResult.Member as IMethod;
var invocationResult = resolveResult as CSharpInvocationResolveResult;
int shift = 0;
if (resolvedMethod != null && invocationResult != null &&
resolvedMethod.IsExtensionMethod && invocationResult.IsExtensionMethodInvocation)
{
shift = 1;
this.ThisName = resolvedMethod.Parameters[0].Name;
this.IsExtensionMethod = true;
}
Expression[] result = new Expression[parameters.Count - shift];
string[] names = new string[result.Length];
int i = 0;
foreach (var arg in arguments)
{
if (arg is NamedArgumentExpression)
{
NamedArgumentExpression namedArg = (NamedArgumentExpression)arg;
var namedParam = parameters.First(p => p.Name == namedArg.Name);
var index = parameters.IndexOf(namedParam);
result[index] = namedArg.Expression;
names[index] = namedArg.Name;
}
else
{
if (paramsArg == null && (parameters.Count > (i + shift)) && parameters[i + shift].IsParams)
{
if (resolvedMethod.DeclaringTypeDefinition == null || !this.Emitter.Validator.IsIgnoreType(resolvedMethod.DeclaringTypeDefinition))
{
paramsArg = arg;
}
paramArgName = parameters[i + shift].Name;
}
if (i >= result.Length)
{
var list = result.ToList();
list.AddRange(new Expression[arguments.Count - i]);
var strList = names.ToList();
strList.AddRange(new string[arguments.Count - i]);
result = list.ToArray();
names = strList.ToArray();
}
result[i] = arg;
names[i] = (i + shift) < parameters.Count ? parameters[i + shift].Name : paramArgName;
}
i++;
}
for (i = 0; i < result.Length; i++)
{
if (result[i] == null)
{
var p = parameters[i + shift];
if (p.Type.Kind == TypeKind.Enum)
{
result[i] = new PrimitiveExpression(Helpers.GetEnumValue(this.Emitter, p.Type, p.ConstantValue));
}
else
{
result[i] = new PrimitiveExpression(p.ConstantValue);
}
names[i] = parameters[i + shift].Name;
}
}
this.ArgumentsExpressions = result;
this.ArgumentsNames = names;
this.ParamsExpression = paramsArg;
this.NamedExpressions = this.CreateNamedExpressions(names, result);
}
else
{
this.ArgumentsExpressions = arguments.ToArray();
}
}
开发者ID:RashmiPankaj,项目名称:Bridge,代码行数:95,代码来源:ArgumentsInfo.cs
示例15: VisitPrimitiveExpression
public void VisitPrimitiveExpression(PrimitiveExpression primitiveExpression)
{
StartNode(primitiveExpression);
writer.WritePrimitiveValue(primitiveExpression.Value, primitiveExpression.UnsafeLiteralValue);
EndNode(primitiveExpression);
}
开发者ID:jeremiahyan,项目名称:ILSpy,代码行数:6,代码来源:CSharpOutputVisitor.cs
示例16: ExtractExpression
bool ExtractExpression (Statement statement, out Expression leftSide, out Expression rightSide) {
ExpressionStatement expression = statement as ExpressionStatement;
if (expression != null) {
AssignmentExpression assignment = expression.Expression as AssignmentExpression;
if (assignment != null) {
if (assignment.Operator == AssignmentOperatorType.Add) {
leftSide = assignment.Left;
rightSide = assignment.Right;
return true;
}
if (assignment.Operator == AssignmentOperatorType.Subtract) {
leftSide = assignment.Left;
rightSide = new UnaryOperatorExpression(UnaryOperatorType.Minus, assignment.Right.Clone());
return true;
}
leftSide = null;
rightSide = null;
return false;
}
UnaryOperatorExpression unary = expression.Expression as UnaryOperatorExpression;
if (unary != null) {
leftSide = unary.Expression;
if (unary.Operator == UnaryOperatorType.Increment || unary.Operator == UnaryOperatorType.PostIncrement) {
rightSide = new PrimitiveExpression(1);
return true;
} else if (unary.Operator == UnaryOperatorType.Decrement || unary.Operator == UnaryOperatorType.PostDecrement) {
rightSide = new PrimitiveExpression(-1);
return true;
} else {
leftSide = null;
rightSide = null;
return false;
}
}
}
if (statement is EmptyStatement || statement.IsNull) {
leftSide = null;
rightSide = null;
return true;
}
BlockStatement block = statement as BlockStatement;
if (block != null) {
leftSide = null;
rightSide = null;
foreach (Statement child in block.Statements) {
Expression newLeft, newRight;
if (!ExtractExpression(child, out newLeft, out newRight)) {
leftSide = null;
rightSide = null;
return false;
}
if (newLeft == null) {
continue;
}
if (leftSide == null) {
leftSide = newLeft;
rightSide = newRight;
} else if (SameNode(leftSide, newLeft)) {
rightSide = new BinaryOperatorExpression(ParenthesizeIfNeeded(rightSide).Clone(),
BinaryOperatorType.Add,
ParenthesizeIfNeeded(newRight).Clone());
} else {
return false;
}
}
return true;
}
IfElseStatement condition = statement as IfElseStatement;
if (condition != null) {
Expression ifLeft, ifRight;
if (!ExtractExpression(condition.TrueStatement, out ifLeft, out ifRight)) {
leftSide = null;
rightSide = null;
return false;
}
Expression elseLeft, elseRight;
if (!ExtractExpression(condition.FalseStatement, out elseLeft, out elseRight)) {
leftSide = null;
rightSide = null;
return false;
}
if (ifLeft == null && elseLeft == null) {
leftSide = null;
rightSide = null;
return true;
}
if (ifLeft != null && elseLeft != null && !SameNode(ifLeft, elseLeft)) {
leftSide = null;
//.........这里部分代码省略.........
开发者ID:qhta,项目名称:NRefactory,代码行数:101,代码来源:AutoLinqSumAction.cs
示例17: VisitPrimitiveExpression
public void VisitPrimitiveExpression(PrimitiveExpression primitiveExpression)
{
StartNode(primitiveExpression);
if (!string.IsNullOrEmpty(primitiveExpression.LiteralValue)) {
formatter.WriteToken(primitiveExpression.LiteralValue);
} else {
WritePrimitiveValue(primitiveExpression.Value);
}
EndNode(primitiveExpression);
}
开发者ID:x-strong,项目名称:ILSpy,代码行数:10,代码来源:CSharpOutputVisitor.cs
示例18: VisitPrimitiveExpression
public virtual void VisitPrimitiveExpression(PrimitiveExpression primitiveExpression)
{
VisitChildren (primitiveExpression);
}
开发者ID:modulexcite,项目名称:ICSharpCode.Decompiler-retired,代码行数:4,代码来源:DepthFirstAstVisitor.cs
示例19: DivideBySize
/// <summary>
/// Divides expr by the size of 'type'.
/// </summary>
Expression DivideBySize(Expression expr, TypeReference type)
{
CastExpression cast = expr as CastExpression;
if (cast != null && cast.Type is PrimitiveType && ((PrimitiveType)cast.Type).Keyword == "int")
expr = cast.Expression.Detach();
Expression sizeOfExpression;
switch (TypeAnalysis.GetInformationAmount(type)) {
case 1:
case 8:
sizeOfExpression = new PrimitiveExpression(1);
break;
case 16:
sizeOfExpression = new PrimitiveExpression(2);
break;
case 32:
sizeOfExpression = new PrimitiveExpression(4);
break;
case 64:
sizeOfExpression = new PrimitiveExpression(8);
break;
default:
sizeOfExpression = new SizeOfExpression { Type = AstBuilder.ConvertType(type) };
break;
}
BinaryOperatorExpression boe = expr as BinaryOperatorExpression;
if (boe != null && boe.Operator == BinaryOperatorType.Multiply && sizeOfExpression.IsMatch(boe.Right))
return boe.Left.Detach();
if (sizeOfExpression.IsMatch(expr))
return new PrimitiveExpression(1);
return new BinaryOperatorExpression(expr, BinaryOperatorType.Divide, sizeOfExpression);
}
开发者ID:JustasB,项目名称:cudafy,代码行数:38,代码来源:AstMethodBodyBuilder.cs
示例20: VisitPrimitiveExpression
public virtual void VisitPrimitiveExpression(PrimitiveExpression primitiveExpression)
{
if (this.ThrowException)
{
throw (Exception)this.CreateException(primitiveExpression);
}
}
开发者ID:fabriciomurta,项目名称:BridgeUnified,代码行数:7,代码来源:Visitor.Exception.cs
注:本文中的PrimitiveExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论