Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何构造一个类型,以容纳两个';类型';数据类型,作为单个参数发送_C#_Class_Optimization_Types - Fatal编程技术网

C# 如何构造一个类型,以容纳两个';类型';数据类型,作为单个参数发送

C# 如何构造一个类型,以容纳两个';类型';数据类型,作为单个参数发送,c#,class,optimization,types,C#,Class,Optimization,Types,我需要实现这种方法——两种数据作为一组参数在一个类型中发送,这样一种类型将保存这两个参数。这样我就可以通过某种方法将类型传递给处理 第一个数据项是: 要显示的列,名为:显示 第二个数据项: 显示的列的副本(或仅显示该列的一部分),因为它具有相同的源,只有这些列将不会显示。。。换句话说,列要省略,因此我将其命名为:省略 两者都是我命名的列类型-SelectedColumns 公共类选择的颜色 { 公共枚举重新派生模式 { 显示, 省略 } 省略公共类 { } 公开课展示 { } } 因为

我需要实现这种方法——两种数据作为一组参数在一个类型中发送,这样一种类型将保存这两个参数。这样我就可以通过某种方法将
类型
传递给处理

第一个数据项是:

  • 要显示的列,名为:
    显示
第二个数据项:

  • 显示的
    列的副本(或仅显示该列的一部分)
    ,因为它具有相同的源,只有这些列将不会显示。。。换句话说,列要省略,因此我将其命名为:
    省略
两者都是我命名的列类型-
SelectedColumns

公共类选择的颜色
{
公共枚举重新派生模式
{
显示,
省略
}
省略公共类
{
}
公开课展示
{
}
}
因为要显示的这组列的请求是通过选择表名来完成的。因此,作为数据显示的列类别根据用户选择的不同而不同。
SelectedColumns
的可用来源如下所示:

公共类表名
{
公共静态只读字符串tblCustomers=“tblCustomers”;
公共静态只读字符串tblProducts=“tblProducts”;
}
公共类TblColumns
{
公共类TBL客户
{
public const string custID=“custID”,
Name=“Name”,
Phone=“Phone”;
Email=“Email”;
}
公共类TBL产品
{
公共常量字符串prudcid=“prudcid”,
PrudcName=“PrudcId”,
PrudctCategory=“PrudctCategory”;
}
…等'
}
当用户选择一组表列时。。。在本例中,用户可以从任何表中。。选择
Customers
Products
列(例如
SelectedColumns
-is
tblCustomers
列),然后我需要有另一个列表,这些列表是用户从所有可用表列中选择忽略(不显示)的列表

假设用户选择将表客户作为表。他选择省略
tblCustomers.custID
+
tblCustomer.Email
,因为他只需要显示姓名和电话

我遇到的问题是,当这些参数在我的范围内(表名+要忽略的列)时,我如何将其发送到进程(作为一个参数传递)?这就是为什么我创建了一个专用类,将这个
类型
作为发送参数保存在一起:
所有列
+
省略列

这就是我目前所处的困境;我需要知道如何使用它根据用户选择构建参数

公共类选择列
{
公共枚举重新派生模式
{
显示,
省略
}
省略公共类
{
列表省略cols_ListStr=新列表();
}
公开课展示
{
List dispCols_ListStr=新列表();
}
}
在这一部分中,我通过
reflection
作为数据供应商,通过以下方法检索列列表:

通过嵌套的
类名
获取任何嵌套的类字段,如
列表
,它是父类-
类型

public静态列表anyNestedClassFiledsAsListByType(字符串NetedClassName)
{
var retnestedClassFildListValues=typeof(ClassToReturneofItsNested)。GetNestedTypes()
.First(t=>String.Compare(t.Name,NetedClassName,true)==0).GetFields(BindingFlags.Public | BindingFlags.Static)
。其中(f=>f.FieldType==typeof(string))。选择(f=>(string)f.GetValue(null)).ToList();
返回retnestedClassFildListValues;
}
所以为了产生这个,我可以使用上面的方法

var TableColumns\u ALL=
anyNestedClassFldsAsListByType(tableNames.tblCustomers);
我的问题与需要发送TableColumns\u ALL+要忽略的选定列,然后由下面的
renderSelectedTable()
处理的类有关

因此,它甚至比反射的复杂性更基本,但我仍然不知道如何使用popper方法来构造
SelectedColumns类
,因此它将适应并格式化这个新数据类型的结构,它将作为一个参数发送。方法是这样的

public void renderSelectedTable(SelectedColoumns CurrentUserSelectedCols)
{
    StringBuilder NwTRLoopSB = new StringBuilder();

    string curRowStyle= string.Empty,
           nwLine = Environment.NewLine + "\t\t\t",
           BaseTemplateTD = string.Empty;

    NwTRLoopSB.Append(
            string.Format(
                "<table id='tbl_Settings' cellspacing='0' border='1'><tr id='TR_headers'{0}>{1}",
                curRowStyle,
                nwLine
                )._Dhtml_DoubleQoutes()
        );
    foreach (var Item in SelectedListStr.Select((Val, counter) => new { Value = Val, Index = counter }))
    {
            curRowStyle = Lsts.DynamicStyle_Generator(Item.Index);

            if(Lsts.ExcludeColumns(Item.Value, OmittedCols))
            {
                BaseTemplateTD = string.Format("<td>{0}</td>{1}", Item.Value, nwLine)._Dhtml_DoubleQoutes();
                NwTRLoopSB.Append(BaseTemplateTD);
            }    
      
    }///ENd TR cells generator Section

    NwTRLoopSB.Append("</tr></table>");
    return NwTRLoopSB.ToString();

}
public void renderSelectedTable(selectedcolumns CurrentUserSelectedCols)
{
StringBuilder NwTRLoopSB=新StringBuilder();
string curRowStyle=string.Empty,
nwLine=Environment.NewLine+“\t\t\t”,
BaseTemplateTD=string.Empty;
NwTRLoopSB.Append(
字符串格式(
"{1}",
科罗斯式,
nwLine
).(Dhtml)u DoubleQoutes()
);
foreach(SelectedListStr.Select中的变量项((Val,counter)=>new{Value=Val,Index=counter}))
{
curRowStyle=Lsts.DynamicStyle_生成器(项目索引);
if(Lsts.ExcludeColumns(Item.Value,省略的cols))
{
BaseTemplateTD=string.Format(“{0}{1}”,Item.Value,nwLine)。\u Dhtml\u DoubleQoutes();
NwTRLoopSB.Append(BaseTemplateTD);
}    
}///端部TR电池发生器部分
NwTRLoopSB.追加(“”);
返回NwTRLoopSB.ToString();
}

所以。。第一。。设计说明:给出了列的列表。。您可以显示列,也可以不显示列。。visib没有其他选项
public class SelectedColumns {
    public List<string> displayed { get; set; }
    public List<string> omitted { get; set; }
}
public class Column{
    public string Name { get; set; }
    public bool Visible { get; set; }
}

public class Grid{
    public List<Column> Columns { get; set; }
}
public class SelectedColumns
{
    //instead of the enum you would have boolean in the column type "Visible" (whether is shown or not)
    public enum renederingMode
    {
        Displayed,
        omitted
    }
    // instead of both these you would have a List o Column types that have a name AND a boolean, so you have your List<string> and a boolean to indicate whether it is visible or ommited. Well at least that's how I understood it.
    public class ommited
    {

    }
    public class displayed
    {
    }
}