Recommended way of declaring an managed property of type Int16 with a default value?

Recommended way of declaring an managed property of type Int16 with a default value?

Old forum URL: forums.lhotka.net/forums/t/10761.aspx


stefan posted on Tuesday, October 11, 2011

When declaring such a property in a BusinessBase derived class, it is not possible to resolve the right method signature, because the default value is of the same type as the RelationshipTypes enum.

public static readonly PropertyInfo<Int16> MyInt16Property = RegisterProperty<Int16>(p => p.MyInt16PropName, "friendly name", 1);

If there was something like RelationshipTypes.Default, we could do:

public static readonly PropertyInfo<Int16> MyInt16Property = RegisterProperty<Int16>(p => p.MyInt16PropName, "friendly name", 1, elationshipTypes.Default;

What is the current recommended solution?

I use csla 3.8.x

Sorry for the formatting...

RockfordLhotka replied on Tuesday, October 11, 2011

At least in CSLA 4, this code works as expected:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      var obj = Csla.DataPortal.Create<TestClass>();
      Console.WriteLine(obj.Test);
      Console.ReadLine();
    }

  }

  [Serializable]
  public class TestClassBusinessBase<TestClass>
  {
    public static readonly PropertyInfo<Int16> TestProperty = RegisterProperty<Int16>(c => c.Test, "Test", 123);
    public Int16 Test
    {
      get { return GetProperty(TestProperty); }
      set { SetProperty(TestProperty, value); }
    }

  }
}

stefan replied on Tuesday, October 11, 2011

OK,  the issue comes up only for a default value of 0...

But as that is the internal default for numeric types...

it's a no-brainer then.

Thanks!

RockfordLhotka replied on Tuesday, October 11, 2011

What I'm saying, is that I ran the code from my previous post, and the value is 123.

Copyright (c) Marimer LLC