当前位置: 首页>>代码示例>>C#>>正文


C# SecurityElement.ToString方法代码示例

本文整理汇总了C#中System.Security.SecurityElement.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityElement.ToString方法的具体用法?C# SecurityElement.ToString怎么用?C# SecurityElement.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.SecurityElement的用法示例。


在下文中一共展示了SecurityElement.ToString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessAssemblyXml

		static bool ProcessAssemblyXml (TextWriter tw, AssemblyDefinition ad)
		{
			SecurityElement se = new SecurityElement ("Assembly");
			se.AddAttribute ("Name", ad.Name.FullName);

			if (ad.SecurityDeclarations.Count > 0) {
				se.AddChild (AddSecurityXml (ad.SecurityDeclarations));
			}

			ArrayList tlist = new ArrayList ();
			ArrayList mlist = new ArrayList ();

			foreach (ModuleDefinition module in ad.Modules) {

				foreach (TypeDefinition type in module.Types) {

					SecurityElement klass = new SecurityElement ("Class");
					SecurityElement methods = new SecurityElement ("Methods");

					SecurityElement typelem = null;
					if (type.SecurityDeclarations.Count > 0) {
						typelem = AddSecurityXml (type.SecurityDeclarations);
					}

					if (mlist.Count > 0)
						mlist.Clear ();

					foreach (MethodDefinition method in type.Methods) {
						if (method.SecurityDeclarations.Count > 0) {
							SecurityElement meth = new SecurityElement ("Method");
							AddAttribute (meth, "Name", method.ToString ());
							meth.AddChild (AddSecurityXml (method.SecurityDeclarations));
							mlist.Add (meth);
						}
					}

					// sort methods
					mlist.Sort (Comparer);
					foreach (SecurityElement method in mlist) {
						methods.AddChild (method);
					}

					if ((typelem != null) || ((methods.Children != null) && (methods.Children.Count > 0))) {
						AddAttribute (klass, "Name", type.ToString ());
						if (typelem != null)
							klass.AddChild (typelem);
						if ((methods.Children != null) && (methods.Children.Count > 0))
							klass.AddChild (methods);
						tlist.Add (klass);
					}
				}

				// sort types
				tlist.Sort (Comparer);
				foreach (SecurityElement type in tlist) {
					se.AddChild (type);
				}
			}

			tw.WriteLine (se.ToString ());
			return true;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:62,代码来源:permview.cs

示例2: EncodeLevel

        internal static void EncodeLevel( PolicyLevel level )
        {
            SecurityElement elConf = new SecurityElement( "configuration" );
            SecurityElement elMscorlib = new SecurityElement( "mscorlib" );
            SecurityElement elSecurity = new SecurityElement( "security" );
            SecurityElement elPolicy = new SecurityElement( "policy" );
                    
            elConf.AddChild( elMscorlib );
            elMscorlib.AddChild( elSecurity );
            elSecurity.AddChild( elPolicy );
            elPolicy.AddChild( level.ToXml() );
                    
            try
            {
                MemoryStream stream = new MemoryStream( 24576 ); 
            
                StreamWriter writer = new StreamWriter( stream, new UTF8Encoding(false) );
                
                Encoding encoding = level.Encoding;

                if (encoding == null)
                    encoding = writer.Encoding;
                
                SecurityElement format = new SecurityElement( "xml" );
                format.m_type = SecurityElementType.Format;
                format.AddAttribute( "version", "1.0" );
                format.AddAttribute( "encoding", encoding.WebName );
                writer.Write( format.ToString() );
                writer.Flush();
                writer = new StreamWriter( stream, encoding );
            
                writer.Write( elConf.ToString() );
                        
                writer.Flush();

                // Write out the new config.

                if (!Config.SaveData( level.ConfigId, stream.GetBuffer(), 0, (int)stream.Length ))
                {
                    throw new PolicyException( String.Format( Environment.GetResourceString( "Policy_UnableToSave" ), level.Label ) );
                }
            }
            catch (Exception e)
            {
                if (e is PolicyException)
                    throw e;
                else
                    throw new PolicyException( String.Format( Environment.GetResourceString( "Policy_UnableToSave" ), level.Label ), e );
            }

            Config.ResetCacheData( level.ConfigId );

            try
            {
                if (CanUseQuickCache( level.RootCodeGroup ))
                {
                    Config.SetQuickCache( level.ConfigId, GenerateQuickCache( level ) );
                }
            }
            catch (Exception)
            {
            }

        }
开发者ID:ArildF,项目名称:masters,代码行数:64,代码来源:policymanager.cs

示例3: TestToString

		[Test] // bug #333699 (ugh, mostly a dup)
		public void TestToString ()
		{
			SecurityElement values = new SecurityElement ("values");
			SecurityElement infoValue = new SecurityElement ("value");
			infoValue.AddAttribute ("name", "string");
			infoValue.Text = SecurityElement.Escape ("<'Suds' & \"Soda\">!");
			values.AddChild (infoValue);
			Assert.AreEqual ("<value name=\"string\">&lt;&apos;Suds&apos; &amp; &quot;Soda&quot;&gt;!</value>" + Environment.NewLine, infoValue.ToString (), "#1");
			Assert.AreEqual ("<'Suds' & \"Soda\">!", infoValue.Text, "#2");
			Assert.IsNull (values.Text, "#3");

#if NET_2_0
			Assert.AreEqual (String.Format ("<values>{0}<value name=\"string\">&lt;&apos;Suds&apos; &amp; &quot;Soda&quot;&gt;!</value>{0}</values>{0}", Environment.NewLine), values.ToString (), "#4");
#else
			Assert.AreEqual (String.Format ("<values>{0}   <value name=\"string\">&lt;&apos;Suds&apos; &amp; &quot;Soda&quot;&gt;!</value>{0}</values>{0}", Environment.NewLine), values.ToString (), "#4");
#endif

#if NET_2_0
			SecurityElement sec = SecurityElement.FromString (values.ToString ());
			Assert.AreEqual (1, sec.Children.Count, "#5");
			Assert.AreEqual ("<'Suds' & \"Soda\">!", ((SecurityElement) sec.Children [0]).Text, "#6");
#endif
		}
开发者ID:nlhepler,项目名称:mono,代码行数:24,代码来源:SecurityElementTest.cs

示例4: EncodeLevel

        internal static void EncodeLevel (PolicyLevel level)
        {
            Contract.Assert(level != null, "No policy level to encode.");

            // We cannot encode a policy level without a backing file  
            if (level.Path == null)
            {
                string errorMessage = Environment.GetResourceString("Policy_UnableToSave",
                                                    level.Label,
                                                    Environment.GetResourceString("Policy_SaveNotFileBased"));
                throw new PolicyException(errorMessage);
            }
                
            SecurityElement elConf = new SecurityElement("configuration");
            SecurityElement elMscorlib = new SecurityElement("mscorlib");
            SecurityElement elSecurity = new SecurityElement("security");
            SecurityElement elPolicy = new SecurityElement("policy");

            elConf.AddChild(elMscorlib);
            elMscorlib.AddChild(elSecurity);
            elSecurity.AddChild(elPolicy);
            elPolicy.AddChild(level.ToXml());

            try
            {
                StringBuilder sb = new StringBuilder();
                Encoding encoding = Encoding.UTF8;

                SecurityElement format = new SecurityElement("xml");
                format.m_type = SecurityElementType.Format;
                format.AddAttribute("version", "1.0");
                format.AddAttribute("encoding", encoding.WebName);
                sb.Append(format.ToString());
                sb.Append(elConf.ToString());

                byte[] data = encoding.GetBytes(sb.ToString());

                // Write out the new config.
                int hrSave = Config.SaveDataByte(level.Path, data, data.Length);
                Exception extendedError = Marshal.GetExceptionForHR(hrSave);
                if (extendedError != null)
                {
                    string extendedInformation = extendedError != null ? extendedError.Message : String.Empty;
                    throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", level.Label, extendedInformation), extendedError);
                }
            }
            catch (Exception e)
            {
                if (e is PolicyException)
                    throw e;
                else
                    throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", level.Label, e.Message), e);
            }

            Config.ResetCacheData(level.ConfigId);
            if (CanUseQuickCache(level.RootCodeGroup))
                Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level));
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:58,代码来源:policymanager.cs

