A suggestion

Mar 20, 2010 at 6:39 PM

Hi Daniel,

This package has potential because it is such a simple tool and would make it really easy to set up membership on a site.

I have a little refactoring suggestion. I couldn't get your control to work, so I had to tinker a little. It is the GetPopulatedEditor method, that can be greatly reduced, and you can get rid of that long switch statement, which seems to have a few bugs.

 

private Control GetPopulatedEditor(Property property, MemberType _currentMemberType)
        {
            if (_currentMemberType.MemberCanEdit(property.PropertyType))
            {
                umbraco.interfaces.IDataType df = property.PropertyType.DataTypeDefinition.DataType;
                df.DataEditor.Editor.ID = string.Format("editor{0}", property.PropertyType.Alias);
                ((Control)df.DataEditor.Editor).ID = string.Format("editor{0}", property.PropertyType.Alias);
                df.Data.PropertyId = property.Id;
                if (!IsPostBack)
                    df.Data.Value = property.Value;

                return df.DataEditor.Editor;
            }

            return null;
       }

Just use the interface instead, and set the data value on the IDataType interface. Much shorter and cleaner, and should work for all controls, even the ones you haven't included, such as File Upload. Anyways... just a suggestion, but use it if it makes sense.

 

private Control GetPopulatedEditor(Property property, MemberType _currentMemberType)
        {
            if (_currentMemberType.MemberCanEdit(property.PropertyType))
            {
                umbraco.interfaces.IDataType df = property.PropertyType.DataTypeDefinition.DataType;
                df.DataEditor.Editor.ID = string.Format("editor{0}", property.PropertyType.Alias);
                ((Control)df.DataEditor.Editor).ID = string.Format("editor{0}", property.PropertyType.Alias);
                df.Data.PropertyId = property.Id;
                if (!IsPostBack)
                    df.Data.Value = property.Value;
                return df.DataEditor.Editor;
            }
            return null;
        }

Keep up the good work, and I hope to see the final version soon.

/RasB