Exemple #1
0
        public void Inventorize(Type t, ConfigSectionNode root)
        {
            InventorizationManager.WriteInventoryAttributes(
                t.GetCustomAttributes(typeof(InventoryAttribute), false).Cast <InventoryAttribute>(),
                root.AddChildNode(InventorizationManager.ATTRIBUTES_NODE));

            if (t.BaseType != null)
            {
                root.AddAttributeNode("base", t.BaseType.FullName);
            }

            root.AddAttributeNode("abstract", t.IsAbstract);
            root.AddAttributeNode("class", t.IsClass);
            root.AddAttributeNode("enum", t.IsEnum);
            root.AddAttributeNode("intf", t.IsInterface);
            root.AddAttributeNode("nested", t.IsNested);
            root.AddAttributeNode("public", t.IsPublic);
            root.AddAttributeNode("sealed", t.IsSealed);
            root.AddAttributeNode("serializable", t.IsSerializable);
            root.AddAttributeNode("valuetype", t.IsValueType);
            root.AddAttributeNode("visible", t.IsVisible);

            var members = t.GetMembers().Where(m => m.GetCustomAttributes(typeof(InventoryAttribute), false).Count() > 0);

            foreach (var mem in members)
            {
                var mnode = root.AddChildNode("member");
                mnode.AddAttributeNode("name", mem.Name);
                mnode.AddAttributeNode("kind", mem.MemberType.ToString());

                InventorizationManager.WriteInventoryAttributes(
                    mem.GetCustomAttributes(typeof(InventoryAttribute), false).Cast <InventoryAttribute>(),
                    mnode.AddChildNode(InventorizationManager.ATTRIBUTES_NODE));

                if (mem is PropertyInfo)
                {
                    var pinf = (PropertyInfo)mem;
                    mnode.AddAttributeNode("can-get", pinf.CanRead);
                    mnode.AddAttributeNode("can-set", pinf.CanWrite);
                    mnode.AddAttributeNode("type", pinf.PropertyType.FullName);
                }
                else
                if (mem is FieldInfo)
                {
                    var finf = (FieldInfo)mem;
                    mnode.AddAttributeNode("not-serialized", finf.IsNotSerialized);
                    mnode.AddAttributeNode("public", finf.IsPublic);
                    mnode.AddAttributeNode("private", finf.IsPrivate);
                    mnode.AddAttributeNode("static", finf.IsStatic);
                    mnode.AddAttributeNode("type", finf.FieldType.FullName);
                }
                else
                if (mem is MethodInfo)
                {
                    var minf = (MethodInfo)mem;
                    mnode.AddAttributeNode("virtual", minf.IsVirtual);
                    mnode.AddAttributeNode("public", minf.IsPublic);
                    mnode.AddAttributeNode("private", minf.IsPrivate);
                    mnode.AddAttributeNode("static", minf.IsStatic);
                    if (minf.ReturnType != null)
                    {
                        mnode.AddAttributeNode("return-type", minf.ReturnType.FullName);
                    }
                }
            }
        }
        public void Inventorize(Type t, Environment.ConfigSectionNode root)
        {
            if (!typeof(Record).IsAssignableFrom(t))
            {
                return;
            }


            if (t.IsAbstract)
            {
                return;
            }
            if (t.ContainsGenericParameters)
            {
                return;
            }

            var rec = Record.Make(t);

            var rnode = root.AddChildNode("record-model");

            rnode.AddAttributeNode("clr-type-ns", t.Namespace);
            rnode.AddAttributeNode("clr-type", t.Name);
            rnode.AddAttributeNode("clr-type-full", t.FullName);
            rnode.AddAttributeNode("table", rec.TableName);
            rnode.AddAttributeNode("store-flag", rec.StoreFlag.ToString());
            rnode.AddAttributeNode("case-sensitive", rec.CaseSensitiveFieldBinding);
            rnode.AddAttributeNode("permission", rec.PermissionName);
            rnode.AddAttributeNode("permission-namespace", rec.PermissionNamespace);
            rnode.AddAttributeNode("throw-init-validation", rec.ThrowOnInitValidation);
            rnode.AddAttributeNode("visible", rec.Visible);

            foreach (var f in rec.Fields)
            {
                var fnode = rnode.AddChildNode("field");

                fnode.AddAttributeNode("name", f.FieldName);
                fnode.AddAttributeNode("type", f.GetFieldDataType().FullName);
                fnode.AddAttributeNode("calc-override", f.AllowCalculationOverride);
                fnode.AddAttributeNode("calculated", f.Calculated);
                fnode.AddAttributeNode("entry-type", f.DataEntryType.ToString());
                fnode.AddAttributeNode("description", f.Description);
                fnode.AddAttributeNode("display-format", f.DisplayFormat);
                fnode.AddAttributeNode("display-h-align", f.DisplayTextHAlignment.ToString());
                fnode.AddAttributeNode("display-width", f.DisplayWidth);
                fnode.AddAttributeNode("has-default-value", f.HasDefaultValue);
                fnode.AddAttributeNode("hint", f.Hint);
                fnode.AddAttributeNode("keep-in-errored-field", f.KeepInErroredField);
                fnode.AddAttributeNode("key", f.KeyField);
                fnode.AddAttributeNode("order", f.LogicalOrder);
                fnode.AddAttributeNode("lookup-type", f.LookupType);

                InventorizationManager.WriteType(f.GetFieldDataType(), fnode.AddChildNode("data-type"));

                if (f.LookupDictionary.Count > 0)
                {
                    var dnode = fnode.AddChildNode("lookup-dictionary");
                    foreach (var key in f.LookupDictionary.Keys)
                    {
                        var inode = dnode.AddChildNode("item");
                        inode.AddAttributeNode("key", key);
                        inode.AddAttributeNode("value", f.LookupDictionary[key]);
                    }
                }


                fnode.AddAttributeNode("permission", f.PermissionName);
                fnode.AddAttributeNode("permission-namespace", f.PermissionNamespace);
                fnode.AddAttributeNode("readonly", f.Readonly);
                fnode.AddAttributeNode("required", f.Required);
                fnode.AddAttributeNode("store-flag", f.StoreFlag.ToString());
                fnode.AddAttributeNode("throw-init-validation", f.ThrowOnInitValidation);
                fnode.AddAttributeNode("visible", f.Visible);


                if (f is StringField)
                {
                    var sf = (StringField)f;
                    fnode.AddAttributeNode("size", sf.Size);
                    fnode.AddAttributeNode("char-case", sf.CharCase.ToString());
                    fnode.AddAttributeNode("password", sf.Password);
                    fnode.AddAttributeNode("regexp", sf.FormatRegExp);
                    fnode.AddAttributeNode("regexp-description", sf.FormatRegExpDescription);
                }
                else
                if (f is IntField)
                {
                    var castf = (IntField)f;
                    fnode.AddAttributeNode("min-max-check", castf.MinMaxChecking);
                    fnode.AddAttributeNode("min-value", castf.MinValue);
                    fnode.AddAttributeNode("max-value", castf.MaxValue);
                    fnode.AddAttributeNode("default-value", castf.DefaultValue);
                }
                else
                if (f is LongField)
                {
                    var castf = (LongField)f;
                    fnode.AddAttributeNode("min-max-check", castf.MinMaxChecking);
                    fnode.AddAttributeNode("min-value", castf.MinValue);
                    fnode.AddAttributeNode("max-value", castf.MaxValue);
                    fnode.AddAttributeNode("default-value", castf.DefaultValue);
                }
                else
                if (f is ShortField)
                {
                    var castf = (ShortField)f;
                    fnode.AddAttributeNode("min-max-check", castf.MinMaxChecking);
                    fnode.AddAttributeNode("min-value", castf.MinValue);
                    fnode.AddAttributeNode("max-value", castf.MaxValue);
                    fnode.AddAttributeNode("default-value", castf.DefaultValue);
                }
                else
                if (f is FloatField)
                {
                    var castf = (FloatField)f;
                    fnode.AddAttributeNode("min-max-check", castf.MinMaxChecking);
                    fnode.AddAttributeNode("min-value", castf.MinValue);
                    fnode.AddAttributeNode("max-value", castf.MaxValue);
                    fnode.AddAttributeNode("default-value", castf.DefaultValue);
                }
                else
                if (f is DoubleField)
                {
                    var castf = (DoubleField)f;
                    fnode.AddAttributeNode("min-max-check", castf.MinMaxChecking);
                    fnode.AddAttributeNode("min-value", castf.MinValue);
                    fnode.AddAttributeNode("max-value", castf.MaxValue);
                    fnode.AddAttributeNode("default-value", castf.DefaultValue);
                }
                else
                if (f is DecimalField)
                {
                    var castf = (DecimalField)f;
                    fnode.AddAttributeNode("min-max-check", castf.MinMaxChecking);
                    fnode.AddAttributeNode("min-value", castf.MinValue);
                    fnode.AddAttributeNode("max-value", castf.MaxValue);
                    fnode.AddAttributeNode("default-value", castf.DefaultValue);
                }
            }
        }