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


C# CSharpCodeProvider.CreateValidIdentifier方法代码示例

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


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

示例1: CacheBinaryReaderMethods

        static void CacheBinaryReaderMethods()
        {
            var types = ExecutingAssembly.GetTypes();
            // get BinaryReader extension methods from the executing assembly 
            var extensionMethods = (from type in types
                                    where type.IsSealed && !type.IsGenericType && !type.IsNested
                                    from method in type.GetMethods(BindingFlags.Static
                                        | BindingFlags.Public | BindingFlags.NonPublic)
                                    where method.IsDefined(typeof(ExtensionAttribute), false)
                                    where method.GetParameters()[0].ParameterType == typeof(BinaryReader)
                                    select new { method = method, type = method.ReturnType }).ToList();

            // trim this down further to one of each return type
            extensionMethods = (from method in extensionMethods
                                group method by method.type into g
                                select g.First()).ToList();

            using (var provider = new CSharpCodeProvider())
            {
                var test = provider.CreateValidIdentifier(typeof(int).ToString());
                var binaryReaderMethods = (from method in typeof(BinaryReader).GetMethods()
                                           where method.ReturnType != typeof(void)
                                           select new { method = method, type = method.ReturnType }).ToList().Where(x =>
                                                {
                                                    var typeString = provider.CreateValidIdentifier((x.type).ToString());
                                                    typeString = typeString.Split('.').Last();
                                                    return x.method.Name.ToLower().Contains(typeString.ToLower());
                                                }).ToList();


                binaryReaderMethods = (from method in binaryReaderMethods
                                       group method by method.type into g
                                       select g.First()).ToList();

                var totalMethods = binaryReaderMethods.Union(extensionMethods);
                ReadTypeMethods = new Dictionary<Type, MethodInvoker>(totalMethods.Count());
                foreach (var item in totalMethods)
                {
                    ReadTypeMethods[item.type] = item.method.DelegateForCallMethod();
                }
            }
        }
开发者ID:jacksoncougar,项目名称:Moonfish-Editor,代码行数:42,代码来源:Deserializer.cs

示例2: ValidateFieldName

 protected virtual string ValidateFieldName(string fieldName)
 {
     using (var provider = new CSharpCodeProvider())
     {
         if (!provider.IsValidIdentifier(fieldName))
         {
             var huh = provider.CreateValidIdentifier(fieldName);
             fieldName = string.Format("invalidName_{0}", fieldName);
         }
     }
     return fieldName;
 }
开发者ID:jacksoncougar,项目名称:Moonfish-Editor,代码行数:12,代码来源:GuerillaBase.cs

示例3: ProcessSwaggerDocuments


//.........这里部分代码省略.........
                                            WriteLine("}");
                                        }
                                    }
                                    foreach (var formParam in formData.Where(x => x.Type.TypeName == "file"))
                                    {
                                        WriteLine(
                                            string.Format(
                                                "var {0}Content = new ByteArrayContent({0}.Item2);",
                                                formParam.Type.Name));
                                        WriteLine(
                                            string.Format(
                                                "{0}Content.Headers.ContentDisposition = new ContentDispositionHeaderValue(\"attachment\") {{ FileName = {0}.Item1 }};",
                                                formParam.Type.Name));
                                    }
                                    WriteLine("HttpContent content = new FormUrlEncodedContent(formKeyValuePairs);");
                                    WriteLine("var response = await client.PostAsync(url, content).ConfigureAwait(false);");
                                }
                                else
                                {
                                    WriteLine(
                                        "var response = await client.PostAsync(url, new StringContent(string.Empty)).ConfigureAwait(false);");
                                }

                                break;
                        }
                        WriteLine("await EnsureSuccessStatusCodeAsync(response);");

                        if (string.IsNullOrWhiteSpace(operationDef.ReturnType) == false)
                        {
                            WriteLine(
                                string.Format(
                                    "return await response.Content.ReadAsAsync<{0}>().ConfigureAwait(false);",
                                    operationDef.ReturnType));
                        }

                        WriteLine("}"); // close up the using
                        WriteLine("}"); // close up the method
                        WriteLine();
                    }

                    foreach (var proxyParamEnum in proxyParamEnums)
                    {
                        WriteLine(string.Format("public enum {0}", SwaggerParser.FixTypeName(proxyParamEnum.Name)));
                        WriteLine("{");
                        foreach (var value in proxyParamEnum.Values.Distinct())
                        {
                            WriteLine(string.Format("{0},", SwaggerParser.FixTypeName(value)));
                        }
                        WriteLine("}");
                        WriteLine();
                    }

                    // close class def
                    WriteLine("}");
                    WriteLine();
                }

                // Model Classes
                foreach (var classDef in proxyDefinition.ClassDefinitions)
                {
                    List<Enum> modelEnums = new List<Enum>();

                    WriteLine(
                        string.Format(
                            "public class {0}{1}",
                            classDef.Name,
                            string.IsNullOrEmpty(classDef.Inherits) ? string.Empty : string.Format(" : {0}", classDef.Inherits)));
                    WriteLine("{");
                    foreach (var prop in classDef.Properties)
                    {
                        var typeName = string.IsNullOrWhiteSpace(prop.TypeName) ? "object" : prop.TypeName;
                        WriteLine(string.Format("public {0} {1} {{ get; set; }}", typeName, prop.Name));
                        if (prop.EnumValues != null)
                        {
                            modelEnums.Add(new Enum() { Name = typeName, Values = prop.EnumValues });
                        }
                    }

                    foreach (var modelEnum in modelEnums)
                    {
                        var csharpCodeProvider = new CSharpCodeProvider();
                        WriteLine(string.Format("public enum {0}", csharpCodeProvider.CreateValidIdentifier(modelEnum.Name)));
                        WriteLine("{");
                        foreach (var value in modelEnum.Values.Distinct())
                        {
                            WriteLine(string.Format("{0},", SwaggerParser.FixTypeName(value)));
                        }
                        WriteLine("}");
                        WriteLine();
                    }

                    WriteLine("}");
                    WriteLine();
                }

                // close namespace def
                WriteLine("}");
                File.WriteAllText(proxyOutputFile, FileText.ToString());
            }
        }
开发者ID:yonglehou,项目名称:Birch.Swagger.ProxyGenerator,代码行数:101,代码来源:ProxyGenerator.cs


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