コード例 #1
0
ファイル: AssemblyProcessor.cs プロジェクト: leohsu91/DbEntry
        private void GenerateHandlers()
        {
            var module = ReadModule();

            var assembly = Assembly.LoadFrom(_oldName);
            var models   = DbEntry.GetAllModels(assembly);

            if (models.Count <= 0)
            {
                Console.WriteLine("Can not find any model to generate handler !");
            }

            var handler = new KnownTypesHandler(module);

            foreach (var type in models)
            {
                Program.ModelClass = type.FullName;
                if (Program.ModelClass != null)
                {
                    var model     = module.GetType(Program.ModelClass.Replace('+', '/'));
                    var generator = new ModelHandlerGenerator(type, model, handler);
                    var mh        = generator.Generate();
                    module.Types.Add(mh);

                    var mhg = new MemberHandlerGenerator(type, model, handler);
                    mhg.Generate(module);

                    new ModelRelationFixer(type, model).Process();
                }
            }

            module.CustomAttributes.Add(handler.GetAssemblyProcessed());

            WriteAssembly(module, _name);
        }
コード例 #2
0
ファイル: IlBuilder.cs プロジェクト: leohsu91/DbEntry
 public IlBuilder GetMember(MemberHandler mm, KnownTypesHandler handler)
 {
     if (mm.MemberInfo.IsProperty)
     {
         var method = ((PropertyInfo)mm.MemberInfo.GetMemberInfo()).GetGetMethod(true);
         return(CallVirtual(handler.Import(method)));
     }
     return(LoadField(handler.Import((FieldInfo)mm.MemberInfo.GetMemberInfo())));
 }
コード例 #3
0
 public MemberHandlerGenerator(Type type, TypeDefinition model, KnownTypesHandler handler)
 {
     this._model      = model;
     this._handler    = handler;
     this._properties = new Dictionary <string, PropertyDefinition>();
     this._fields     = new Dictionary <string, FieldDefinition>();
     GetMembers(model);
     _info = ObjectInfoFactory.Instance.GetInstance(type);
 }
コード例 #4
0
        public static TypeDefinition CreateType(KnownTypesHandler handler, TypeDefinition model, TypeDefinition interfaceType)
        {
            _index++;
            var result = new TypeDefinition(
                GetNamespace(model),
                GetClassName(model, interfaceType.Name),
                ClassTypeAttr,
                handler.ObjectType);

            result.Interfaces.Add(interfaceType);
            return(result);
        }
コード例 #5
0
        public ModelHandlerGenerator(Type type, TypeDefinition model, KnownTypesHandler handler)
        {
            this._model   = model;
            this._handler = handler;
            _result       = TypeFactory.CreateType(model, _handler.ModelHandlerBaseType);
            _result.Interfaces.Add(_handler.DbObjectHandlerInterface);
            _model.CustomAttributes.Add(_handler.GetModelHandler(_result));

            _info = ObjectInfoFactory.Instance.GetInstance(type);

            CheckType(type);
        }
コード例 #6
0
        public ComposedOfClassGenerator(TypeDefinition model, PropertyInformation pi, KnownTypesHandler handler)
        {
            this._composedOfType = pi.PropertyDefinition.PropertyType.Resolve();
            if (!_composedOfType.IsInterface)
            {
                throw new DataException("ComposedOf type must be interface.");
            }
            if (!_composedOfType.HasProperties)
            {
                throw new DataException("ComposedOf type must has properties.");
            }

            this._model        = model;
            this._handler      = handler;
            this._instanceName = pi.PropertyDefinition.Name;
            _result            = TypeFactory.CreateType(handler, model, _composedOfType);
        }
コード例 #7
0
ファイル: IlBuilder.cs プロジェクト: leohsu91/DbEntry
 public IlBuilder CastOrUnbox(TypeReference t, KnownTypesHandler handler)
 {
     //TODO: refactor the types to KnownTypesHandler
     if (t.IsGenericInstance && t.Name == "Nullable`1")
     {
         var inType = ((GenericInstanceType)t).GenericArguments[0];
         if (ProcessDateAndTime(inType, handler.Import(typeof(Date?)), handler.Import(typeof(Time?))))
         {
             return(this);
         }
     }
     if (t.IsValueType)
     {
         if (ProcessDateAndTime(t, handler.Import(typeof(Date)), handler.Import(typeof(Time))))
         {
             return(this);
         }
         if (t.FullName == typeof(bool).FullName)
         {
             t = handler.Import(typeof(bool));
         }
         else if (t.FullName == typeof(uint).FullName)
         {
             t = handler.Import(typeof(int));
         }
         else if (t.FullName == typeof(ulong).FullName)
         {
             t = handler.Import(typeof(long));
         }
         else if (t.FullName == typeof(ushort).FullName)
         {
             t = handler.Import(typeof(short));
         }
         _list.Add(_il.Create(OpCodes.Unbox_Any, t));
     }
     else
     {
         _list.Add(_il.Create(OpCodes.Castclass, t));
     }
     return(this);
 }
コード例 #8
0
ファイル: AssemblyProcessor.cs プロジェクト: leohsu91/DbEntry
        private void ProcessAssembly()
        {
            var module = ReadModule();

            var models = GetAllModels(module);

            if (models.Count <= 0)
            {
                Console.WriteLine("Can not find any model to process !");
                return;
            }

            var handler = new KnownTypesHandler(module);

            foreach (var type in models)
            {
                Program.ModelClass = type.FullName;
                var processor = new ModelProcessor(type, handler);
                processor.Process();
            }

            WriteAssembly(module, _oldName);
        }
コード例 #9
0
ファイル: ModelProcessor.cs プロジェクト: leohsu91/DbEntry
        private List <PropertyInformation> GetProperties()
        {
            var result = new List <PropertyInformation>();

            foreach (PropertyDefinition pi in _model.Properties)
            {
                if (pi.SetMethod != null && pi.GetMethod != null &&
                    pi.SetMethod.IsCompilerGenerated() &&
                    pi.GetMethod.IsCompilerGenerated())
                {
                    var ft  = KnownTypesHandler.GetFieldType(pi);
                    var ico = KnownTypesHandler.IsComposedOf(pi);
                    result.Add(new PropertyInformation
                    {
                        PropertyDefinition = pi,
                        FieldType          = ft,
                        IsComposedOf       = ico,
                        IsExclude          = KnownTypesHandler.IsExclude(pi)
                    });
                }
            }
            return(result);
        }
コード例 #10
0
ファイル: PropertyProcessor.cs プロジェクト: leohsu91/DbEntry
 public PropertyProcessor(PropertyInformation pi, TypeDefinition model, KnownTypesHandler handler)
 {
     this._pi      = pi;
     this._model   = model;
     this._handler = handler;
 }
コード例 #11
0
        public static PropertyDefinition CreateProperty(string name, MethodAttributes attr, TypeReference type, KnownTypesHandler handler)
        {
            var pd = new PropertyDefinition(name, PropertyAttributes.None, type);

            pd.GetMethod = new MethodDefinition("get_" + name, attr, type);
            pd.SetMethod = new MethodDefinition("set_" + name, attr, handler.VoidType);
            pd.SetMethod.Parameters.Add(new ParameterDefinition("value", ParameterAttributes.None, type));
            return(pd);
        }
コード例 #12
0
ファイル: ModelProcessor.cs プロジェクト: leohsu91/DbEntry
 public ModelProcessor(TypeDefinition model, KnownTypesHandler handler)
 {
     this._model   = model;
     this._handler = handler;
     _properties   = GetProperties();
 }