Tag: 属性

基于属性对XML进行排序和分组

我在C#中使用LINQ to XML,我需要对xml节点的属性进行一些排序。 我的xml看起来像这样。 我可以使用orderby子句对xml进行排序 var query= from claim in root.Elements(“Claim”) let Key = claim.Attributes(“Key”).First().Value let Carrier = claim.Attributes(“Carrier”).First().Value let CarrierZip = int.Parse(claim.Attributes(“CarrierZip”).First().Value) let Pages = claim.Attributes(“Pages”).First().Value orderby Pages ascending, CarrierZip ascending, Carrier ascending select claim; 然后我从查询中获取密钥列表。 我想要做的是获得所有索赔的集合1页,然后所有索赔2页等等,但我不知道最大页数是多少。 谁能帮我吗? 编辑 – 我改变了关于如何实现这一点的初步想法,我现在希望将其视为类似于此。 List<List<List<List>>> All claims – 1 page -zip1 -carr1 -int claim key -int claim2 […]

如何在属性get或set body中获取属性的属性

是否可以在没有StackFrame情况下获取属性get或set body中的属性? 例如 [SomeAttribute] public int SomeProp { get { //Get of SomeAttribute is set on this property } set { //Get of SomeAttribute is set on this property } }

C#财产系统

更新抱歉。 我并不是说整个reflection库都是不受限制的。 我只是意味着疯狂的* .Invoke()东西。 嗨, 我需要在C#中实现一个允许正常属性访问的属性系统 [property_attribute()] return_type Property { get; set; } 并通过字符串访问 SetProperty(string name, object value); object GetProperty(string name); 然而, 我不想单独注册每个属性。 我不想用reflection 我不想通过字典访问属性(即没有PropertyTable[“abc”]=val; ) 这种方案是集群计算方案所必需的,我必须远程和本地设置属性。 所有属性都将具有将在初始化时读取的自定义属性。 我希望获得持续的运行时性能。 目前,我的想法是让自定义解析器/ preprocesser在运行时解析/编译脚本并生成set / get代码,如下所示: object GetProperty(string name) { if(name = “blah”) return Property1; … } … 但是,我将无法使用此方案调试代码。 谁能想到解决方案? 谢谢

DirectShow:如何更改filter属性?

我正在开发一个帮助用户配置电视调谐卡的应用程序。 基本上用户选择设备,应用程序生成图形文件(.GRF)作为输出。 但是,用户应该能够更改一些设置。 这些设置包括video标准(PAL,NTSC,SECAM),video输入(调谐器,复合video,SVideo)等。 在GraphEdit中,可以通过右键单击所需的filter,然后选择“filter属性…”来完成。 但是,我不知道如何在代码中实现相同的function。 问题1 :如何在代码中更改DirectShowfilter的属性? 因为我使用ICaptureGraphBuilder2 :: RenderStream来构建我的图形,所以我只保留对源filter和渲染器的引用。 我希望能够更改的大多数属性都可以在其他filter上找到,例如交叉开关filter,它由RenderStream方法自动添加。 问题2 :如何获取图表中其他filter的引用,以便更改其属性? 注意:我不会使用FindFilterByName,因为我的应用程序应该与大多数电视调谐器卡一起使用,并且每张卡都可以作为不同的名称。 编辑 :我找到了一种通过EnumFilters枚举来获取对这些filter的引用的方法。 然后我在每个filter上使用QueryFilterInfo来查找它的名称。 这与使用FindFilterByName不同,因为我现在可以使用Contains来查找某些单词(如“Crossbar”)。 但是,我已经有一个横杆filter命名的例子(“… Xbar”),所以我仍然在寻找一种更通用的方法来做到这一点。 我希望我能按他们的类别找到filter…… 顺便说一句,我目前正在使用DirectShow.Net库 ,但我相信这种方法应该与C ++库相同。 但是,我并不完全理解C ++语法,因此如果您计划发布(引用)代码示例,那么如果它是在C#或VB.NET中,它将是一个很大的帮助。 解决方案 :查看已接受的答案评论。 我需要将需要更改属性的filter转换为各自的接口。 例如,需要将交叉开关filter连接到IAMCrossbar接口 。 通过此界面,我现在可以更改所有与横杆相关的属性。

c#使用一种方法按元素或属性排序

我需要有时按属性排序xml文档,有时候按元素排序,具体取决于文档的类型。我如何在c#中使用一个sortBy方法来解决这个问题? 非常感谢您的帮助! 例如,我的排序键是“bookID”元素或属性,xml文件是: 100 The cat in the hat 90 another book 103 a new book 或者有时xml有以下格式: The cat in the hat another book a new book

使用构造函数中的reflection设置数据类的属性

我有几个以类似于下面的方式定义的数据类,我正在尝试决定是否为每个数据类都有一个内置的构造函数来填充成员,或者在调用方法中只使用一次reflection: public class reportData { public List Deposits; } public class Deposits { public Deposits(List<Dictionary> LPQReq) { PropertyInfo[] properties = typeof(Deposits).GetProperties(); foreach (Dictionary PQList in LPQReq) { foreach (KeyValuePair kvp in PQList) { MemberInfo info = typeof(Deposits).GetField(kvp.Key) as MemberInfo ?? typeof(Deposits).GetProperty(kvp.Key) as MemberInfo; //PropertyInfo property = properties[kvp.Key]; // info.setvalue } } foreach (PropertyInfo property in […]

将属性作为参数传递

我想为LoadFromXML加载和validation创建一个通用的辅助方法。 如果我加载的XML不完整,我确实希望它在没有抛出exception的情况下完全失败。 目前,我的代码看起来像这样(或多或少) public override bool Load(XElement source) { return new List<Func> { i => this.LoadHelper(i.Element(User.XML_Username), ref this._username, User.Failure_Username), i => this.LoadHelper(i.Element(User.XML_Password), ref this._password, User.Failure_Password) //there are many more invokations of LoadHelper to justify this architecture } .AsParallel() .All(i => i.Invoke(source)); } private bool LoadHelper(XElement k, ref string index, string failure) { if (k != […]

MarshalAsAttribute字符串数组

我试图从Beckhoff-PLC读取报警结构到ac#class。 首先,我必须在c#中使用完全相同的结构,它目前看起来像这样: [StructLayout(LayoutKind.Sequential, Pack = 1)] public class Alarm { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 81)] public string text; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)] public string objectName; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public string[] instancePath = new string[6]; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 24)] public string timeStamp; public int priority; [MarshalAs(UnmanagedType.I1)] public bool acknowledge; [MarshalAs(UnmanagedType.I1)] public bool disabled; [MarshalAs(UnmanagedType.I1)] public bool […]

C#属性数组

我有几个get属性,我希望能够像一组函数一样循环。 我希望能够做到这样的事情 public int prop1 { get; } public string prop2 { get; } public int[] prop3 { get; } public int prop4 { get; } public string prop5 { get; } public string prop6 { get; } Func myProperties = { prop1, prop2, prop3, prop4, prop5, prop6 }; ArrayList myList = new ArrayList(); foreach( […]

LINQ to SQL – 保存前格式化字符串?

我正在尝试将现有(非LINQ to SQL)类转换为LINQ to SQL实体类,该实体类具有现有(db列)属性,如: public string MyString { get { return myString; } set { myString = FormatMyString(value); } } 有没有办法在保存之前对实体类属性的值进行这种处理? 我应该使用某种实体级别的保存事件来进行格式化(如果这样可以工作)? 我知道LINQ to SQL提供了validation,并且生成了On…Changing()部分方法,它们通过值(而不是ref)提供对新值的访问,但这些方法似乎都没有提供实际修改/的方法在设置值时格式化值 。 谢谢您的帮助。