Error: 'Csla.Utilities' is inaccessible due to its protection level

Error: 'Csla.Utilities' is inaccessible due to its protection level

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


redgoblin83 posted on Tuesday, May 09, 2006

Where do I have to create my own Validation rules. I made a copy of the StringMaxLenght but now it is StringMinLenght, p 275 of book, and added it into my Object. As a Class.

public class MinLenghtRuleArgs : RuleArgs

{

private int _minLenght;

public int MinLenght

{

get { return _minLenght; }

}

public MinLenghtRuleArgs(string propertyName, int minLenght)

: base(propertyName)

{

_minLenght = minLenght;

}

public override string ToString()

{

return base.ToString() + "!" + _minLenght.ToString();

}

}

public static bool StringMinLenght(object target, RuleArgs e)

{

int min = ((MinLenghtRuleArgs)e).MinLenght;

string value = (string)Utilities.CallByName(target, e.PropertyName, CallType.Get);

if (!String.IsNullOrEmpty(value) && (value.Length < min))

{

e.Description = string.Format("{0} can not be les then {1} characters", e.PropertyName, min.ToString());

return false;

}

return true;

}

What do I have to do ?

RockfordLhotka replied on Tuesday, May 09, 2006

The Utilities.CallByName() method is internal/Friend in scope. It probably could be public, but I was very conservative in terms of which parts of the framework I made public. To some degree this was to reduce the surface area for testing - this method is supposed to provide C# with a match for the capabilities of CallByName() in VB. But it is used in a limited capacity in CSLA, and so I only tested the parts that I needed - it may or may not actually do everything the VB method does.

That was my reasoning. Still, I am considering making CallByName(), along with other methods in Utilities and MethodCaller, public in the next release of the framework. There are cases (like yours) where having access to these methods would be useful.

In the meantime, you can look at CallByName - it isn't that complex, and merely wraps some use of reflection. You can copy it into your project, or use reflection in a more direct way as you choose.

Copyright (c) Marimer LLC