Search code examples
c#csla

How do I retrieve a CSLA property's friendly name from outside the class?


The property looks like this:

private static PropertyInfo<bool> FooProperty=
        RegisterProperty<bool>(c => c.Foo, "Foo Friendly Name");
public bool Foo
{
    get { return GetProperty(FooProperty); }
    private set { SetProperty(FooProperty, value); }
}

I would like to recieve "Foo Friendly Name" from outside the class.


Solution

  • Loosen the access on your static FooProperty:

    //access FooProperty from inside the assembly where it is defined
    internal static PropertyInfo<bool> FooProperty=
        RegisterProperty<bool>(c => c.Foo, "Foo Friendly Name");
    

    or

    //access FooProperty from anywhere
    public static PropertyInfo<bool> FooProperty=
        RegisterProperty<bool>(c => c.Foo, "Foo Friendly Name");
    

    Then access it from outside its class:

    string fooName = FooClass.FooProperty.Name;