本文整理匯總了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;
}