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


C# ResourceSet.GetEnumerator方法代码示例

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


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

示例1: CreateClassFromResourceSet

        public string CreateClassFromResourceSet(ResourceSet resourceSet, string nameSpace, string classname, string fileName)
        {
            IsVb = IsFileVb(fileName);

            StringBuilder sbClass = new StringBuilder();

            CreateClassHeader(classname, nameSpace, IsVb, sbClass);

            string indent = "\t\t";

            // Any resource set that contains a '.' is considered a Local Resource
            bool IsGlobalResource = !classname.Contains(".");

            // We'll enumerate through the Recordset to get all the resources
            IDictionaryEnumerator Enumerator = resourceSet.GetEnumerator();

            // We have to turn into a concrete Dictionary            
            while (Enumerator.MoveNext())
            {
                DictionaryEntry item = (DictionaryEntry)Enumerator.Current;
                if (item.Value == null)
                    item.Value = string.Empty;

                string typeName = item.Value.GetType().FullName;
                string key = item.Key as string;
                if (string.IsNullOrEmpty(key))
                    continue;

                string varName = SafeVarName(key);

                // It's a string
                if (!IsVb)
                {
                    sbClass.Append(indent + "public static " + typeName + " " + varName + "\r\n" + indent + "{\r\n");
                    sbClass.AppendFormat(indent + "\tget\r\n" +
                                         indent + "\t{{\r\n" +
                                         indent +
                                         (string.IsNullOrEmpty(typeName) || typeName == "System.String"
                                         ? "\t\t" + @"return GeneratedResourceHelper.GetResourceString(""{0}"",""{1}"",ResourceManager,GeneratedResourceSettings.ResourceAccessMode);" + "\r\n"
                                         : "\t\t" + @"return ({2}) GeneratedResourceHelper.GetResourceObject(""{0}"",""{1}"",ResourceManager,GeneratedResourceSettings.ResourceAccessMode);" + "\r\n")
                                         +
                                         indent + "\t}}\r\n",
                                         classname, key, typeName);
                    sbClass.Append(indent + "}\r\n\r\n");
                }
                else
                {
                    sbClass.Append(indent + "Public Shared Property " + varName + "() as " + typeName + "\r\n");
                    sbClass.AppendFormat(indent + "\tGet\r\n" + indent + "\t\treturn CType( HttpContext.GetGlobalResourceObject(\"{0}\",\"{1}\"), {2})\r\n",
                                         classname, key, typeName);
                    sbClass.Append(indent + "\tEnd Get\r\n");
                    sbClass.Append(indent + "End Property\r\n\r\n");
                }
            }

            if (!IsVb)
                sbClass.Append("\t}\r\n\r\n");
            else
                sbClass.Append("End Class\r\n\r\n");

            string Output = CreateNameSpaceWrapper(nameSpace, IsVb, sbClass.ToString());

            if (!string.IsNullOrEmpty(fileName))
            {
                File.WriteAllText(fileName, Output);
                return Output;
            }

            return sbClass.ToString();
        }
开发者ID:revocengiz,项目名称:Westwind.Globalization,代码行数:70,代码来源:StronglyTypedResources.cs

