GacMembershipCondition Class
Determines whether an assembly belongs to a code group by testing its global assembly cache membership. This class cannot be inherited.
Assembly: mscorlib (in mscorlib.dll)
| Name | Description | |
|---|---|---|
![]() | GacMembershipCondition() | Initializes a new instance of the GacMembershipCondition class. |
| Name | Description | |
|---|---|---|
![]() | Check(Evidence^) | Indicates whether the specified evidence satisfies the membership condition. |
![]() | Copy() | Creates an equivalent copy of the membership condition. |
![]() | Equals(Object^) | Indicates whether the current object is equivalent to the specified object.(Overrides Object::Equals(Object^).) |
![]() | FromXml(SecurityElement^) | Uses the specified XML encoding to reconstruct a security object. |
![]() | FromXml(SecurityElement^, PolicyLevel^) | Uses the specified XML encoding to reconstruct a security object, using the specified policy level context. |
![]() | GetHashCode() | Gets a hash code for the current membership condition.(Overrides Object::GetHashCode().) |
![]() | GetType() | |
![]() | ToString() | Returns a string representation of the membership condition.(Overrides Object::ToString().) |
![]() | ToXml() | Creates an XML encoding of the security object and its current state. |
![]() | ToXml(PolicyLevel^) | Creates an XML encoding of the security object and its current state, using the specified policy level context. |
All assemblies installed in the global assembly cache are granted the FullTrust permission set.
The following example demonstrates the use of the GacMembershipCondition class.
using namespace System; using namespace System::Security; using namespace System::Security::Policy; using namespace System::Collections; public ref class GacMembershipConditionDemo { private: // Demonstrate the Copy method, which creates an identical // copy of the current permission. bool CopyDemo() { Console::WriteLine( "************************************************************"); GacMembershipCondition ^ Gac1 = gcnew GacMembershipCondition; Console::WriteLine("Original membership condition = "); Console::WriteLine(Gac1->ToXml()); try { IMembershipCondition^ membershipCondition = Gac1->Copy(); Console::WriteLine("Result of Copy = "); Console::WriteLine( (dynamic_cast<GacMembershipCondition^>(membershipCondition)) ->ToXml()); } catch (Exception^ e) { Console::WriteLine("Copy failed : {0}{1}", Gac1, e); return false; } return true; } // Demonstrate the Check method, which determines whether the specified // evidence satisfies the membership condition. bool CheckDemo() { Console::WriteLine( "************************************************************"); GacMembershipCondition ^ Gac1 = gcnew GacMembershipCondition; GacInstalled ^ myGac = gcnew GacInstalled; try { array<Object^>^hostEvidence = {myGac}; array<Object^>^assemblyEvidence = {}; Evidence^ myEvidence = gcnew Evidence(hostEvidence,assemblyEvidence); bool retCode = Gac1->Check(myEvidence); Console::WriteLine("Result of Check = {0}\n", retCode); } catch (Exception^ e) { Console::WriteLine("Check failed : {0}{1}", Gac1, e); return false; } return true; } // Demonstrate the GetHashCode method, which returns a hash code // for the specified membership condition. bool GetHashCodeDemo() { Console::WriteLine( "************************************************************"); GacMembershipCondition ^ Gac1 = gcnew GacMembershipCondition; try { Console::WriteLine( "Result of GetHashCode for a GacMembershipCondition = {0}\n", Gac1->GetHashCode()); } catch (Exception^ e) { Console::WriteLine("GetHashCode failed : {0}{1}", Gac1, e); return false; } return true; } // Demonstrate the ToXml and FromXml methods, including the overloads. // ToXml creates an XML encoding of the membership condition and its // current state; FromXml reconstructs a membership condition with the // specified state from the XML encoding. bool ToFromXmlDemo() { Console::WriteLine( "************************************************************"); try { GacMembershipCondition ^ Gac1 = gcnew GacMembershipCondition; GacMembershipCondition ^ Gac2 = gcnew GacMembershipCondition; // Roundtrip a GacMembershipCondition to and from an XML encoding. Gac2->FromXml(Gac1->ToXml()); bool result = Gac2->Equals(Gac1); if (result) { Console::WriteLine("Result of ToXml() = {0}", Gac2->ToXml()); Console::WriteLine( "Result of ToFromXml roundtrip = {0}", Gac2); } else { Console::WriteLine(Gac2->ToString()); Console::WriteLine(Gac1->ToString()); return false; } GacMembershipCondition ^ Gac3 = gcnew GacMembershipCondition; GacMembershipCondition ^ Gac4 = gcnew GacMembershipCondition; IEnumerator^ policyEnumerator = SecurityManager::PolicyHierarchy(); while (policyEnumerator->MoveNext()) { PolicyLevel^ currentLevel = dynamic_cast<PolicyLevel^>(policyEnumerator->Current); if (currentLevel->Label->Equals("Machine")) { Console::WriteLine("Result of ToXml(level) = {0}", Gac3->ToXml(currentLevel)); Gac4->FromXml(Gac3->ToXml(), currentLevel); Console::WriteLine( "Result of FromXml(element, level) = {0}", Gac4); } } } catch (Exception^ e) { Console::WriteLine("ToFromXml failed. {0}", e); return false; } return true; } public: // Invoke all demos. bool RunDemo() { bool returnCode = true; bool tempReturnCode; // Call the Copy demo. if (tempReturnCode = CopyDemo()) Console::WriteLine("Copy demo completed successfully."); else Console::WriteLine("Copy demo failed."); returnCode = tempReturnCode && returnCode; // Call the Check demo. if (tempReturnCode = CheckDemo()) Console::WriteLine("Check demo completed successfully."); else Console::WriteLine("Check demo failed."); returnCode = tempReturnCode && returnCode; // Call the GetHashCode demo. if (tempReturnCode = GetHashCodeDemo()) Console::WriteLine("GetHashCode demo completed successfully."); else Console::WriteLine("GetHashCode demo failed."); returnCode = tempReturnCode && returnCode; // Call the ToFromXml demo. if (tempReturnCode = ToFromXmlDemo()) Console::WriteLine("ToFromXml demo completed successfully."); else Console::WriteLine("ToFromXml demo failed."); returnCode = tempReturnCode && returnCode; return (returnCode); } }; // Test harness. int main() { try { GacMembershipConditionDemo^ testcase = gcnew GacMembershipConditionDemo; bool returnCode = testcase->RunDemo(); if (returnCode) { Console::WriteLine( "The GacMembershipCondition demo completed successfully."); Console::WriteLine("Press the Enter key to exit."); Console::ReadLine(); System::Environment::ExitCode = 100; } else { Console::WriteLine("The GacMembershipCondition demo failed."); Console::WriteLine("Press the ENTER key to exit."); Console::ReadLine(); System::Environment::ExitCode = 101; } } catch (Exception^ e) { Console::WriteLine("The GacIdentityPermission demo failed."); Console::WriteLine(e); Console::WriteLine("Press the Enter key to exit."); Console::ReadLine(); System::Environment::ExitCode = 101; } }
Available since 2.0
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
