本文整理汇总了C#中Mono.Cecil.PropertyDefinition.Size方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyDefinition.Size方法的具体用法?C# PropertyDefinition.Size怎么用?C# PropertyDefinition.Size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.PropertyDefinition
的用法示例。
在下文中一共展示了PropertyDefinition.Size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildPropertyCore
public static PropertyDefinition BuildPropertyCore(Property property, TypeDefinition type)
{
var mod = type.Module;
//从缓存中查找clr type
var ptype = property.PropertyType.GetTypeReference();
var fieldInfo = new FieldDefinition("_" + property.名称, FieldAttributes.Private, ptype);
type.Fields.Add(fieldInfo);
// type.DefineField("_" + property.名称, ptype, FieldAttributes.Private);
var propertyInfo = new PropertyDefinition(property.名称, PropertyAttributes.None, ptype) { HasThis = true };
type.Properties.Add(propertyInfo);
#region 基本属性设置
if (property.Size != 100 && property.Size != 0)
{
propertyInfo.Size(property.Size);
}
//if (!string.IsNullOrEmpty(property.Expression))
//{
// propertyInfo.PersistentAlias(property.Expression);
//}
#endregion;
#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 setattr = 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.MaxStackSize = 8;
getMethod.Body.InitLocals = true;
getMethodIl.Emit(OpCodes.Ldarg_0);
getMethodIl.Emit(OpCodes.Ldfld, fieldInfo);
getMethodIl.Emit(OpCodes.Ret);
type.Methods.Add(getMethod);
propertyInfo.GetMethod = getMethod;
#endregion
#region 非计算类型
if (string.IsNullOrEmpty(property.Expression))
{
var set = new MethodDefinition("set_" + property.名称, setattr, mod.ImportReference(typeof (void)));
var para = new ParameterDefinition("value", ParameterAttributes.None, ptype);
set.Parameters.Add(para);
var setPropertyValue = mod.ImportReference(
typeof (PersistentBase)
.GetMethods(
SR.BindingFlags.InvokeMethod | SR.BindingFlags.NonPublic |
SR.BindingFlags.Instance)
.Single(x => x.Name.StartsWith("SetPropertyValue") && x.IsGenericMethod &&
x.GetParameters().Length == 3)
);
var setPropertyValueMethod = new GenericInstanceMethod(setPropertyValue);
setPropertyValueMethod.GenericArguments.Add(ptype);
//setPropertyValue = setPropertyValue.MakeGenericMethod(ptype);
var setIl = set.Body.Instructions;
setIl.Add(Instruction.Create(OpCodes.Ldarg_0));
setIl.Add(Instruction.Create(OpCodes.Ldstr, property.名称));
setIl.Add(Instruction.Create(OpCodes.Ldarg_0));
setIl.Add(Instruction.Create(OpCodes.Ldflda, fieldInfo));
setIl.Add(Instruction.Create(OpCodes.Ldarg_1));
setIl.Add(Instruction.Create(OpCodes.Call, setPropertyValueMethod));
setIl.Add(Instruction.Create(OpCodes.Pop));
setIl.Add(Instruction.Create(OpCodes.Ret));
propertyInfo.SetMethod = set;
type.Methods.Add(set);
}
#endregion
return propertyInfo;
}