本文整理汇总了C#中MetadataTypes.RemoveIgnoredTypesForNet方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataTypes.RemoveIgnoredTypesForNet方法的具体用法?C# MetadataTypes.RemoveIgnoredTypesForNet怎么用?C# MetadataTypes.RemoveIgnoredTypesForNet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetadataTypes
的用法示例。
在下文中一共展示了MetadataTypes.RemoveIgnoredTypesForNet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCode
public string GetCode(MetadataTypes metadata, IRequest request)
{
var namespaces = Config.GetDefaultNamespaces(metadata);
metadata.RemoveIgnoredTypesForNet(Config);
if (Config.GlobalNamespace == null)
{
metadata.Types.Each(x => namespaces.Add(x.Namespace));
metadata.Operations.Each(x => namespaces.Add(x.Request.Namespace));
}
else
{
namespaces.Add(Config.GlobalNamespace);
}
Func<string,string> defaultValue = k =>
request.QueryString[k].IsNullOrEmpty() ? "//" : "";
var sbInner = StringBuilderCache.Allocate();
var sb = new StringBuilderWrapper(sbInner);
sb.AppendLine("/* Options:");
sb.AppendLine("Date: {0}".Fmt(DateTime.Now.ToString("s").Replace("T"," ")));
sb.AppendLine("Version: {0}".Fmt(Env.ServiceStackVersion));
sb.AppendLine("Tip: {0}".Fmt(HelpMessages.NativeTypesDtoOptionsTip.Fmt("//")));
sb.AppendLine("BaseUrl: {0}".Fmt(Config.BaseUrl));
sb.AppendLine();
sb.AppendLine("{0}GlobalNamespace: {1}".Fmt(defaultValue("GlobalNamespace"), Config.GlobalNamespace));
sb.AppendLine("{0}MakePartial: {1}".Fmt(defaultValue("MakePartial"), Config.MakePartial));
sb.AppendLine("{0}MakeVirtual: {1}".Fmt(defaultValue("MakeVirtual"), Config.MakeVirtual));
sb.AppendLine("{0}MakeDataContractsExtensible: {1}".Fmt(defaultValue("MakeDataContractsExtensible"), Config.MakeDataContractsExtensible));
sb.AppendLine("{0}AddReturnMarker: {1}".Fmt(defaultValue("AddReturnMarker"), Config.AddReturnMarker));
sb.AppendLine("{0}AddDescriptionAsComments: {1}".Fmt(defaultValue("AddDescriptionAsComments"), Config.AddDescriptionAsComments));
sb.AppendLine("{0}AddDataContractAttributes: {1}".Fmt(defaultValue("AddDataContractAttributes"), Config.AddDataContractAttributes));
sb.AppendLine("{0}AddIndexesToDataMembers: {1}".Fmt(defaultValue("AddIndexesToDataMembers"), Config.AddIndexesToDataMembers));
sb.AppendLine("{0}AddGeneratedCodeAttributes: {1}".Fmt(defaultValue("AddGeneratedCodeAttributes"), Config.AddGeneratedCodeAttributes));
sb.AppendLine("{0}AddResponseStatus: {1}".Fmt(defaultValue("AddResponseStatus"), Config.AddResponseStatus));
sb.AppendLine("{0}AddImplicitVersion: {1}".Fmt(defaultValue("AddImplicitVersion"), Config.AddImplicitVersion));
sb.AppendLine("{0}InitializeCollections: {1}".Fmt(defaultValue("InitializeCollections"), Config.InitializeCollections));
sb.AppendLine("{0}IncludeTypes: {1}".Fmt(defaultValue("IncludeTypes"), Config.IncludeTypes.Safe().ToArray().Join(",")));
sb.AppendLine("{0}ExcludeTypes: {1}".Fmt(defaultValue("ExcludeTypes"), Config.ExcludeTypes.Safe().ToArray().Join(",")));
sb.AppendLine("{0}AddDefaultXmlNamespace: {1}".Fmt(defaultValue("AddDefaultXmlNamespace"), Config.AddDefaultXmlNamespace));
//[GeneratedCode]
//sb.AppendLine("{0}DefaultNamespaces: {1}".Fmt(defaultValue("DefaultNamespaces"), Config.DefaultNamespaces.ToArray().Join(", ")));
sb.AppendLine("*/");
sb.AppendLine();
namespaces.Where(x => !string.IsNullOrEmpty(x))
.Each(x => sb.AppendLine("using {0};".Fmt(x)));
if (Config.AddGeneratedCodeAttributes)
sb.AppendLine("using System.CodeDom.Compiler;");
if (Config.AddDataContractAttributes
&& Config.AddDefaultXmlNamespace != null)
{
sb.AppendLine();
namespaces.Where(x => !Config.DefaultNamespaces.Contains(x)).ToList()
.ForEach(x =>
sb.AppendLine("[assembly: ContractNamespace(\"{0}\", ClrNamespace=\"{1}\")]"
.Fmt(Config.AddDefaultXmlNamespace, x)));
}
sb.AppendLine();
string lastNS = null;
var existingTypes = new HashSet<string>();
var requestTypes = metadata.Operations.Select(x => x.Request).ToHashSet();
var requestTypesMap = metadata.Operations.ToSafeDictionary(x => x.Request);
var responseTypes = metadata.Operations
.Where(x => x.Response != null)
.Select(x => x.Response).ToHashSet();
var types = metadata.Types.ToHashSet();
var allTypes = new List<MetadataType>();
allTypes.AddRange(requestTypes);
allTypes.AddRange(responseTypes);
allTypes.AddRange(types);
var orderedTypes = allTypes
.OrderBy(x => x.Namespace)
.ThenBy(x => x.Name);
foreach (var type in orderedTypes)
{
var fullTypeName = type.GetFullName();
if (requestTypes.Contains(type))
{
if (!existingTypes.Contains(fullTypeName))
{
MetadataType response = null;
MetadataOperationType operation;
if (requestTypesMap.TryGetValue(type, out operation))
{
response = operation.Response;
}
//.........这里部分代码省略.........
示例2: GetCode
public string GetCode(MetadataTypes metadata, IRequest request)
{
var namespaces = Config.GetDefaultNamespaces(metadata);
var typeNamespaces = new HashSet<string>();
metadata.RemoveIgnoredTypesForNet(Config);
metadata.Types.Each(x => typeNamespaces.Add(x.Namespace));
metadata.Operations.Each(x => typeNamespaces.Add(x.Request.Namespace));
// Look first for shortest Namespace ending with `ServiceModel` convention, else shortest ns
var globalNamespace = Config.GlobalNamespace
?? typeNamespaces.Where(x => x.EndsWith("ServiceModel"))
.OrderBy(x => x).FirstOrDefault()
?? typeNamespaces.OrderBy(x => x).First();
Func<string, string> defaultValue = k =>
request.QueryString[k].IsNullOrEmpty() ? "//" : "";
var sb = new StringBuilderWrapper(new StringBuilder());
sb.AppendLine("(* Options:");
sb.AppendLine("Date: {0}".Fmt(DateTime.Now.ToString("s").Replace("T", " ")));
sb.AppendLine("Version: {0}".Fmt(Env.ServiceStackVersion));
sb.AppendLine("Tip: {0}".Fmt(HelpMessages.NativeTypesDtoOptionsTip.Fmt("//")));
sb.AppendLine("BaseUrl: {0}".Fmt(Config.BaseUrl));
sb.AppendLine();
sb.AppendLine("{0}GlobalNamespace: {1}".Fmt(defaultValue("GlobalNamespace"), Config.GlobalNamespace));
sb.AppendLine("{0}MakeDataContractsExtensible: {1}".Fmt(defaultValue("MakeDataContractsExtensible"), Config.MakeDataContractsExtensible));
sb.AppendLine("{0}AddReturnMarker: {1}".Fmt(defaultValue("AddReturnMarker"), Config.AddReturnMarker));
sb.AppendLine("{0}AddDescriptionAsComments: {1}".Fmt(defaultValue("AddDescriptionAsComments"), Config.AddDescriptionAsComments));
sb.AppendLine("{0}AddDataContractAttributes: {1}".Fmt(defaultValue("AddDataContractAttributes"), Config.AddDataContractAttributes));
sb.AppendLine("{0}AddIndexesToDataMembers: {1}".Fmt(defaultValue("AddIndexesToDataMembers"), Config.AddIndexesToDataMembers));
sb.AppendLine("{0}AddGeneratedCodeAttributes: {1}".Fmt(defaultValue("AddGeneratedCodeAttributes"), Config.AddGeneratedCodeAttributes));
sb.AppendLine("{0}AddResponseStatus: {1}".Fmt(defaultValue("AddResponseStatus"), Config.AddResponseStatus));
sb.AppendLine("{0}AddImplicitVersion: {1}".Fmt(defaultValue("AddImplicitVersion"), Config.AddImplicitVersion));
sb.AppendLine("{0}IncludeTypes: {1}".Fmt(defaultValue("IncludeTypes"), Config.IncludeTypes.Safe().ToArray().Join(",")));
sb.AppendLine("{0}ExcludeTypes: {1}".Fmt(defaultValue("ExcludeTypes"), Config.ExcludeTypes.Safe().ToArray().Join(",")));
sb.AppendLine("{0}InitializeCollections: {1}".Fmt(defaultValue("InitializeCollections"), Config.InitializeCollections));
//sb.AppendLine("{0}AddDefaultXmlNamespace: {1}".Fmt(defaultValue("AddDefaultXmlNamespace"), Config.AddDefaultXmlNamespace));
//sb.AppendLine("{0}DefaultNamespaces: {1}".Fmt(defaultValue("DefaultNamespaces"), Config.DefaultNamespaces.ToArray().Join(", ")));
sb.AppendLine("*)");
sb.AppendLine();
string lastNS = null;
var existingTypes = new HashSet<string>();
var requestTypes = metadata.Operations.Select(x => x.Request).ToHashSet();
var requestTypesMap = metadata.Operations.ToSafeDictionary(x => x.Request);
var responseTypes = metadata.Operations
.Where(x => x.Response != null)
.Select(x => x.Response).ToHashSet();
var types = metadata.Types.ToHashSet();
var allTypes = new List<MetadataType>();
allTypes.AddRange(types);
allTypes.AddRange(responseTypes);
allTypes.AddRange(requestTypes);
var orderedTypes = allTypes.OrderTypesByDeps();
sb.AppendLine("namespace {0}".Fmt(globalNamespace.SafeToken()));
sb.AppendLine();
foreach (var ns in namespaces.Where(x => !string.IsNullOrEmpty(x)))
{
sb.AppendLine("open " + ns);
}
if (Config.AddGeneratedCodeAttributes)
sb.AppendLine("open System.CodeDom.Compiler");
foreach (var type in orderedTypes)
{
var fullTypeName = type.GetFullName();
if (requestTypes.Contains(type))
{
if (!existingTypes.Contains(fullTypeName))
{
MetadataType response = null;
MetadataOperationType operation;
if (requestTypesMap.TryGetValue(type, out operation))
{
response = operation.Response;
}
lastNS = AppendType(ref sb, type, lastNS,
new CreateTypeOptions
{
ImplementsFn = () =>
{
if (!Config.AddReturnMarker
&& !type.ReturnVoidMarker
&& type.ReturnMarkerTypeName == null)
return null;
if (type.ReturnVoidMarker)
return "IReturnVoid";
if (type.ReturnMarkerTypeName != null)
return Type("IReturn`1", new[] { Type(type.ReturnMarkerTypeName) });
return response != null
? Type("IReturn`1", new[] { Type(response.Name, response.GenericArgs) })
: null;
//.........这里部分代码省略.........