【首页> C#>如何插入条件字段与WTForms?】教程文章相关的互联网学习教程文章

.NET/C# 使用 ConditionalWeakTable 附加字段(CLR 版本的附加属性,也可用用来当作弱引用字典 WeakDictionary)【代码】【图】

如果你使用过 WPF/UWP 等 XAML UI 框架,那么应该了解到附加属性的概念。那么没有依赖属性支持的时候如何做附加属性的功能呢?你可能会想到弱引用。但这需要做一个弱引用字典,要写的代码还是非常麻烦的。 本文介绍 .NET 的 ConditionalWeakTable<TKey,TValue> 类型,适用于 .NET Framework 4.0 以上和全部 .NET Core 的版本。本文内容这不是字典验证 这不是字典 现成可用的弱引用字典,即 ConditionalWeakTable<TKey,TValue>。然而...

c# – 为什么这个’标签’是一个字段?【代码】

我目前通过Xamarin书自己工作.在那里你可以看到这个代码:using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using Xamarin.Forms;namespace BookCode{public class Greetings : ContentPage {public Greetings(){Label label;label = new Label{FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),HorizontalOptions = LayoutOptions.Center,Vertica...

c# – 如何检查是否定义了字段?【代码】

在this blog中,它显示了如何检索字段的元数据. 我想知道如何检查(除了上面结合try-catch-statement之外)是否存在字段. 原因是当我执行QueryExpression时,我需要知道要在ColumnSet中包含哪些列. 现在的Q& D代码是这样的.private bool DoesFieldExist(String entityName, String fieldName) {try{RetrieveAttributeRequest req = new RetrieveAttributeRequest();req.EntityLogicalName = entityName;req.LogicalName = fieldName;Re...

c# – 共享程序集中的静态字段【代码】

如果共享程序集(在GAC中)具有静态字段,并且字段的值已更新,那么是否会反映在引用共享程序集的客户端应用程序中?或者客户端应用程序是否需要重建?解决方法:如果该字段表示为const:public const int Foo = 100;然后,您将需要重建所有客户端应用程序,因为该值将被烘焙到这些客户端. 如果它只是一个公共静态只读字段:public static readonly int Foo = 100;…那么你将不需要重建客户端.该值将在执行时从程序集中获取. (当然,客户端...

c# – Sitecore字段ID与字段名称相对应【代码】

我在“专业Sitecore开发”一书中读到了 – 约翰韦斯特说,最好的做法是在获取项目字段值时使用字段ID代替字段名称. 但是像sc:text,sc:link,sc:image等的sitecore控件有一个名为field的属性,它使用字段名称.所以,我现在很困惑是将整个项目更改为Field ID,还是将字段名称保留为与sitecore使用一致. 任何建议将不胜感激.解决方法:是的,Sitecore允许您使用名称和ID.此外,Sitecore允许您在同一模板中具有相同的字段名称,这可能会导致一...

c# – 在没有方法的类中是否需要私有字段?【代码】

我一直在使用ReSharper做一些清理C#代码库的工作.我一直在使用模型类中的私有字段以及公共属性.但是,我发现我可以简单地获取没有支持字段的属性并将它们转换为自动属性.这些是模型类;其中不存在影响对象中数据的方法.是否更好地使用自动属性? 编辑:包括“支持字段”的示例public class Gizmo {//this is what I call the "backing" field, only because it's "behind" the//publicly-accessible property and you access it thro...

从Json Serialize动态忽略c#字段

出于API目的,我需要根据收到的条件忽略某些字段.通常我可以使用[ScriptIgnore]属性来执行此操作. 但是如何动态忽略字段(基于某些条件)?解决方法:使用Newtonsoft.Json包中的JsonIgnore属性. 然后,如果您希望它是动态条件的,请参阅ShouldSerialize

C#表达式按键字段对通用查询进行排序【代码】

我有一个通用的方法,我想在其中排序IQueryable< T>通过其关键字段(假设只有一个是安全的).从而:void DoStuff<T>(...) {IQueryable<T> queryable = ... // givenPropertyInfo keyField = ... // givenvar sortedQueryable = queryable.OrderBy(<some expression here>);... }如何定义一个将返回T的keyField属性的Expression,以便它可以工作?解决方法:这并不太难,但您需要使用反射调用OrderBy,因为您不知道关键字段的类型.所以考虑...

c# – 静态字段/属性初始化【代码】

如果我有这样的类型:public struct Effect {public int Value { get; set; }public static int MinValue = Int32.MinValue; }MinValue只会初始化为ONCE,就像执行静态构造函数一样吗?或者我应该在静态构造函数中初始化MinValue? 这会对班级有什么不同吗?解决方法:它将被执行一次,但不完全像在静态构造函数中.关于何时执行类型初始化程序的规则是different when a type has a static constructor.请注意观察到的行为changed a bi...

C#构造函数使用私有/公共字段[复制]【代码】

参见英文答案 > OO Design – do you use public properties or private fields internally? 10个 class Student { private string firstName;public string FirstName{get{return firstName;}set{firstName = value; // Possible logical checks may be implemented here in the future}}public Student (firstName){this.firstName = firstName; // Option 1// OrFirstName = firstName; /...

c# – MVC3模型绑定 – 列表到隐藏字段【代码】

我有一个特殊的问题 – 我有一个带有List的ViewModel用于显示图像列表:public List<int> TrackerKeys { get; set; }这在页面的两个位置使用:@for (int i = 0; i < Model.TrackerKeys.Count(); i++) { @Html.GenerateImage(PageModes.Http, Model.TrackerKeys[i]) }并且@for (int i = 0; i < Model.TrackerKeys.Count(); i++) { @Html.HiddenFor(model => model.TrackerKeys[i]) }这是在表单中 – 当提交表单时,如果发生验证错误,...

c# – 字段’xxx’永远不会被赋值,并且将始终具有其默认值null【代码】

我的错误: 字段’StockManagement.LargeItems1.largeS’永远不会被赋值,并且将始终具有其默认值null我的代码:namespace StockManagement {class LargeItems1{private Stack<string> largeS;public LargeItems1(){Stack<string> largeS = new Stack<string>();}public void LargeItemsAdd(){string usersInput2, tempValue;int tempValueI = 0;bool attempt = false;//, whichOne = false;Console.WriteLine("Would you like to...

c# – 将公共只读字段用于不可变结构而不是私有字段/公共getter对【代码】

这是我第一次编写将用于广泛几何计算的小型不可变结构.我很想使用公共只读字段而不是私有字段/公共getter组合.public struct Vector4 {public readonly float Angle, Velocity;// As opposed to:private float _Angle, _Velocity;public float Angle { get { return (this._Angle); } }public float Velocity { get { return (this._Velocity); } }public Vector4 (float angle, float velocity){// Once set in the constructor, ...

c# – int字段的默认值是0吗?【代码】

我有一个控制台应用程序,其代码如下:using System;namespace HeadfirstPage210bill{class Program{static void Main(string[] args){CableBill myBill = new CableBill(4);Console.WriteLine(myBill.iGotChanged);Console.WriteLine(myBill.CalculateAmount(7).ToString("£##,#0.00"));Console.WriteLine("Press enter to exit");Console.WriteLine(myBill.iGotChanged);Console.Read();}}}CableBill.cs类如下:using System;nam...

c#中给出警告的结构字段永远不会分配给,并且始终具有默认值0【代码】

我有非常简单的结构如下:public struct ShFileInfo{public int hIcon;public int iIcon;public int dwAttributes;}我已将警告设为错误.现在为所有三个int获取错误Field is never assigned to,and will always have its default value 0显然,如果我尝试将int初始化为0,我将得到错误.有没有办法处理这个而不禁用警告为错误.解决方法:当我复制粘贴的作者代码时,我一直收到警告. 您可以像这样为Struct定义构造函数public struct ShFil...

FORMS - 相关标签