///////////////////////////////////////////////////////////////// // AttribProgram.cpp - demonstrate use of custom attribute // // // // Jim Fawcett, CSE775 - Distributed Objects, Spring 2003 // ///////////////////////////////////////////////////////////////// // Build Process: // // Required Files: // AttribProgram.cpp, AttribLib.dll, AttribDef.dll // // To Build: // - compile and run. // - For running AttribDef.dll and AttribLib.dll need to be // copied into the AttribProgram Project debug folder. ///////////////////////////////////////////////////////////////// //#using using namespace System; #using "../AttribDef/Debug/AttribDef.dll" // defines DeveloperAttribute using namespace AttribDef; #using "../AttribLib/Debug/AttribLib.dll" // uses DeveloperAttribute using namespace AttribLib; #include using namespace std; //----< extract developer name from metadata >------------------- String^ getDeveloper() { Type^ pType = Test::typeid; array^ pObjs = Attribute::GetCustomAttributes(pType); Console::Write("\n Test has {0} attribute(s)",pObjs->Length); for(int i=0; iLength; ++i) { if(pObjs[i]->GetType()->Equals(DeveloperAttribute::typeid)) { Console::Write("\n found developer"); String^ dev = static_cast(pObjs[i])->Developer; return dev; } } return "not found"; } //----< test stub >---------------------------------------------- int main() { Console::Write("\n Testing Custom Attribute Definition and Use"); Console::Write("\n =============================================\n"); // use attributed library Test^ pTest = gcnew Test(); Console::WriteLine("\n Library result: {0}",pTest->say()); // display DeveloperAttribute String^ dev = getDeveloper(); Console::WriteLine("\n developer is: {0}\n\n",dev); }