Skip to main content
deleted 5 characters in body; edited tags
Source Link
Tunaki
  • 9.3k
  • 1
  • 30
  • 46

I have a simple class which holds my product. Someone can add a serial to this product and also a purchaseidpurchase id. On change of the properties i, I want to check whether both properties are set, and get the license class and add it to the product.

That's the approach how I did itused. Is this a correct way how to do it.? How is this called and what is the best practice.? I need to use .NetNET Framework 3.5.

I have a simple class which holds my product. Someone can add a serial to this product and also a purchaseid. On change of the properties i want to check whether both properties are set and get the license class and add it to the product.

That's the approach how I did it. Is this a correct way how to do it. How is this called and what is best practice. I need to use .Net Framework 3.5.

I have a simple class which holds my product. Someone can add a serial to this product and also a purchase id. On change of the properties, I want to check whether both properties are set, and get the license class and add it to the product.

That's the approach I used. Is this a correct way to do it? How is this called and what is the best practice? I need to use .NET Framework 3.5.

deleted 17 characters in body; edited tags; edited title
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

How to execute Instantiating a method within only if multiple areproperty when the required attributes have been set properly?

Lets assume that weI have a simple class which holds my product. Someone can add a serial to this product and also a purchaseid. On change of the properties i want to check wetherwhether both properties are set and get the license class and add it to the product.

How to execute a method within only if multiple are set properly?

Lets assume that we have a simple class which holds my product. Someone can add a serial to this product and also a purchaseid. On change of the properties i want to check wether both properties are set and get the license class and add it to the product.

Instantiating a property when the required attributes have been set

I have a simple class which holds my product. Someone can add a serial to this product and also a purchaseid. On change of the properties i want to check whether both properties are set and get the license class and add it to the product.

deleted 620 characters in body
Source Link
STORM
  • 217
  • 1
  • 8

Lets assume that we have a simple class with multiplewhich holds my product. Someone can add a serial to this product and also a purchaseid. On change of the properties i want to check wether both properties are set and get the license class and add it to the product.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace classtest2
{
   public class ClassALicense
    {
    public bool IsTrial { privateget; AnotherClassBset; anotherClassb;}
     
    public AnotherClassBbool ClassBIsValid {
          get; set; get}
            {
      public string Type { get; set; }

    returnpublic anotherClassb;License()
        {

    } 

    public License(string purchaseId, string serial)
    set{
          this.IsTrial = {true;
                anotherClassbthis.IsValid = value;true;
          this.Type = }"Enterprise";
        }
 
  

Example License class

public class Product
{
    private int?License id1;_license;
        public int? Id1License {license
    {
        get
            {
                return id1;_license;
            }
            set
            {
                id1_license = value;
        }
    } 

    public string Name { get; set; }

        private int?string id2;_purchaseId;
        public int?string Id2PurchaseId {
            get
            {
                return id2;_purchaseId;
            }
            set
            {
                id2_purchaseId = value;
                CreateAnotherClassBGetLicense();
            }
        }

        private voidstring CreateAnotherClassB()_serial;
      public string {Serial
       {
     if (this.Id1 != null && this.Id2 != null)get
            { 
                Console.WriteLine("CreateAnotherClassBreturn ctor");_serial;
                AnotherClassB a = new AnotherClassB(Convert.ToInt32(this.Id1), Convert.ToInt32(this.Id2));}
                this.ClassB = a;set
            }{
        }
    }
}

then lets say i have a second class

using System;
using System.Collections.Generic;
using_serial System.Linq;
using= System.Text;value;
using System.Threading.Tasks;

namespace classtest2
{
    public class AnotherClassB
    {GetLicense();
        public string s1 { get; set; }
        public int i1 { get; set; }

       private publicvoid AnotherClassBGetLicense()
        {
           if Console(!string.WriteLineIsNullOrEmpty("AnotherClassB ctor"this.Serial);
        }

        public&& AnotherClassB!string.IsNullOrEmpty(int id1, int id2this.PurchaseId))
        {
            Console.WriteLine("AnotherClassB(..) ctor");
            this.i1License lice = id1new +License(serial, id2;PurchaseId);
            this.s1License = id1.ToString() + ", " + id2.ToString();lice;
        }
    }
}

The second class is also a property of ClassA. I want to automatically create this second class when multiple properties of ClassA getting set.

Lets assume that we have a simple class with multiple properties

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace classtest2
{
    class ClassA
    {
        private AnotherClassB anotherClassb;
        public AnotherClassB ClassB {
            get
            {
                return anotherClassb;
            }
            set
            {
                anotherClassb = value;
            }
        }
 
        private int? id1;
        public int? Id1 {
            get
            {
                return id1;
            }
            set
            {
                id1 = value;
            }
        }

        private int? id2;
        public int? Id2 {
            get
            {
                return id2;
            }
            set
            {
                id2 = value;
                CreateAnotherClassB();
            }
        }

        private void CreateAnotherClassB()
        {
            if (this.Id1 != null && this.Id2 != null)
            { 
                Console.WriteLine("CreateAnotherClassB ctor");
                AnotherClassB a = new AnotherClassB(Convert.ToInt32(this.Id1), Convert.ToInt32(this.Id2));
                this.ClassB = a;
            }
        }
    }
}

then lets say i have a second class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace classtest2
{
    public class AnotherClassB
    {
        public string s1 { get; set; }
        public int i1 { get; set; }

        public AnotherClassB()
        {
            Console.WriteLine("AnotherClassB ctor");
        }

        public AnotherClassB(int id1, int id2)
        {
            Console.WriteLine("AnotherClassB(..) ctor");
            this.i1 = id1 + id2;
            this.s1 = id1.ToString() + ", " + id2.ToString();
        }
    }
}

The second class is also a property of ClassA. I want to automatically create this second class when multiple properties of ClassA getting set.

Lets assume that we have a simple class which holds my product. Someone can add a serial to this product and also a purchaseid. On change of the properties i want to check wether both properties are set and get the license class and add it to the product.

public class License
{
    public bool IsTrial { get; set; }
 
    public bool IsValid { get; set; }

    public string Type { get; set; }

    public License()
    {

    } 

    public License(string purchaseId, string serial)
    {
        this.IsTrial = true;
        this.IsValid = true;
        this.Type = "Enterprise";
    }

Example License class

public class Product
{
    private License _license;
    public License license
    {
        get
        {
            return _license;
        }
        set
        {
            _license = value;
        }
    } 

    public string Name { get; set; }

    private string _purchaseId;
    public string PurchaseId {
        get
        {
            return _purchaseId;
        }
        set
        {
            _purchaseId = value;
            GetLicense();
        }
    }

    private string _serial;
    public string Serial
    {
        get
        {
            return _serial;
        }
        set
        {
            _serial = value;
            GetLicense();
        }
    }

    private void GetLicense()
    {
        if (!string.IsNullOrEmpty(this.Serial) && !string.IsNullOrEmpty(this.PurchaseId))
        { 
            License lice = new License(serial, PurchaseId);
            this.License = lice;
        }
    }
added 1 character in body
Source Link
Pimgd
  • 22.3k
  • 5
  • 66
  • 144
Loading
Source Link
STORM
  • 217
  • 1
  • 8
Loading