本文整理汇总了C#中TypeDefinition.GetProperties方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDefinition.GetProperties方法的具体用法?C# TypeDefinition.GetProperties怎么用?C# TypeDefinition.GetProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeDefinition
的用法示例。
在下文中一共展示了TypeDefinition.GetProperties方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddToString
private void AddToString(TypeDefinition type)
{
var methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual;
var strType = ModuleDefinition.TypeSystem.String;
var method = new MethodDefinition("ToString", methodAttributes, strType);
method.Body.Variables.Add(new VariableDefinition(new ArrayType(ModuleDefinition.TypeSystem.Object)));
var allProperties = type.GetProperties().Where(x => !x.HasParameters).ToArray();
var properties = RemoveIgnoredProperties(allProperties);
var format = GetFormatString(type, properties);
var body = method.Body;
body.InitLocals = true;
var ins = body.Instructions;
var hasCollections = properties.Any(x => !x.PropertyType.IsGenericParameter && x.PropertyType.Resolve().IsCollection());
if (hasCollections)
{
method.Body.Variables.Add(new VariableDefinition(stringBuilderType));
var enumeratorType = ModuleDefinition.Import(typeof (IEnumerator));
method.Body.Variables.Add(new VariableDefinition(enumeratorType));
method.Body.Variables.Add(new VariableDefinition(ModuleDefinition.TypeSystem.Boolean));
method.Body.Variables.Add(new VariableDefinition(new ArrayType(ModuleDefinition.TypeSystem.Object)));
}
var genericOffset = !type.HasGenericParameters ? 0 : type.GenericParameters.Count;
AddInitCode(ins, format, properties, genericOffset);
if (type.HasGenericParameters)
{
AddGenericParameterNames(type, ins);
}
for (var i = 0; i < properties.Length; i++)
{
var property = properties[i];
AddPropertyCode(method.Body, i + genericOffset, property, type, method.Body.Variables);
}
AddMethodAttributes(method);
AddEndCode(body);
body.OptimizeMacros();
var toRemove = type.Methods.FirstOrDefault(x => x.Name == method.Name && x.Parameters.Count == 0);
if (toRemove != null)
{
type.Methods.Remove(toRemove);
}
type.Methods.Add(method);
RemoveFodyAttributes(type, allProperties);
}