CommonScript.cs

本文介绍了一套C#编程中常用的工具方法,包括访问修饰符转换、类型判断及命名空间管理等功能,为开发者提供了便利。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
 * This file contains script types and methods
 * that are common to all collection templates.
 */

public enum AccessibilityEnum {
    Public,
    Protected,
    Internal,
    ProtectedInternal,
    Private
}

public string GetAccessModifier(AccessibilityEnum accessibility) {
    switch (accessibility) {
        case AccessibilityEnum.Public:            return "public";
        case AccessibilityEnum.Protected:         return "protected";
        case AccessibilityEnum.Internal:          return "internal";
        case AccessibilityEnum.ProtectedInternal: return "protected internal";
        case AccessibilityEnum.Private:           return "private";
        default:                                  return "public";
    }
}

public bool IsInt32(string type) {
    if (type == null || type.Length == 0) return false;
    type = type.ToLower();
    return (type == "int" || type == "integer" || type == "int32"
        || type == "system.int32" || type == "::system.int32");
}

public bool IsString(string type) {
    if (type == null || type.Length == 0) return false;
    type = type.ToLower();
    return (type == "string" || type == "system.string"
        || type == "::system.string");
}

private System.Collections.Specialized.StringCollection
    _namespaces = new System.Collections.Specialized.StringCollection();

public void UsingNamespace(string ns) {
    if (!IncludeNamespaces) return;
    if (ns == null || ns.Length == 0) return;
    if (_namespaces.Contains(ns)) return;

    if (_namespaces.Count == 0) Response.WriteLine();
    Response.WriteLine("using " + ns + ";");
    _namespaces.Add(ns);
}

public void StartNamespace(string ns) {
    if (!IncludeNamespaces) return;
    if (ns == null || ns.Length == 0) return;
    Response.WriteLine();
    Response.WriteLine("namespace " + ns + " {");
}

public void EndNamespace(string ns) {
    if (!IncludeNamespaces) return;
    if (ns == null || ns.Length == 0) return;
    Response.WriteLine("}");
}

public CodeTemplate GenerateInterfaces(string file) {
    CodeTemplate template = GetCodeTemplateInstance(file);
    if (template == null) return null;

    CopyPropertiesTo(template);
    template.SetProperty("IncludeNamespaces", false);
    template.Render(Response);

    return template;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值