示例5: Tag

		public void Tag ()
		{
			SecurityElement se = new SecurityElement ("Values");
			Assert.AreEqual ("Values", se.Tag, "#A1");
			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"<Values/>{0}", Environment.NewLine), 
				se.ToString (), "#A2");
			se.Tag = "abc:Name";
			Assert.AreEqual ("abc:Name", se.Tag, "#B1");
			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"<abc:Name/>{0}", Environment.NewLine),
				se.ToString (), "#B2");
			se.Tag = "Name&Address";
			Assert.AreEqual ("Name&Address", se.Tag, "#C1");
			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"<Name&Address/>{0}", Environment.NewLine),
				se.ToString (), "#C2");
			se.Tag = string.Empty;
			Assert.AreEqual (string.Empty, se.Tag, "#D1");
			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"</>{0}", Environment.NewLine),
				se.ToString (), "#D2");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:23,代码来源:SecurityElementTest.cs

示例6: MultipleAttributes

		public void MultipleAttributes () 
		{
			SecurityElement se = new SecurityElement ("Multiple");
			se.AddAttribute ("Attribute1", "One");
			se.AddAttribute ("Attribute2", "Two");
#if NET_2_0
			string expected = String.Format ("<Multiple Attribute1=\"One\"{0}Attribute2=\"Two\"/>{0}", Environment.NewLine);
#else
			string expected = String.Format ("<Multiple Attribute1=\"One\"{0}          Attribute2=\"Two\"/>{0}", Environment.NewLine);
#endif
			Assert.AreEqual (expected, se.ToString (), "ToString()");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:12,代码来源:SecurityElementTest.cs

示例7: CreatePermissionFromElement

        CreatePermissionFromElement( SecurityElement el, bool safeLoad, bool policyLoad, out bool assemblyIsLoading )
        {
    #if _DEBUG
            if (debug)
                DEBUG_WRITE( "ip element = " + el.ToString() );
    #endif            
        
            IPermission ip = XMLUtil.CreatePermission( el, safeLoad, policyLoad, out assemblyIsLoading );

    #if _DEBUG
            if (debug)
                DEBUG_WRITE( "ip after create = " + (ip == null ? "<null>" : ip.ToString()) );
    #endif

            if (ip == null)
                return null ;
            
            ip.FromXml( el );

    #if _DEBUG
            if (debug)
                DEBUG_WRITE( "ip after decode = " + (ip == null ? "<null>" : ip.ToString()) );
    #endif
            
            return ip;            
        }
开发者ID:ArildF,项目名称:masters,代码行数:26,代码来源:permissionset.cs

示例8: BuildPathFile

 private void BuildPathFile()
 {
     LoggerHelper.Debug("BuildPathFile");
     var root = new System.Security.SecurityElement("root");
     foreach (var item in m_instance.m_filesDic)
     {
         root.AddChild(new System.Security.SecurityElement("k", item.Key));
         root.AddChild(new System.Security.SecurityElement("v", item.Value));
     }
     XMLParser.SaveText(m_instance.m_resourcePath + "resourceInfo.xml", root.ToString());
 }
开发者ID:lbddk,项目名称:ahzs-client,代码行数:11,代码来源:LoadResources.cs

示例9: LoadMap

        /// <summary>
        /// 从指定的 XML 文档加载 map 数据。
        /// </summary>
        /// <param name="xml">XML 文档</param>
        /// <returns>map 数据</returns>
        public static Dictionary<String, Dictionary<String, String>> LoadMap(SecurityElement xml)
        {
            var result = new Dictionary<String, Dictionary<String, String>>();

            foreach (SecurityElement subMap in xml.Children)
            {
                String key = (subMap.Children[0] as SecurityElement).Text.Trim();
                if (result.ContainsKey(key))
                {
                    LoggerHelper.Warning(String.Format("Key {0} already exist, in {1}.", key, xml.ToString()));
                    continue;
                }

                var children = new Dictionary<string, string>();
                result.Add(key, children);
                for (int i = 1; i < subMap.Children.Count; i++)
                {
                    var node = subMap.Children[i] as SecurityElement;
                    if (node != null && !children.ContainsKey(node.Tag))
                    {
                        if (String.IsNullOrEmpty(node.Text))
                            children.Add(node.Tag, "");
                        else
                            children.Add(node.Tag, node.Text.Trim());
                    }
                    else
                        LoggerHelper.Warning(String.Format("Key {0} already exist, index {1} of {2}.", node.Tag, i, node.ToString()));
                }
            }
            return result;
        }
开发者ID:lbddk,项目名称:ahzs-client,代码行数:36,代码来源:XMLParser.cs

示例10: EncodeLevel

        internal static void EncodeLevel (PolicyLevel level) {
            SecurityElement elConf = new SecurityElement("configuration");
            SecurityElement elMscorlib = new SecurityElement("mscorlib");
            SecurityElement elSecurity = new SecurityElement("security");
            SecurityElement elPolicy = new SecurityElement("policy");

            elConf.AddChild(elMscorlib);
            elMscorlib.AddChild(elSecurity);
            elSecurity.AddChild(elPolicy);
            elPolicy.AddChild(level.ToXml());

            try
            {
                StringBuilder sb = new StringBuilder();
                Encoding encoding = Encoding.UTF8;

                SecurityElement format = new SecurityElement("xml");
                format.m_type = SecurityElementType.Format;
                format.AddAttribute("version", "1.0");
                format.AddAttribute("encoding", encoding.WebName);
                sb.Append(format.ToString());
                sb.Append(elConf.ToString());

                byte[] data = encoding.GetBytes(sb.ToString());

                // Write out the new config.
                if (level.Path == null || !Config.SaveDataByte(level.Path, data, 0, data.Length))
                    throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label));
            }
            catch (Exception e)
            {
                if (e is PolicyException)
                    throw e;
                else
                    throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label), e);
            }
            catch
            {
                throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label));
            }

            Config.ResetCacheData(level.ConfigId);
            if (CanUseQuickCache(level.RootCodeGroup))
                Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level));
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:45,代码来源:policymanager.cs

