本文整理汇总了C#中IndentedTextWriter类的典型用法代码示例。如果您正苦于以下问题:C# IndentedTextWriter类的具体用法?C# IndentedTextWriter怎么用?C# IndentedTextWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IndentedTextWriter类属于命名空间,在下文中一共展示了IndentedTextWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteProxy
protected override void WriteProxy(IndentedTextWriter writer)
{
if (writer == null)
throw new ArgumentNullException("writer");
writer.WriteLine("// This JavaScript was automatically generated by");
writer.Write("// ");
writer.WriteLine(GetType().AssemblyQualifiedName);
writer.Write("// on ");
DateTime now = DateTime.Now;
TimeZone timeZone = TimeZone.CurrentTimeZone;
writer.Write(now.ToLongDateString());
writer.Write(" at ");
writer.Write(now.ToLongTimeString());
writer.Write(" (");
writer.Write(timeZone.IsDaylightSavingTime(now) ?
timeZone.DaylightName : timeZone.StandardName);
writer.WriteLine(")");
writer.WriteLine();
string version = Mask.EmptyString(Request.QueryString["v"], "1").Trim();
Uri url = new Uri(Request.Url.GetLeftPart(UriPartial.Path));
if (version.Equals("2"))
Version2(Service.GetClass(), url, writer);
else
Version1(Service.GetClass(), url, writer);
}
示例2: Outline
public Outline (Type t, TextWriter output, bool declared_only, bool show_private, bool filter_obsolete)
{
this.t = t;
this.o = new IndentedTextWriter (output, "\t");
this.declared_only = declared_only;
this.show_private = show_private;
this.filter_obsolete = filter_obsolete;
}
示例3: Generate
public void Generate() {
_anyError = false;
var reflectedMethods = new Dictionary<string, MethodInfo>();
foreach (var type in typeof(RubyOps).Assembly.GetExportedTypes()) {
if (type.IsDefined(typeof(ReflectionCachedAttribute), false)) {
Console.WriteLine(type);
ReflectMethods(reflectedMethods, type);
}
}
var methods = reflectedMethods.Sort((m1, m2) => m1.Key.CompareTo(m2.Key));
if (_anyError) {
Environment.ExitCode = 1;
return;
}
using (TextWriter writer = new StreamWriter(File.Open(_outFile, FileMode.Create, FileAccess.Write))) {
_output = new IndentedTextWriter(writer, " ");
_output.NewLine = "\r\n";
WriteLicenseStatement(writer);
_output.WriteLine("using System.Reflection;");
_output.WriteLine("using System.Diagnostics;");
_output.WriteLine("using IronRuby.Runtime;");
_output.WriteLine("using IronRuby.Builtins;");
_output.WriteLine("using Microsoft.Scripting.Utils;");
_output.WriteLine();
_output.WriteLine("namespace {0} {{", MethodCacheType.Namespace);
_output.Indent++;
_output.WriteLine("public static partial class {0} {{", MethodCacheType.Name);
_output.Indent++;
GenerateOps(methods);
_output.WriteLine();
GenerateStringFactoryOps("CreateRegex");
GenerateStringFactoryOps("CreateMutableString");
GenerateStringFactoryOps("CreateSymbol");
GenerateOptimizedOps("Yield", BlockDispatcher.MaxBlockArity);
GenerateOptimizedOps("YieldSplat", BlockDispatcher.MaxBlockArity);
_output.Indent--;
_output.WriteLine("}");
_output.Indent--;
_output.WriteLine("}");
Debug.Assert(_output.Indent == 0);
}
}
示例4: WriteClassTail
private static void WriteClassTail(IndentedTextWriter writer)
{
writer.WriteLine(@"def __call(self, method, params):
self.__id = self.__id + 1
response = json.loads(urllib.urlopen(self.url, urllib.urlencode([('JSON-RPC', json.dumps({ 'id' : self.__id, 'method' : method, 'params' : params }))])).read())
if response.has_key('error'): raise Error(None, response)
return response['result']
");
writer.Indent--;
}
示例5: ProcessRequest
protected override void ProcessRequest()
{
if (!Modified())
{
Response.StatusCode = 304;
return;
}
if (HasLastModifiedTime)
{
Response.Cache.SetCacheability(HttpCacheability.Public);
//
// Unfortunately, HttpCachePolicy.SetLastModified fails
// if the last modified time passed has a precision higher
// than second so we need to crop anything less than a
// second before setting it.
//
long lastModifiedTicks = LastModifiedTime.Ticks;
Response.Cache.SetLastModified(new DateTime(lastModifiedTicks - (lastModifiedTicks % TimeSpan.TicksPerSecond)));
}
IRpcServiceDescriptor service = TargetService.GetDescriptor();
Response.ContentType = "text/javascript";
Response.AppendHeader("Content-Disposition",
"attachment; filename=" + service.Name + "Proxy.js");
IndentedTextWriter writer = new IndentedTextWriter(Response.Output);
writer.WriteLine("// This JavaScript was automatically generated by");
writer.Write("// ");
writer.WriteLine(GetType().AssemblyQualifiedName);
writer.Write("// on ");
DateTime now = DateTime.Now;
TimeZone timeZone = TimeZone.CurrentTimeZone;
writer.Write(now.ToLongDateString());
writer.Write(" at ");
writer.Write(now.ToLongTimeString());
writer.Write(" (");
writer.Write(timeZone.IsDaylightSavingTime(now) ?
timeZone.DaylightName : timeZone.StandardName);
writer.WriteLine(")");
writer.WriteLine();
string version = Mask.EmptyString(Request.QueryString["v"], "1").Trim();
if (version.Equals("2"))
Version2(service, new Uri(Request.Url.GetLeftPart(UriPartial.Path)), writer);
else
Version1(service, new Uri(Request.Url.GetLeftPart(UriPartial.Path)), writer);
}
示例6: Generate
public void Generate() {
_anyError = false;
var unsortedMethods = ReflectMethods(typeof(RubyOps)).Values;
List<MethodInfo> methods = new List<MethodInfo>();
methods.AddRange(unsortedMethods);
methods.Sort((m1, m2) => m1.Name.CompareTo(m2.Name));
if (_anyError) {
Environment.ExitCode = 1;
return;
}
using (TextWriter writer = new StreamWriter(File.Open(_outFile, FileMode.Create, FileAccess.Write))) {
_output = new IndentedTextWriter(writer, " ");
_output.NewLine = "\r\n";
WriteLicenseStatement(writer);
_output.WriteLine("using System.Reflection;");
_output.WriteLine("using System.Diagnostics;");
_output.WriteLine("using IronRuby.Runtime;");
_output.WriteLine("using Microsoft.Scripting.Utils;");
_output.WriteLine();
_output.WriteLine("namespace {0} {{", MethodCacheType.Namespace);
_output.Indent++;
_output.WriteLine("internal static partial class {0} {{", MethodCacheType.Name);
_output.Indent++;
GenerateOps(methods);
_output.WriteLine();
GenerateStringFactoryOps("CreateRegex");
GenerateStringFactoryOps("CreateMutableString");
GenerateStringFactoryOps("CreateSymbol");
GenerateOptimizedOps("Yield", BlockDispatcher.MaxBlockArity);
GenerateOptimizedOps("YieldSplat", BlockDispatcher.MaxBlockArity);
_output.Indent--;
_output.WriteLine("}");
_output.Indent--;
_output.WriteLine("}");
Debug.Assert(_output.Indent == 0);
}
}
示例7: WriteProxy
protected override void WriteProxy(IndentedTextWriter writer)
{
if (writer == null)
throw new ArgumentNullException("writer");
WriteProlog(writer);
ServiceClass serviceClass = Service.GetClass();
WriteClass(writer, serviceClass);
foreach (Method method in serviceClass.GetMethods())
WriteMethod(writer, method);
WriteClassTail(writer);
WriteEpilog(writer);
}
示例8: ProcessRequest
protected override void ProcessRequest()
{
if (!Modified())
{
Response.StatusCode = 304;
return;
}
if (HasLastModifiedTime)
{
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetLastModified(LastModifiedTime);
}
JsonRpcServiceClass service = Service.GetClass();
Response.ContentType = "text/javascript";
Response.AppendHeader("Content-Disposition",
"attachment; filename=" + service.Name + "Proxy.js");
IndentedTextWriter writer = new IndentedTextWriter(Response.Output);
writer.WriteLine("// This JavaScript was automatically generated by");
writer.Write("// ");
writer.WriteLine(GetType().AssemblyQualifiedName);
writer.Write("// on ");
DateTime now = DateTime.Now;
TimeZone timeZone = TimeZone.CurrentTimeZone;
writer.Write(now.ToLongDateString());
writer.Write(" at ");
writer.Write(now.ToLongTimeString());
writer.Write(" (");
writer.Write(timeZone.IsDaylightSavingTime(now) ?
timeZone.DaylightName : timeZone.StandardName);
writer.WriteLine(")");
writer.WriteLine();
string version = Mask.EmptyString(Request.QueryString["v"], "1").Trim();
if (version.Equals("2"))
Version2(service, new Uri(Request.Url.GetLeftPart(UriPartial.Path)), writer);
else
Version1(service, new Uri(Request.Url.GetLeftPart(UriPartial.Path)), writer);
}
示例9: WriteClass
private void WriteClass(IndentedTextWriter writer, ServiceClass serviceClass)
{
writer.Write("class ");
writer.Write(serviceClass.Name);
writer.WriteLine(":");
writer.Indent++;
writer.Write(_docQuotes);
writer.Indent--;
if (serviceClass.Description.Length > 0)
{
writer.WriteLine(serviceClass.Description);
writer.WriteLine();
}
writer.WriteLine("This Python class was automatically generated by");
writer.WriteLine(GetType().AssemblyQualifiedName);
DateTime now = DateTime.Now;
writer.Write("on ");
writer.Write(now.ToLongDateString());
writer.Write(" at ");
writer.Write(now.ToLongTimeString());
writer.Write(" (");
TimeZone timeZone = TimeZone.CurrentTimeZone;
writer.Write(timeZone.IsDaylightSavingTime(now) ?
timeZone.DaylightName : timeZone.StandardName);
writer.WriteLine(")");
writer.WriteLine(_docQuotes);
writer.Indent++;
Uri url = new Uri(Request.Url.GetLeftPart(UriPartial.Path));
writer.WriteLine(@"def __init__(self, url = '" + url + @"'):
self.url = url
self.__id = 0");
writer.WriteLine();
}
示例10: Outline
public Outline (Universe universe, Assembly mscorlib, Type t, TextWriter output, bool declared_only, bool show_private, bool filter_obsolete)
{
if (universe == null)
throw new ArgumentNullException ("universe");
if (mscorlib == null)
throw new ArgumentNullException ("mscorlib");
this.universe = universe;
this.mscorlib = mscorlib;
this.t = t;
this.o = new IndentedTextWriter (output, "\t");
this.declared_only = declared_only;
this.show_private = show_private;
this.filter_obsolete = filter_obsolete;
type_multicast_delegate = mscorlib.GetType("System.MulticastDelegate");
type_object = mscorlib.GetType ("System.Object");
type_value_type = mscorlib.GetType ("System.ValueType");
type_int = mscorlib.GetType ("System.Int32");
type_flags_attribute = mscorlib.GetType ("System.FlagsAttribute");
type_obsolete_attribute = mscorlib.GetType ("System.ObsoleteAttribute");
type_param_array_attribute = mscorlib.GetType ("System.ParamArrayAttribute");
}
示例11: JsonWriter
public JsonWriter(TextWriter writer, bool minimizeWhitespace)
{
_writer = new IndentedTextWriter(writer, minimizeWhitespace);
_scopes = new Stack<Scope>();
}
示例12: WriteProlog
private void WriteProlog(IndentedTextWriter writer)
{
writer.WriteLine("import simplejson");
writer.WriteLine("import urllib");
writer.WriteLine();
}
示例13: WriteMethod
private void WriteMethod(IndentedTextWriter writer, Method method)
{
string clientMethodName = method.Name.Replace(".", "_");
writer.Write("def ");
writer.Write(clientMethodName);
writer.Write("(self");
Parameter[] parameters = method.GetParameters();
foreach (Parameter parameter in parameters)
{
writer.Write(", ");
writer.Write(parameter.Name);
}
writer.WriteLine("):");
writer.Indent++;
if (method.Description.Length > 0)
{
// TODO: What to do if /* and */ appear in the summary?
writer.Write(_docQuotes);
writer.WriteLine(method.Description);
writer.WriteLine(_docQuotes);
}
writer.Write("return self.__call('");
writer.Write(method.Name);
writer.Write("', (");
foreach (Parameter parameter in parameters)
{
writer.Write(parameter.Name);
writer.Write(", ");
}
writer.WriteLine("))");
writer.Indent--;
writer.WriteLine();
}
示例14: WriteEpilog
private void WriteEpilog(IndentedTextWriter writer)
{
writer.WriteLine(@"class Error(Exception):
""""""Exception raised when an error occurs calling a JSON-RPC service.""""""
def __init__(self, message = None, response = None):
self.error = response['error']
self.response = response
if message: self.message = str(message)
else: self.message = self.error['message']");
}
示例15: Version1
private static void Version1(JsonRpcServiceClass service, Uri url, IndentedTextWriter writer)
{
Debug.Assert(service != null);
Debug.Assert(url!= null);
Debug.Assert(!url.IsFile);
Debug.Assert(writer != null);
writer.WriteLine("// Proxy version 1.0");
writer.WriteLine();
writer.Write("function ");
writer.Write(service.Name);
writer.WriteLine("(url)");
writer.WriteLine("{");
writer.Indent++;
JsonRpcMethod[] methods = service.GetMethods();
string[] methodNames = new string[methods.Length];
for (int i = 0; i < methods.Length; i++)
{
JsonRpcMethod method = methods[i];
methodNames[i] = method.Name;
if (method.Description.Length > 0)
{
// TODO: What to do if /* and */ appear in the summary?
writer.Write("/* ");
writer.Write(method.Description);
writer.WriteLine(" */");
writer.WriteLine();
}
writer.Write("this[\"");
writer.Write(method.Name);
writer.Write("\"] = function(");
JsonRpcParameter[] parameters = method.GetParameters();
foreach (JsonRpcParameter parameter in parameters)
{
writer.Write(parameter.Name);
writer.Write(", ");
}
writer.WriteLine("callback)");
writer.WriteLine("{");
writer.Indent++;
writer.Write("return call(\"");
writer.Write(method.Name);
writer.Write("\", [");
foreach (JsonRpcParameter parameter in parameters)
{
if (parameter.Position > 0)
writer.Write(',');
writer.Write(' ');
writer.Write(parameter.Name);
}
writer.WriteLine(" ], callback);");
writer.Indent--;
writer.WriteLine("}");
writer.WriteLine();
}
writer.Write("var url = typeof(url) === 'string' ? url : '");
writer.Write(url);
writer.WriteLine("';");
writer.WriteLine(@"var self = this;
var nextId = 0;
function call(method, params, callback)
{
var request = { id : nextId++, method : method, params : params };
return callback == null ?
callSync(method, request) : callAsync(method, request, callback);
}
function callSync(method, request)
{
var http = newHTTP();
http.open('POST', url, false, self.httpUserName, self.httpPassword);
setupHeaders(http, method);
http.send(JSON.stringify(request));
if (http.status != 200)
throw { message : http.status + ' ' + http.statusText, toString : function() { return message; } };
var response = JSON.eval(http.responseText);
if (response.error != null) throw response.error;
return response.result;
}
function callAsync(method, request, callback)
{
var http = newHTTP();
http.open('POST', url, true, self.httpUserName, self.httpPassword);
setupHeaders(http, method);
//.........这里部分代码省略.........