public GetType ( string fullName ) : Mono.Cecil.TypeDefinition | ||
fullName | string | |
Результат | Mono.Cecil.TypeDefinition |
void OnInterface(XPathNavigator nav) { string name = GetName(nav); TypeDefinition type = _context.GetType(GetTypeName(name)); if (type != null) { _visitor.OnInterface(nav, type); } }
IEnumerable <CustomAttribute> ProcessAttributes(XPathNavigator nav) { XPathNodeIterator iterator = nav.SelectChildren("attribute", string.Empty); var attributes = new List <CustomAttribute> (); while (iterator.MoveNext()) { AssemblyDefinition assembly; TypeDefinition attributeType; string attributeFullName = GetFullName(iterator.Current); if (attributeFullName == String.Empty) { _context.LogWarning($"Attribute element does not contain attribute 'fullname'", 2029, _xmlDocumentLocation); continue; } string assemblyName = GetAttribute(iterator.Current, "assembly"); if (assemblyName == String.Empty) { attributeType = _context.GetType(attributeFullName); } else { try { assembly = GetAssembly(_context, AssemblyNameReference.Parse(assemblyName)); } catch (Exception) { _context.LogWarning($"Could not resolve assembly '{assemblyName}' in attribute '{attributeFullName}' specified in the '{_xmlDocumentLocation}'", 2030, _xmlDocumentLocation); continue; } attributeType = assembly.FindType(attributeFullName); } if (attributeType == null) { _context.LogWarning($"Attribute type '{attributeFullName}' could not be found", 2031, _xmlDocumentLocation); continue; } ArrayBuilder <string> arguments = GetAttributeChildren(iterator.Current.SelectChildren("argument", string.Empty)); MethodDefinition constructor = attributeType.Methods.Where(method => method.IsInstanceConstructor()).FirstOrDefault(c => c.Parameters.Count == arguments.Count); if (constructor == null) { _context.LogWarning($"Could not find a constructor for type '{attributeType}' that receives '{arguments.Count}' arguments as parameter", 2022, _xmlDocumentLocation); continue; } string[] xmlArguments = arguments.ToArray(); bool recognizedArgument = true; CustomAttribute attribute = new CustomAttribute(constructor); for (int i = 0; i < xmlArguments.Length; i++) { object argumentValue = null; if (constructor.Parameters[i].ParameterType.Resolve().IsEnum) { foreach (var field in constructor.Parameters[i].ParameterType.Resolve().Fields) { if (field.IsStatic && field.Name == xmlArguments[i]) { argumentValue = Convert.ToInt32(field.Constant); break; } } if (argumentValue == null) { _context.LogWarning($"Could not parse argument '{xmlArguments[i]}' specified in '{_xmlDocumentLocation}' as a {constructor.Parameters[i].ParameterType.FullName}", 2021, _xmlDocumentLocation); recognizedArgument = false; } } else { switch (constructor.Parameters[i].ParameterType.MetadataType) { case MetadataType.String: argumentValue = xmlArguments[i]; break; case MetadataType.Int32: int result; if (int.TryParse(xmlArguments[i], out result)) { argumentValue = result; } else { _context.LogWarning($"Argument '{xmlArguments[i]}' specified in '{_xmlDocumentLocation}' could not be transformed to the constructor parameter type", 2032, _xmlDocumentLocation); } break; default: _context.LogWarning($"Argument '{xmlArguments[i]}' specified in '{_xmlDocumentLocation}' is of unsupported type '{constructor.Parameters[i].ParameterType}'", 2020, _xmlDocumentLocation); recognizedArgument = false; break; } } attribute.ConstructorArguments.Add(new CustomAttributeArgument(constructor.Parameters[i].ParameterType, argumentValue)); } if (recognizedArgument) { attributes.Add(attribute); } } return(attributes); }