System.Security.Policy.ApplicationSecurityManager.DecodeAppTrustManagerFromElement C# (CSharp) Method

DecodeAppTrustManagerFromElement() private static method

private static DecodeAppTrustManagerFromElement ( SecurityElement elTrustManager ) : IApplicationTrustManager
elTrustManager SecurityElement
return IApplicationTrustManager
        private static IApplicationTrustManager DecodeAppTrustManagerFromElement (SecurityElement elTrustManager) {
            new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Assert();
            string trustManagerName = elTrustManager.Attribute("class");
            Type tmClass = Type.GetType(trustManagerName, false, false);
            if (tmClass == null)
                return null;

            IApplicationTrustManager appTrustManager = Activator.CreateInstance(tmClass) as IApplicationTrustManager;
            if (appTrustManager != null)
                appTrustManager.FromXml(elTrustManager);
            return appTrustManager;
        }
    }

Usage Example

Example #1
0
 private static IApplicationTrustManager DecodeAppTrustManager()
 {
     if (File.InternalExists(ApplicationSecurityManager.s_machineConfigFile))
     {
         string end;
         using (FileStream fileStream = new FileStream(ApplicationSecurityManager.s_machineConfigFile, FileMode.Open, FileAccess.Read))
             end = new StreamReader((Stream)fileStream).ReadToEnd();
         SecurityElement securityElement1 = SecurityElement.FromString(end).SearchForChildByTag("mscorlib");
         if (securityElement1 != null)
         {
             SecurityElement securityElement2 = securityElement1.SearchForChildByTag("security");
             if (securityElement2 != null)
             {
                 SecurityElement securityElement3 = securityElement2.SearchForChildByTag("policy");
                 if (securityElement3 != null)
                 {
                     SecurityElement securityElement4 = securityElement3.SearchForChildByTag("ApplicationSecurityManager");
                     if (securityElement4 != null)
                     {
                         SecurityElement elTrustManager = securityElement4.SearchForChildByTag("IApplicationTrustManager");
                         if (elTrustManager != null)
                         {
                             IApplicationTrustManager applicationTrustManager = ApplicationSecurityManager.DecodeAppTrustManagerFromElement(elTrustManager);
                             if (applicationTrustManager != null)
                             {
                                 return(applicationTrustManager);
                             }
                         }
                     }
                 }
             }
         }
     }
     return(ApplicationSecurityManager.DecodeAppTrustManagerFromElement(ApplicationSecurityManager.CreateDefaultApplicationTrustManagerElement()));
 }