Optional property c#
-
I want to create a class that has an optional property. I don't want to create a subclass
Example
public class MyClass
{
public MyClass( int extraPoperty)
{
// Something like this
public int ExtraPoperty { get; set; }} public int EntityId { get; set; } }
Is this possible ?
-
I want to create a class that has an optional property. I don't want to create a subclass
Example
public class MyClass
{
public MyClass( int extraPoperty)
{
// Something like this
public int ExtraPoperty { get; set; }} public int EntityId { get; set; } }
Is this possible ?
No - you can't define a property within a method or constructor, only within the class body. What exactly are you trying to do? Why do you think you need this?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
I want to create a class that has an optional property. I don't want to create a subclass
Example
public class MyClass
{
public MyClass( int extraPoperty)
{
// Something like this
public int ExtraPoperty { get; set; }} public int EntityId { get; set; } }
Is this possible ?
-
I want to create a class that has an optional property. I don't want to create a subclass
Example
public class MyClass
{
public MyClass( int extraPoperty)
{
// Something like this
public int ExtraPoperty { get; set; }} public int EntityId { get; set; } }
Is this possible ?
I would suggest that what you are asking about is going to violate the S in SOLID.
This space for rent
-
I want to create a class that has an optional property. I don't want to create a subclass
Example
public class MyClass
{
public MyClass( int extraPoperty)
{
// Something like this
public int ExtraPoperty { get; set; }} public int EntityId { get; set; } }
Is this possible ?
It depends on what you mean with "optional Property". Do you mean something like this : You have a Property "BorderStyle" and a Property "BorderSize". If you select BoderStyle = None then you want that BorderSize isn't to be seen (invisible).
-
I want to create a class that has an optional property. I don't want to create a subclass
Example
public class MyClass
{
public MyClass( int extraPoperty)
{
// Something like this
public int ExtraPoperty { get; set; }} public int EntityId { get; set; } }
Is this possible ?
Check out the "ExpandoObject". [ExpandoObject Class (System.Dynamic)](https://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject(v=vs.110).aspx) (Always makes me think of "Plastic Man" for some reason).
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
-
Check out the "ExpandoObject". [ExpandoObject Class (System.Dynamic)](https://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject(v=vs.110).aspx) (Always makes me think of "Plastic Man" for some reason).
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
5 :thumbsup:
-
I want to create a class that has an optional property. I don't want to create a subclass
Example
public class MyClass
{
public MyClass( int extraPoperty)
{
// Something like this
public int ExtraPoperty { get; set; }} public int EntityId { get; set; } }
Is this possible ?
I would add the optional property in an Interface. Then you inherit the Interface you want to apply optional methods or properties. For example;
public interface IExtraProperty
{
// Something like this
public int ExtraPoperty { get; set; }
}public class MyClass : IExtraProperty
Ben Scharbach Temporalwars.Com YouTube:Ben Scharbach