當前位置: 首頁>>代碼示例>>C#>>正文


C# PropertyDefinition.Assocication方法代碼示例

本文整理匯總了C#中Mono.Cecil.PropertyDefinition.Assocication方法的典型用法代碼示例。如果您正苦於以下問題:C# PropertyDefinition.Assocication方法的具體用法?C# PropertyDefinition.Assocication怎麽用?C# PropertyDefinition.Assocication使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.PropertyDefinition的用法示例。


在下文中一共展示了PropertyDefinition.Assocication方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: BuildCollectionProperty

        public PropertyDefinition BuildCollectionProperty(CollectionProperty property,TypeDefinition type)
        {
            //如果是一對多關係,即關聯屬性是單值屬性時,直接在上麵加上關聯關係
            //如果是多對多,則不需要處理,因為所屬類型會執行這個動作

            var mod = type.Module;
            var elementType = property.PropertyType.GetTypeReference();
            var ptype = mod.ImportReference(typeof(XPCollection<>)).MakeGenericType(elementType);
            var propertyInfo = new PropertyDefinition(property.名稱, PropertyAttributes.None, ptype) { HasThis = true };
            type.Properties.Add(propertyInfo);

            propertyInfo.Assocication(property);
            if (property.Aggregated)
            {
                propertyInfo.Aggregate();
            }

            #region getter
            //.method public hidebysig specialname instance string get_創建者() cil managedMono.Cecil.MethodAttributes.Public | Mono.Cecil.MethodAttributes.HideBySig | Mono.Cecil.MethodAttributes.SpecialName
            var attr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.FamANDAssem | MethodAttributes.Family;

            var getMethod = new MethodDefinition("get_" + property.名稱, attr, ptype);

            var getMethodIl = getMethod.Body.GetILProcessor();
            getMethod.Body.Variables.Add(new VariableDefinition(ptype));

            getMethod.Body.MaxStackSize = 8;

            getMethod.Body.InitLocals = true;
            //.maxstack 2
            //.locals init ([0] class [DevExpress.Xpo.v15.2]DevExpress.Xpo.XPCollection`1<class IMatrix.ERP.Module.BusinessObjects.員工> xps)
            //L_0000: nop
            //L_0001: ldarg.0
            //L_0002: ldstr "\u8054\u7cfb\u4eba"
            //L_0007: call instance class [DevExpress.Xpo.v15.2]DevExpress.Xpo.XPCollection`1<!!0> [DevExpress.Xpo.v15.2]DevExpress.Xpo.XPBaseObject::GetCollection<class IMatrix.ERP.Module.BusinessObjects.員工>(string)
            //L_000c: stloc.0
            //L_000d: br.s L_000f
            //L_000f: ldloc.0
            //L_0010: ret
            getMethodIl.Emit(OpCodes.Nop);
            getMethodIl.Emit(OpCodes.Ldarg_0);
            getMethodIl.Emit(OpCodes.Ldstr, property.名稱);
            var clrGetCollection = typeof(SimpleObject).GetMethods(SR.BindingFlags.NonPublic | SR.BindingFlags.Instance).Single(x => x.Name == "GetCollection" && x.ReturnType.IsGenericType);
            var getCollection = mod.ImportReference(clrGetCollection);    //(tb as TypeDefinition).Methods.Single(x => x.Name == ".ctor" && x.Parameters.First().ParameterType.FullName == typeof(Session).FullName);
            getCollection = getCollection.MakeGenericMethod(elementType);

            getMethodIl.Emit(OpCodes.Call, getCollection);
            getMethodIl.Emit(OpCodes.Stloc_0);

            var ldloc0 = getMethodIl.Create(OpCodes.Ldloc_0);
            getMethodIl.Emit(OpCodes.Br_S, ldloc0);
            getMethodIl.Append(ldloc0);
            getMethodIl.Emit(OpCodes.Ret);
            type.Methods.Add(getMethod);
            propertyInfo.GetMethod = getMethod;

            #endregion

            return propertyInfo;
        }
開發者ID:ZixiangBoy,項目名稱:CIIP,代碼行數:60,代碼來源:GenerateBusinessModuleController.cs


注:本文中的Mono.Cecil.PropertyDefinition.Assocication方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。