Questions tagged [automatic-properties]

219 questions
2
votes
1 answer

Fluent NHibernate PropertyNotFoundException for Auto Property

I'm trying to get Fluent NHibernate to map a collection for me. My class definitions are as follows: public abstract class Team { public virtual Guid Id { get; set; } public virtual string Name { get; set; } } public class ClientTeam :…
Matt Mills
  • 8,692
  • 6
  • 40
  • 64
2
votes
1 answer

When is an automatic property initialised?

If I have this object, which has a child object as an automatic property: public class ParentObject { public ChildObject Child { get; set; } = new ChildObject(); } At what point is the Child initialised? During construction of the ParentObject,…
PaulG
  • 13,871
  • 9
  • 56
  • 78
2
votes
2 answers

VB.net automatic properties with different access level for set

In c# you can auto property a value with different level of access for the get and set . . . e.g. public String myString { get; private set; } Is there away to do that with automatic properties in vb.net or are you forced to go for the long…
Dustin Hodges
  • 4,110
  • 3
  • 26
  • 41
2
votes
1 answer

Explicit Override Using Automatic Property

I'm trying to use a C++/CLI auto-implemented property to explicitly override an interface. In particular, I have written (in C++/CLI) interface IInterface { property Object ^MyProperty { Object ^get(void); void…
2
votes
1 answer

In CSS, how to create automatic section numbering only when there are multiple sections?

In CSS, how to create automatic section numbering only when there are multiple sections? I learned that one can create automatica numbering in front of sections by using CSS body { counter-reset: section } h2 { counter-reset: sub-section } h3 {…
qazwsx
  • 25,536
  • 30
  • 72
  • 106
2
votes
1 answer

No automatic underscore ivar in Xcode 5.1.1

I just noticed that, for some reason, I don't seem to have automatically created underscore iVars in my iOS 7 project, and I wonder why that is. My setup: MyClass.h @property (readonly) NSNumber *aNumber; MyClass.m @interface MyClass () @property…
BlackWolf
  • 5,239
  • 5
  • 33
  • 60
2
votes
2 answers

Auto Property that returns an interface

This is something curious that I saw in my coding today. Here is the sample code: public class SomeClass { public IUtils UtilitiesProperty { get; set; } } public interface IUtils { void DoSomething(); } public class Utils : IUtils { void…
Vaccano
  • 78,325
  • 149
  • 468
  • 850
2
votes
4 answers

Is the implementation of Auto Properties in the spec?

Can I rely on the fact that the underlying field to a property named Foo is called "k__BackingField" ?
ripper234
  • 222,824
  • 274
  • 634
  • 905
2
votes
6 answers

Is this the correct syntax for auto properties?

I've been programming for so long its hard to keep up with language changes sometimes... Is it really ok to set properties like this after .net v2 public string LocaleName { get; set; } Not requiring an inner field?…
JL.
  • 78,954
  • 126
  • 311
  • 459
2
votes
2 answers

Objective-C multiple declarations of instance variables / properties

I'm still pretty new to ObjC. I noticed that it's pretty standard everywhere to create your @interface myObj : NSObject { id delegate; NSDictionary *dict; } and then @property (nonatomic,retain) NSDictionary *dict; @property (retain) id…
Authman Apatira
  • 3,994
  • 1
  • 26
  • 33
2
votes
4 answers

Struct with auto-implemented properties and constructor initializer

Recently a compiler warning and (very useful) hint prompted me to write the code below. I had no idea you could do this, but it is perfectly legal, and also convenient in that I can declare a managed struct with public properties similar to public…
Jerome Viveiros
  • 241
  • 3
  • 14
1
vote
3 answers

Anyone tried implement C#.Auto-Property which would store value in Session?

I like using c# Auto-Property in code as I found it much more nicer. Recently got an idea how I would manage to use Auto-Property, but store the value in Session. Simply for few reason: - avoid typos in Session item name - avoid extra code -…
Jaroslav Urban
  • 1,269
  • 3
  • 20
  • 32
1
vote
3 answers

Can I define a custom getter for a C# auto-implemented property (a.k.a. auto backing field)?

Note: I know how to accomplish this without using auto-implemented properties, but I'm wondering if C# has a built-in way to do this. Let's say I have this simple example of an auto-implemented property (a.k.a. auto backing field): public class…
1
vote
4 answers

Can I create an automatic property (no private member) with get and set code?

In c#, I can do this: public int Foo { get; set; } Which is nice. But as soon as I want to do anything in the getter or setter, I have to change it to this: private int foo; public int Foo { get { return foo; } set { foo = value; …
Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
1
vote
1 answer

Will use 'k_BackingField' cause version compatibility problem?

Recently, I'm working on serialization with C#. I found that the automatic-properties' fields are named "<...>k_BackingField". So my problem is dose this naming rule same in all .Net versions, and it won't change in any situations?