private void ReplaceWithComponentReference(Node node, string name) { Expression argument; ConstructorInfo constructorInfo; name = name.Substring(1); var entity = NameResolutionService.ResolveQualifiedName(name); if (node.ParentNode.NodeType == NodeType.GenericReferenceExpression) { var genericRef = (GenericReferenceExpression)(node = node.ParentNode); entity = NameResolutionService.ResolveGenericReferenceExpression(genericRef, entity); name = genericRef.ToCodeString(); } if (entity == null || entity.EntityType != EntityType.Type) { constructorInfo = _componentReferenceConstructor; argument = CodeBuilder.CreateStringLiteral(name); } else { constructorInfo = _componentReferenceTypeConstructor; argument = CodeBuilder.CreateReference(entity); } var constructor = new ExternalConstructor(My <IReflectionTypeSystemProvider> .Instance, constructorInfo); var invocation = CodeBuilder.CreateConstructorInvocation(constructor, argument); node.ParentNode.Replace(node, invocation); }
public override void OnReferenceExpression(ReferenceExpression node) { IEntity entity = NameResolutionService.Resolve(node.Name); if (entity != null) { base.OnReferenceExpression(node); return; } if (node.Name.StartsWith("@")) { string refComponentName = node.Name.Substring(1); StringLiteralExpression literal = CodeBuilder.CreateStringLiteral(refComponentName); ExternalConstructor constructor = new ExternalConstructor(TypeSystemServices, _componentReferenceConstructor); MethodInvocationExpression invocation = CodeBuilder.CreateConstructorInvocation(constructor, literal); node.ParentNode.Replace(node, invocation); return; } else if (node.ParentNode is MethodInvocationExpression) { MethodInvocationExpression mie = (MethodInvocationExpression)node.ParentNode; //Transform the first parameter of Component ctor to string. if (mie.Target.ToString() == "Component") { StringLiteralExpression literal = CodeBuilder.CreateStringLiteral(node.Name); mie.Replace(node, literal); return; } } base.OnReferenceExpression(node); }
private void ReplaceWithComponentReference(Node node, string name) { Expression argument; ConstructorInfo constructorInfo; name = name.Substring(1); IEntity entity = NameResolutionService.ResolveQualifiedName(name); if (entity == null || entity.EntityType != EntityType.Type) { constructorInfo = _componentReferenceConstructor; argument = CodeBuilder.CreateStringLiteral(name); } else { constructorInfo = _componentReferenceTypeConstructor; argument = CodeBuilder.CreateReference(entity); } ExternalConstructor constructor = new ExternalConstructor(TypeSystemServices, constructorInfo); MethodInvocationExpression invocation = CodeBuilder.CreateConstructorInvocation(constructor, argument); node.ParentNode.Replace(node, invocation); }