草庐IT

Q_PROPERTY

全部标签

ios - Swift 编程 : getter/setter in stored property

如何在Swift中覆盖存储属性的setter?在Obj-C中,我可以覆盖它的setter,但Swift似乎不喜欢将getter/setter用于存储属性。假设我有一个Card类,它有一个名为rank的属性。我不希望客户端给它任何无效值,因此,在Objective-C中,我可以覆盖setRank以便它执行额外的检查。但是Swift中的willSet似乎没有帮助,因为newValue是常量并且分配rank没有意义,因为setter将在循环。 最佳答案 好的。阅读有关Swift的Apple文档,我发现this:Ifyouassignava

ios - Swift 编程 : getter/setter in stored property

如何在Swift中覆盖存储属性的setter?在Obj-C中,我可以覆盖它的setter,但Swift似乎不喜欢将getter/setter用于存储属性。假设我有一个Card类,它有一个名为rank的属性。我不希望客户端给它任何无效值,因此,在Objective-C中,我可以覆盖setRank以便它执行额外的检查。但是Swift中的willSet似乎没有帮助,因为newValue是常量并且分配rank没有意义,因为setter将在循环。 最佳答案 好的。阅读有关Swift的Apple文档,我发现this:Ifyouassignava

properties - Swift 类 : Property not initialized at super. init 调用出错

我有两个类,Shape和SquareclassShape{varnumberOfSides=0varname:Stringinit(name:String){self.name=name}funcsimpleDescription()->String{return"Ashapewith\(numberOfSides)sides."}}classSquare:Shape{varsideLength:Doubleinit(sideLength:Double,name:String){super.init(name:name)//Errorhereself.sideLength=sideLe

properties - Swift 类 : Property not initialized at super. init 调用出错

我有两个类,Shape和SquareclassShape{varnumberOfSides=0varname:Stringinit(name:String){self.name=name}funcsimpleDescription()->String{return"Ashapewith\(numberOfSides)sides."}}classSquare:Shape{varsideLength:Doubleinit(sideLength:Double,name:String){super.init(name:name)//Errorhereself.sideLength=sideLe

c# - property.GetValue() 中的参数计数不匹配

这个问题在这里已经有了答案:ParameterCountMismatchexceptionwhencallingPropertyInfo.GetValue(3个答案)关闭7年前。我得到了parametercountmismatch错误。它出现在if子句中。我的代码:privateDictionaryObjectToDict(Dictionarydict,objectobj){varproperties=obj.GetType().GetProperties();foreach(varpropertyinproperties){if(property.GetValue(obj,null)

c# - property.GetValue() 中的参数计数不匹配

这个问题在这里已经有了答案:ParameterCountMismatchexceptionwhencallingPropertyInfo.GetValue(3个答案)关闭7年前。我得到了parametercountmismatch错误。它出现在if子句中。我的代码:privateDictionaryObjectToDict(Dictionarydict,objectobj){varproperties=obj.GetType().GetProperties();foreach(varpropertyinproperties){if(property.GetValue(obj,null)

c# - C# : "An object reference is required for the non-static field, method, or property" 错误

我在WPF中编写代码。首先,我编写了一个单独的项目来测试COMport的工作。设备,并且运行良好。接下来我决定将它集成到另一个项目中,但我得到了一个错误。我没有更改代码;我只是将它复制到一个新的代码文件中。此代码运行良好:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usi

c# - C# : "An object reference is required for the non-static field, method, or property" 错误

我在WPF中编写代码。首先,我编写了一个单独的项目来测试COMport的工作。设备,并且运行良好。接下来我决定将它集成到另一个项目中,但我得到了一个错误。我没有更改代码;我只是将它复制到一个新的代码文件中。此代码运行良好:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usi

c# - ReSharper 7.1 "To Property with Backing Field"将字段移出位置

我最近升级到R#7.1,我遇到了这个问题,其中ToPropertyWithBackingFieldaction取代了我的支持字段并将它们移到类的顶部。例子:第1步:定义一个自动属性:publicclassMyClass{//...LotsofmembersherepublicintMyNewProperty{get;set;}//第2步:ReSharper的“ToPropertyWithBackingField”预期结果:publicclassMyClass{//...Lotsofmembershereprivateint_myNewProperty;//得到的结果:publiccla

c# - ReSharper 7.1 "To Property with Backing Field"将字段移出位置

我最近升级到R#7.1,我遇到了这个问题,其中ToPropertyWithBackingFieldaction取代了我的支持字段并将它们移到类的顶部。例子:第1步:定义一个自动属性:publicclassMyClass{//...LotsofmembersherepublicintMyNewProperty{get;set;}//第2步:ReSharper的“ToPropertyWithBackingField”预期结果:publicclassMyClass{//...Lotsofmembershereprivateint_myNewProperty;//得到的结果:publiccla