|Posted by Read Bixby||PermalinkReply|
I'm a bit new with the D programming language, so I figured this would be the right place to ask a few questions that have been piling up.
So let's start. First, I recently found the AutoImplement class while I was trying to build a Proxy object. It seemed like an interesting thing to try, though it may not be a good way to manage asynchronously created resources (which is what I was planning to use it for).
At any rate, since AutoImplement is a class already, and I have this "thing" about not deriving from concrete classes, I decided use AutoImplement_Helper instead. I needed a proxied object, after all, so I needed to be able to manipulate the class definition. It was only after doing so that I noticed it was marked private, and thus presumably not intended for public consumption (and I have no idea why it even compiles).
private shared class Proxy(InterfaceType) if (is (InterfaceType ==
interface)) : public InterfaceType
private alias AutoImplement_Helper!("autoImplement_helper_",
"InterfaceType", InterfaceType, GeneratePassthroughMethod,
public shared static this()
s_proxy = new BlackHole!(InterfaceType);
m_instance = s_proxy;
public void setProxiedInstance(shared(InterfaceType)
m_instance = instance;
private static shared(InterfaceType) s_proxy;
private InterfaceType m_instance;
private template GeneratePassthroughMethod(InterfaceType, method...)
public const(string) GeneratePassthroughMethod =
"__traits(getMember, this.m_instance, __traits(identifier, self))
Is there another way (that I just haven't seen) to do what I'm trying to do? I could just bite the bullet and derive my proxy from AutoImplement, but I thought I'd ask first.
Next, you may have noticed that it's a shared class. I wanted to make sure that the assignment I'm doing in the setProxiedInstance() method will be atomic, and that reading the variable will also be atomic.
My third question is about attributes. As far as I can tell, D has no user defined attributes, correct? I was making myself a unit test framework (with simple reporting, encapsulation of unit tests as methods, and assertion tools). I was hoping to perform automatic registration of the individual unit tests, but the best I could manage was compile-time detection of methods starting with "test", and this feels like a hack. I would prefer to mark the methods explicitly in some way. Does anyone know of a way to do this?
Thanks for your time.