示例11: EncodeLevel

 internal static void EncodeLevel(PolicyLevel level)
 {
     if (level.Path == null)
     {
         throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, Environment.GetResourceString("Policy_SaveNotFileBased") }));
     }
     SecurityElement element = new SecurityElement("configuration");
     SecurityElement child = new SecurityElement("mscorlib");
     SecurityElement element3 = new SecurityElement("security");
     SecurityElement element4 = new SecurityElement("policy");
     element.AddChild(child);
     child.AddChild(element3);
     element3.AddChild(element4);
     element4.AddChild(level.ToXml());
     try
     {
         StringBuilder builder = new StringBuilder();
         Encoding encoding = Encoding.UTF8;
         SecurityElement element5 = new SecurityElement("xml") {
             m_type = SecurityElementType.Format
         };
         element5.AddAttribute("version", "1.0");
         element5.AddAttribute("encoding", encoding.WebName);
         builder.Append(element5.ToString());
         builder.Append(element.ToString());
         byte[] bytes = encoding.GetBytes(builder.ToString());
         Exception exceptionForHR = Marshal.GetExceptionForHR(Config.SaveDataByte(level.Path, bytes, bytes.Length));
         if (exceptionForHR != null)
         {
             string str2 = (exceptionForHR != null) ? exceptionForHR.Message : string.Empty;
             throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, str2 }), exceptionForHR);
         }
     }
     catch (Exception exception2)
     {
         if (exception2 is PolicyException)
         {
             throw exception2;
         }
         throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, exception2.Message }), exception2);
     }
     Config.ResetCacheData(level.ConfigId);
     if (CanUseQuickCache(level.RootCodeGroup))
     {
         Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:47,代码来源:PolicyManager.cs

示例12: SaveFingerPrint

		private static void SaveFingerPrint(String destFileName, FingerPrint fingerPrint)
		{
			String fingerPrintFileName = FileDownloader.MakeFingerPrintFilePath(destFileName);

			SecurityElement finger_print = new SecurityElement("finger_print");

			finger_print.AddAttribute("time_stamp", fingerPrint.timeStamp);
			finger_print.AddAttribute("file_size", fingerPrint.fileSize.ToString());

			File.WriteAllText(fingerPrintFileName, finger_print.ToString());
		}
开发者ID:fengqk,项目名称:Art,代码行数:11,代码来源:FileDownloader.cs

示例13: SaveVersion

 private void SaveVersion(VersionManagerInfo version)
 {
     var props = typeof(VersionManagerInfo).GetProperties();
     var root = new System.Security.SecurityElement("root");
     foreach (var item in props)
     {
         root.AddChild(new System.Security.SecurityElement(item.Name, item.GetGetMethod().Invoke(version, null) as String));
     }
     XMLParser.SaveText(SystemConfig.VersionPath, root.ToString());
 }
开发者ID:lbddk,项目名称:ahzs-client,代码行数:10,代码来源:VersionManager.cs


注:本文中的System.Security.SecurityElement.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。