⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 externalreferences.t4

📁 visual basic.net进销存程序设计.rar] - visual basic.net进销存程序设计 [进销存管系统.rar] - 进销存管系统,VB源代码 [vb.net计算机机房管理系统.
💻 T4
📖 第 1 页 / 共 2 页
字号:
        <#= cc #>    get
        <#= cc #>    {
        <#= cc #>        object value = ReferencedType.GetField("<#= field.Name #>").GetValue(_reference);
        <#= cc #>        return value != null ? new <#= fieldType #>(value) : null;
        <#= cc #>    }
<#
                }
                else
                {
#>
        <#= cc #>    get { return (<#= fieldType #>) ReferencedType.GetField("<#= field.Name #>").GetValue(_reference); }
<#
                }
#>>
        <#= cc #>    set { ReferencedType.GetField("<#= field.Name #>").SetValue(_reference, value<#= wrapped ? " != null ? value.Reference : null" : "" #>); }
        <#= cc #>}
<#
            }
            foreach (PropertyInfo property in type.GetProperties())
            {
                string cc = !IncludeMember(type, property.Name) || !IsExposableType(property.PropertyType) ? "// " : "";
                string propertyType = GetTypeName(property.PropertyType);
                bool wrapped = IsWrappedType(property.PropertyType);
#>
        <#= cc #>[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Auto-generated wrapper")]
        <#= cc #>public <#= propertyType #> <#= property.Name #>
        <#= cc #>{
<#
                if (property.CanRead)
                {
                    if (wrapped)
                    {
#>
        <#= cc #>    get
        <#= cc #>    {
        <#= cc #>        object value = ReferencedType.GetProperty("<#= property.Name #>").GetValue(_reference, new object[] { });
        <#= cc #>        return value != null ? new <#= propertyType #>(value) : null;
        <#= cc #>    }
<#
                    }
                    else
                    {
#>
        <#= cc #>    get { return (<#= propertyType #>) ReferencedType.GetProperty("<#= property.Name #>").GetValue(_reference, new object[] { }); }
<#
                    }
                }
                if (property.CanWrite)
                {
#>
        <#= cc #>    set { ReferencedType.GetProperty("<#= property.Name #>").SetValue(_reference, value<#= wrapped ? " != null ? value.Reference : null" : "" #>, new object[] { }); }
<#
                }
#>
        <#= cc #>}
        
<# 
            }
            foreach (MethodInfo method in type.GetMethods())
            {
                if (method.IsSpecialName)
                {
                    continue;
                }
                
                ParameterInfo[] parameters = method.GetParameters();
                
                string cc = !IncludeMember(type, method.Name) || !IsExposableType(method.ReturnType) ? "// " : "";
                foreach (ParameterInfo parameter in parameters)
                {
                    if (!IsExposableType(parameter.ParameterType) || parameter.IsOut)
                    {
                        cc = "// ";
                    }
                }
                
                bool wrapped = IsWrappedType(method.ReturnType);
                bool returns = method.ReturnType != typeof(void);
                string returnType = GetTypeName(method.ReturnType);
                
                string returnName = "value";
                bool unique;
                do
                {
                    unique = true;
                    foreach (ParameterInfo parameter in parameters)
                    {
                        if (string.Compare(parameter.Name, returnName, StringComparison.Ordinal) == 0)
                        {
                            unique = false;
                            returnName = "_" + returnName;
                            break;
                        }
                    }
                } while (!unique);
#>
        <#= cc #>[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Auto-generated wrapper")]
        <#= cc #>public <#= returnType #> <#= method.Name #>(<#
                    bool first = true;
                    foreach (ParameterInfo parameter in parameters)
                    {
                        if (!first)
                        {
                            #>, <#
                        }
                        first = false;
                        #><#= GetTypeName(parameter.ParameterType) #> <#= parameter.Name #><#
                    }
#>)
        <#= cc #>{
        <#= cc #>    <# if (returns) { #>object <#= returnName #> = <# } #>ReferencedType.GetMethod("<#= method.Name #>").Invoke(_reference, new object[] { <#
                    first = true;
                    foreach (ParameterInfo parameter in parameters)
                    {
                        if (!first)
                        {
                            #>, <#
                        }
                        first = false;
                        if (IsWrappedType(parameter.ParameterType))
                        {
                            #><#= parameter.Name #> != null ? <#= parameter.Name #>.Reference : null<#
                        }
                        else
                        {
                            #><#= parameter.Name #><#
                        }
                    }#> });
<#
                    if (returns)
                    {
                        if (wrapped)
                        {
#>
        <#= cc #>    return <#= returnName #> != null ? new <#= returnType #>(<#= returnName #>) : null;
<#
                        }
                        else
                        {
#>
        <#= cc #>    return (<#= returnType #>) <#= returnName #>;
<#
                        }
                    }
#>
        <#= cc #>}
        
<#
            }    
        }
#>
    }

<#
    }
#>
}
<#+ 
    public List<Type> Types = new List<Type>();
    public Dictionary<Assembly, string> Assemblies = new Dictionary<Assembly, string>();
    public Dictionary<Type, Type> TypeAliases = new Dictionary<Type, Type>();
    public Dictionary<Type, List<string>> TypeMembers = new Dictionary<Type, List<string>>();
    
    public string GetTypeName(Type t)
    {
        if (t == typeof(void))
        {
            return "void";
        }
        t = (TypeAliases.ContainsKey(t)) ? TypeAliases[t] : t;
        return string.Format("{0}{1}", !Assemblies.ContainsKey(t.Assembly) ? t.Namespace + "." : "", t.Name);
    }
    
    public bool IsExposableType(Type t)
    {
        return !t.IsPointer && !t.IsByRef && (!Assemblies.ContainsKey(t.Assembly) || Types.Contains(t) || (TypeAliases.ContainsKey(t) && IsExposableType(TypeAliases[t])));
    }
    
    public bool IsWrappedType(Type t)
    {
        return Types.Contains(t) || (TypeAliases.ContainsKey(t) && IsWrappedType(TypeAliases[t]));
    }
    
    public void AddType(Type type, params string[] members)
    {
        Types.Add(type);
        TypeMembers[type] = new List<string>(members);
    }
    
    public bool IncludeMember(Type type, string name)
    {
        List<string> members;
        if (!TypeMembers.TryGetValue(type, out members) || members == null)
        {
            return false;
        }
        return members.Contains(name);
    }
#>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -