当我尝试从<#+#>括号中声明的非静态方法访问Host对象时,一切正常.但我需要从类方法访问它,如下所示:
<#+
public class ProjectTraverser
{
public void Traverse()
{
var a = Host;
}
}
#>
Run Code Online (Sandbox Code Playgroud)
此模板执行时出现以下错误:"编译转换:无法通过嵌套类型'Microsoft.VisualStudio.TextTemplating7D03DF372FEAC3D3A28C011A41F02403.GeneratedTextTransformation.ProjectTraverser'd:\访问外部类型的非静态成员'Microsoft.VisualStudio.TextTemplating7D03DF372FEAC3D3A28C011A41F02403.GeneratedTextTransformation' Projects\Test Solutions\GettingStarted\TelerikMvc3RazorApplication\TextTemplate2.tt"
请分享任何想法.
我一直在玩积木并遇到一种奇怪的行为.这是接口/实现,它只包含一个能够执行它的块:
@interface TestClass : NSObject {
#if NS_BLOCKS_AVAILABLE
void (^blk)(void);
#endif
}
- (id)initWithBlock:(void (^)(void))block;
- (void)exec;
@end
@implementation TestClass
#if NS_BLOCKS_AVAILABLE
- (id)initWithBlock:(void (^)(void))block {
if ((self = [super init])) {
blk = Block_copy(block);
}
return self;
}
- (void)exec {
if (blk) blk();
}
- (void)dealloc {
Block_release(blk);
[super dealloc];
}
#endif
@end
Run Code Online (Sandbox Code Playgroud)
虽然常规实例化并传递常规块工作:
TestClass *test = [[TestClass alloc] initWithBlock:^{
NSLog(@"TestClass");
}];
[test exec];
[test release];
Run Code Online (Sandbox Code Playgroud)
使用参考正在创建的对象的块不会:
TestClass *test1 = [[TestClass alloc] initWithBlock:^{
NSLog(@"TestClass %@", test1);
}];
[test1 …Run Code Online (Sandbox Code Playgroud)