示例#1
0
 /// <summary>
 /// Istanzia Biz object da una entry
 /// </summary>
 /// <param name="entry"></param>
 /// <param name="dalObj"></param>
 /// <returns></returns>
 internal BusinessObjectBase CreateBizObj(ProxyEntryBiz entry, DataObjectBase dalObj)
 {
     if (entry.Factory == null)
     {
         return(entry.Create(dalObj));
     }
     else
     {
         return(entry.Factory.Create(dalObj));
     }
 }
示例#2
0
        /// <summary>
        /// Ritorna proxy create per business object
        /// </summary>
        /// <returns></returns>
        private static ProxyEntryBiz buildBizProxyEntry(Type tOriginal, ProxyAssemblyCache.ProxyAssemblyBiz outProxy)
        {
            //Chiave
            long iOriginalTypeHandle = tOriginal.TypeHandle.Value.ToInt64();

            //Recupera tipo dal
            var tBizGen = tOriginal.BaseType;

            while (!tBizGen.IsGenericType)
            {
                tBizGen = tBizGen.BaseType;
            }

            if (tBizGen == null)
            {
                throw new ArgumentException(string.Format("Il tipo business {0} non eredita da BusinessObject<T>", tOriginal.Name));
            }

            var tDal = tBizGen.GetGenericArguments()[0];

            //Qui dovremmo assicurarci che la scansione dal sia avvenuta
            ProxyAssemblyCache.Instance.GetDaoEntry(tDal);

            //Imposta costruttore
            Type[] argTypesDef = new Type[] { typeof(object) };
            Type[] argTypes    = new Type[] { tDal };

            DynamicMethod dm    = new DynamicMethod("MyCtor", tOriginal, argTypesDef, tOriginal.Module);
            ILGenerator   ilgen = dm.GetILGenerator();

            ilgen.Emit(OpCodes.Ldarg_0);
            ilgen.Emit(OpCodes.Newobj, tOriginal.GetConstructor(argTypes));
            ilgen.Emit(OpCodes.Ret);

            var entry = new ProxyEntryBiz()
            {
                TypeKey = iOriginalTypeHandle,
                DalType = tDal,
                Create  = (ProxyEntryBiz.FastCreateBizObj)dm.CreateDelegate(typeof(ProxyEntryBiz.FastCreateBizObj))
            };

            outProxy.TypeBizEntries.Add(iOriginalTypeHandle, entry);

            return(entry);
        }