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