[AllowNull] Boolean/int

Jan 7, 2009 at 2:51 AM
if [AllowNull] attribute add to bool or int, there will be an exception


private static void Set2ndArgForGetNullable(MemberHandler f, ILBuilder il)
        {
            if (f.MemberInfo.MemberType.IsValueType && f.MemberInfo.MemberType.GetGenericArguments()[0] == typeof(Guid))
/////Index was outside the bounds of the array.
            {
                il.LoadInt(1);
            }
            else if (f.MemberInfo.MemberType.IsValueType && f.MemberInfo.MemberType.GetGenericArguments()[0] == typeof(bool))
            {
                il.LoadInt(2);
            }
            else
            {
                il.LoadInt(0);
            }
        }
Jan 7, 2009 at 2:53 AM

 public class ToolbarSchema : IDbObject
    {
        [DbKey(IsDbGenerate = false)]
        public int ApplicationID;

        [Length(1)]
        [AllowNull]
        public string ButtonStyle;

        [Length(32)]
        [AllowNull]
        public string Caption;

        [AllowNull]
        public bool Checked;

        [Length(255)]
        [AllowNull]
        public string Comment;

        [AllowNull]
        public bool FollowSeperated;

        [DbKey(IsDbGenerate = false)]
        public int ID;

        [Length(32)]
        public string Name;

        [AllowNull]
        public int ParentID;

        [Length(500)]
        [AllowNull]
        public string Picture;

        public int ToolbarLevel;

        [Length(10)]
        [AllowNull]
        public string Type;

    }

Jan 7, 2009 at 3:13 AM
Edited Jan 7, 2009 at 3:14 AM
modify to this is right,
f.MemberInfo.MemberType.IsValueType && f.MemberInfo.MemberType ==


but if modify ,there still an error:

public void LoadSimpleValues(object o, bool UseIndex, IDataReader dr)
        {
            if (UseIndex)
            {
                LoadSimpleValuesByIndex(o, dr);//System.NullReferenceException
            }
            else
            {
                LoadSimpleValuesByName(o, dr);
            }
        }

--------------------------------------
I don't know why, I don't know what is il.LoadInt...
Jan 7, 2009 at 3:45 AM
OK ,i Fixit

I make it wrong

  public class ToolbarSchema : IDbObject
    {
        [DbKey(IsDbGenerate = false)]
        public int ApplicationID;

        [Length(1)]
        [AllowNull]
        public string ButtonStyle;

       
        [Length(32)]
        [AllowNull]
        public string Caption;

        public bool? Checked;

        [Length(255)]
        [AllowNull]
        public string Comment;

        public bool? FollowSeperated;

        [DbKey(IsDbGenerate = false)]
        public int? ID;

        [Length(32)]
        public string Name;

        public int? ParentID;

        [Length(500)]
        [AllowNull]
        public string Picture;

        public short ToolbarLevel;

        [Length(10)]
        [AllowNull]
        public string Type;

    }


我犯了好几个错误,一个是int? bool? 还有一个short写成int了。

Coordinator
Jan 7, 2009 at 4:24 AM
Maybe I should throw the readable exception for this situation...