Exemplo n.º 1
0
 public void CreateFigureKeyAttribute(FieldBuilder field, FigureKeyAttribute attrib)
 {
     field.SetCustomAttribute(new CustomAttributeBuilder(figureKeyCtor, Type.EmptyTypes,
                                                         new FieldInfo[] { typeof(FigureKeyAttribute).GetField("Order"),
                                                                           typeof(FigureKeyAttribute).GetField("IsAutoincrement") },
                                                         new object[] { attrib.Order, attrib.IsAutoincrement }));
 }
Exemplo n.º 2
0
        private void resolveFigureKeyAttributes(FieldBuilder fb, MemberInfo mi, MemberRubric mr)
        {
            object[] o = mi.GetCustomAttributes(typeof(FigureKeyAttribute), false);
            if (o != null && o.Any())
            {
                FigureKeyAttribute fka = (FigureKeyAttribute)o.First();
                mr.IsKey           = true;
                mr.IsIdentity      = true;
                mr.IsAutoincrement = fka.IsAutoincrement;

                if (Identities.ContainsKey(fka.Order))
                {
                    fka.Order = (short)(Identities.LastOrDefault().Key + 1);
                }

                mr.IdentityOrder = fka.Order;
                Identities.Add(mr.IdentityOrder, mr);
                mr.Required = true;

                if (fb != null)
                {
                    CreateFigureKeyAttribute(fb, fka);
                }
            }
            else if (mr.IsKey)
            {
                mr.IsIdentity = true;
                mr.Required   = true;

                if (Identities.ContainsKey(mr.IdentityOrder))
                {
                    mr.IdentityOrder += (short)(Identities.LastOrDefault().Key + 1);
                }

                Identities.Add(mr.IdentityOrder, mr);

                if (fb != null)
                {
                    CreateFigureKeyAttribute(fb, new FigureKeyAttribute()
                    {
                        IsAutoincrement = mr.IsAutoincrement, Order = mr.IdentityOrder
                    });
                }
            }
        }