/////////////////////////////////////////////////////////////////////// // AttribProgram.cpp - demonstrate use of custom attribute // // // // Jim Fawcett, CSE681 - Software Modeling and Analysis, Fall 2004 // /////////////////////////////////////////////////////////////////////// // Build Process: // // Required Files: // AttribProgram.cpp, AttribLib.dll, AttribDef.dll // // To Build: // - For compilation AttribDef.dll and AttribLib.dll need to be // in the AttribProgram project folder. // - For running AttribDef.dll and AttribLib.dll need to be in // the AttribProgram Project debug folder. // - compile and run. /////////////////////////////////////////////////////////////////////// //#using using namespace System; #using "AttribDef.dll" // defines DeveloperAttribute using namespace AttribDef; #using "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); for(int i=0; iLength; ++i) { if(pObjs[i]->GetType()->Equals(DeveloperAttribute::typeid)) { String^ dev = static_cast(pObjs[i])->Developer; return dev; } } return "Developer not found"; } //----< test stub >---------------------------------------------- int main() { std::cout << "\n Demonstrate User-defined Attributes"; std::cout << "\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); }