示例2: AddResourceNameToList

        // 
        // Add all the availabe resource names in ResourceSet to ArrayList
        //
        private void AddResourceNameToList(ResourceSet rs, ref ArrayList resourceList)
        {
            IDictionaryEnumerator deResources;

            deResources = rs.GetEnumerator();

            if (deResources != null)
            {
                while (deResources.MoveNext())
                {
                    string resName = deResources.Key as string;

                    resourceList.Add(resName);
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:19,代码来源:ResourceManagerWrapper.cs

示例3: CreateClassFromResourceSet

        /// <summary>
        /// Creates a strongly typed resource from a ResourceSet object. The ResourceSet passed should always
        /// be the invariant resourceset that contains all the ResourceIds.
        /// 
        /// Creates strongly typed keys for each of the keys/values.
        /// </summary>
        /// <param name="ResourceSet"></param>
        /// <param name="Namespace">Namespace of the generated class. Pass Null or string.Empty to not generate a namespace</param>
        /// <param name="Classname">Name of the class to generate. Pass null to use the ResourceSet name</param>
        /// <param name="FileName">Output filename for the CSharp class. If null no file is generated and only the class is returned</param>
        /// <returns></returns>
        public string CreateClassFromResourceSet(ResourceSet ResourceSet, string Namespace, string Classname, string FileName)
        {
            this.IsVb = this.IsFileVb(FileName);

            StringBuilder sbClass = new StringBuilder();

            this.CreateClassHeader(Classname, IsVb, sbClass);

            string Indent = "\t\t";

            // Any resource set that contains a '.' is considered a Local Resource
            bool IsGlobalResource = !Classname.Contains(".");

            // We'll enumerate through teh Recordset to get all the resources
            IDictionaryEnumerator Enumerator = ResourceSet.GetEnumerator();

            // We have to turn into a concrete Dictionary            
            while (Enumerator.MoveNext())
            {
                DictionaryEntry Item = (DictionaryEntry)Enumerator.Current;

                string TypeName = Item.Value.GetType().FullName;
                string Key = Item.Key as string;
                Key = Key.Replace(".", "_");
                if (string.IsNullOrEmpty(Key))
                    continue;

                // It's a string
                if (!IsVb)
                {
                    sbClass.Append(Indent + "public static " + TypeName + " " + Key + "\r\n" + Indent + "{\r\n");
                    sbClass.AppendFormat(Indent + "\tget {{ return ({2}) HttpContext.GetGlobalResourceObject(\"{0}\",\"{1}\"); }}\r\n",
                                         Classname, Key,TypeName);
                    sbClass.Append(Indent + "}\r\n\r\n");                    
                }
                else
                {
                    sbClass.Append(Indent + "Public Shared Property " + Key + "() as " + TypeName + "\r\n");
                    sbClass.AppendFormat(Indent + "\tGet\r\n" + Indent + "\t\treturn CType( HttpContext.GetGlobalResourceObject(\"{0}\",\"{1}\"), {2})\r\n",
                                         Classname, Key,TypeName);
                    sbClass.Append(Indent + "\tEnd Get\r\n");
                    sbClass.Append(Indent + "End Property\r\n\r\n");
                }
            }

            if (!this.IsVb)
                sbClass.Append("\t}\r\n\r\n");
            else
                sbClass.Append("End Class\r\n\r\n");

            string Output = this.CreateNameSpaceWrapper(Namespace,this.IsVb,sbClass.ToString() );

            if (!string.IsNullOrEmpty(FileName))
            {
                File.WriteAllText(FileName, Output);
                return Output;
            }
                
            return sbClass.ToString();
        }
开发者ID:hernangm,项目名称:Westwind.Globalization,代码行数:71,代码来源:StronglyTypedWebResources.cs

示例4: LoadFromResource

        /// <summary>
        /// Loads all strings found in the resource
        /// </summary>
        /// <param name="path">The path of the resource from where to load the data.</param>
        public bool LoadFromResource(string path)
        {
            if(path == null) {
                throw new ArgumentNullException("path");
            }

            try {
                ResourceSet set = new ResourceSet(path);

                if(set == null) {
                    return false;
                }

                // extract the string resources
                IDictionaryEnumerator id = set.GetEnumerator();

                while(id.MoveNext()) {
                    if(id.Key is string && id.Value is string) {
                        AddString((string)id.Key, (string)id.Value);
                    }
                }
            }
            catch(Exception e) {
                Console.WriteLine(e.Message);
                return false;
            }

            return true;
        }
开发者ID:gratianlup,项目名称:DebugUtils,代码行数:33,代码来源:StringTable.cs


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