All pastes #715769 Raw Edit

Stuff

public text v1 · immutable
#715769 ·published 2007-09-26 13:37 UTC
rendered paste body
// This is in a switch, checking to see if you want to create a:
// 1 - Admin, 2 - Staff, 3 - Student
       newUsr = AutoPrompt.Create<Users.Admin>();


//   Yeah, dunno...
        public static datatype Create<datatype>() where datatype : new()
        {
            datatype dt = new datatype();
            CreateWorker<datatype>(ref dt, typeof(datatype));

            return dt;
        }

// Bam, wtf does this do?

        private static void CreateWorker<datatype>(ref datatype obj, Type t)
        {
            if (t == typeof(object))
                return;

            CreateWorker<datatype>(ref obj, t.BaseType);
            foreach (MemberInfo mi in t.GetMembers(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (mi.MemberType == MemberTypes.Field)
                {
                    AutoPrompt ap = Attribute.GetCustomAttribute(mi, typeof(AutoPrompt)) as AutoPrompt;
                    if (ap == null)
                        continue;

                    FieldInfo fi = mi as FieldInfo;
                    string fieldPrompt = ap.PromptText;