本文整理汇总了C#中ICSharpCode.NRefactory.Ast.TypeReference类的典型用法代码示例。如果您正苦于以下问题:C# TypeReference类的具体用法?C# TypeReference怎么用?C# TypeReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeReference类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了TypeReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: add_Method
public static MethodDeclaration add_Method(this TypeDeclaration typeDeclaration, string methodName, Dictionary<string, object> invocationParameters, BlockStatement body)
{
var newMethod = new MethodDeclaration
{
Name = methodName,
//Modifier = Modifiers.None | Modifiers.Public | Modifiers.Static,
Modifier = Modifiers.None | Modifiers.Public,
Body = body
};
newMethod.setReturnType();
if (invocationParameters != null)
foreach (var invocationParameter in invocationParameters)
{
var parameterType = new TypeReference(
(invocationParameter.Value != null && invocationParameter.Key != "returnData")
? invocationParameter.Value.typeFullName()
: "System.Object", true);
var parameter = new ParameterDeclarationExpression(parameterType, invocationParameter.Key);
newMethod.Parameters.Add(parameter);
}
typeDeclaration.AddChild(newMethod);
return newMethod;
}
示例2: LocalLookupVariable
public LocalLookupVariable(TypeReference typeRef, Location startPos, Location endPos, bool isConst)
{
this.typeRef = typeRef;
this.startPos = startPos;
this.endPos = endPos;
this.isConst = isConst;
}
示例3: add_Variable
public static VariableDeclaration add_Variable(this BlockStatement blockDeclaration, string name, Expression expression, TypeReference typeReference)
{
var variableDeclaration = new VariableDeclaration(name, expression) {TypeReference = typeReference};
var localVariableDeclaration = new LocalVariableDeclaration(variableDeclaration);
blockDeclaration.append(localVariableDeclaration);
return variableDeclaration;
}
示例4: TrackedVisitInvocationExpression
public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
if (invocationExpression.TargetObject is FieldReferenceExpression)
{
FieldReferenceExpression targetObject = (FieldReferenceExpression) invocationExpression.TargetObject;
if (targetObject.FieldName == "toArray" || targetObject.FieldName == "ToArray")
{
Expression invoker = targetObject.TargetObject;
TypeReference invokerType = GetExpressionType(invoker);
if (invokerType != null && collectionTypes.Contains(invokerType.Type))
{
if (invocationExpression.Arguments.Count == 1)
{
Expression argExpression = (Expression) invocationExpression.Arguments[0];
if (argExpression is ArrayCreateExpression)
{
InvocationExpression newInvocation = invocationExpression;
TypeReference old = ((ArrayCreateExpression) argExpression).CreateType;
TypeReference tr = new TypeReference(old.Type);
TypeOfExpression tof = new TypeOfExpression(tr);
tr.Parent = tof;
tof.Parent = newInvocation;
newInvocation.Arguments.Clear();
newInvocation.Arguments.Add(tof);
ReplaceCurrentNode(newInvocation);
}
}
}
}
}
return base.TrackedVisitInvocationExpression(invocationExpression, data);
}
示例5: CreateReturnType
public static IReturnType CreateReturnType(TypeReference reference, NRefactoryResolver resolver)
{
return CreateReturnType(reference,
resolver.CallingClass, resolver.CallingMember,
resolver.CaretLine, resolver.CaretColumn,
resolver.ProjectContent, ReturnTypeOptions.None);
}
示例6: TrackedVisitTypeReference
public override object TrackedVisitTypeReference(TypeReference typeReference, object data)
{
string name = typeReference.Type;
if (name.IndexOf('.') != -1)
Add(name);
return base.TrackedVisitTypeReference(typeReference, data);
}
示例7: AddParameter
/// <summary>
/// Adds a <see cref="ParameterDeclarationExpression"/> to <see cref="ParametrizedNode.Parameters"/> in a single
/// call, for convenience.
/// </summary>
///
/// <param name="node">
/// The method or constructor to add the parameter to.
/// </param>
///
/// <param name="parameterType">
/// The <see cref="TypeReference"/> of the parameter to add.
/// </param>
///
/// <param name="parameterName">
/// The name of the parameter to add.
/// </param>
///
/// <returns>
/// The <see cref="ParameterDeclarationExpression"/> instance that was created and added to
/// <paramref name="node"/>.
/// </returns>
public static ParameterDeclarationExpression AddParameter(this ParametrizedNode node,
TypeReference parameterType, string parameterName)
{
var parameter = new ParameterDeclarationExpression(parameterType, parameterName);
node.Parameters.Add(parameter);
return parameter;
}
示例8: CreateDefaultValueForType
public static Expression CreateDefaultValueForType(TypeReference type)
{
if (type != null && !type.IsArrayType) {
switch (type.Type) {
case "System.SByte":
case "System.Byte":
case "System.Int16":
case "System.UInt16":
case "System.Int32":
case "System.UInt32":
case "System.Int64":
case "System.UInt64":
case "System.Single":
case "System.Double":
return new PrimitiveExpression(0, "0");
case "System.Char":
return new PrimitiveExpression('\0', "'\\0'");
case "System.Object":
case "System.String":
return new PrimitiveExpression(null, "null");
case "System.Boolean":
return new PrimitiveExpression(false, "false");
default:
return new DefaultValueExpression(type);
}
} else {
return new PrimitiveExpression(null, "null");
}
}
示例9: GenerateCode
public override void GenerateCode(List<AbstractNode> nodes, IList items)
{
TypeReference stringReference = new TypeReference("System.String");
MethodDeclaration method = new MethodDeclaration("ToString",
Modifiers.Public | Modifiers.Override,
stringReference,
null, null);
method.Body = new BlockStatement();
Expression target = new FieldReferenceExpression(new TypeReferenceExpression(stringReference),
"Format");
InvocationExpression methodCall = new InvocationExpression(target);
StringBuilder formatString = new StringBuilder();
formatString.Append('[');
formatString.Append(currentClass.Name);
for (int i = 0; i < items.Count; i++) {
formatString.Append(' ');
formatString.Append(codeGen.GetPropertyName(((FieldWrapper)items[i]).Field.Name));
formatString.Append("={");
formatString.Append(i);
formatString.Append('}');
}
formatString.Append(']');
methodCall.Arguments.Add(new PrimitiveExpression(formatString.ToString(), formatString.ToString()));
foreach (FieldWrapper w in items) {
methodCall.Arguments.Add(new FieldReferenceExpression(new ThisReferenceExpression(), w.Field.Name));
}
method.Body.AddChild(new ReturnStatement(methodCall));
nodes.Add(method);
}
示例10: HasAssignmentsVisitor
public HasAssignmentsVisitor(string name, TypeReference type, Location startRange, Location endRange)
{
this.name = name;
this.type = type;
this.startRange = startRange;
this.endRange = endRange;
}
示例11: TrackedVisitBlockStatement
public override object TrackedVisitBlockStatement(BlockStatement blockStatement, object data)
{
blockStatement.Children.Clear();
TypeReference notImplmentedException = new TypeReference("System.NotImplementedException");
ObjectCreateExpression objectCreate = new ObjectCreateExpression(notImplmentedException, new List<Expression>());
blockStatement.Children.Add(new ThrowStatement(objectCreate));
return null;
}
示例12: GetArgumentTypes
public TypeReference[] GetArgumentTypes(string sig)
{
Match m = methodRegex.Match(sig);
int count = m.Groups["param"].Captures.Count;
TypeReference[] arguments = new TypeReference[count];
for (int i = 0; i < count; i++)
arguments[i] = GetTypeReference(m.Groups["param"].Captures[i].Value);
return arguments;
}
示例13: HasReturnValue_HasVoid
public void HasReturnValue_HasVoid()
{
var methodToTest = new MethodDeclaration();
var retval = new TypeReference("void");
methodToTest.TypeReference = retval;
var victim = new TestableMethodTemplate(methodToTest, null);
Assert.IsFalse(victim.HasReturnValue);
}
示例14: HasReturnValue_HasOne
public void HasReturnValue_HasOne()
{
var methodToTest = new MethodDeclaration();
var retval = new TypeReference("string", new[] { 0 });
methodToTest.TypeReference = retval;
var victim = new TestableMethodTemplate(methodToTest, null);
Assert.IsTrue(victim.HasReturnValue);
}
示例15: IsIn
bool IsIn(TypeReference type, List<TypeReference> list)
{
foreach (TypeReference tr in list) {
if (tr.Type == type.Type)
return true;
}
return false;
}