本文整理汇总了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;
}