/// <summary>Generates an event information from the given event definition</summary> /// <param name="ev">The event definition to gather information from</param> /// <returns>Returns the event information generated</returns> public static EventInfo GenerateInfo(EventDefinition ev) { // Variables EventInfo info = new EventInfo(); info.name = ev.Name; info.typeInfo = QuickTypeInfo.GenerateInfo(ev.EventType); info.implementedType = QuickTypeInfo.GenerateInfo(ev.DeclaringType); info.adder = MethodInfo.GenerateInfo(ev.AddMethod); info.remover = MethodInfo.GenerateInfo(ev.RemoveMethod); info.accessor = info.adder.accessor; info.modifier = info.adder.modifier; info.isStatic = info.adder.isStatic; info.attributes = AttributeInfo.GenerateInfoArray(ev.CustomAttributes); info.fullDeclaration = ( info.accessor + " " + (info.modifier != "" ? info.modifier + " " : "") + info.typeInfo.name + " " + info.name ); if (TypeInfo.ignorePrivate && PropertyInfo.GetAccessorId(info.accessor) == 0) { info.shouldDelete = true; } return(info); }
/// <summary>Generates the information for the parameter given the parameter definition</summary> /// <param name="parameter">The parameter definition to look into</param> /// <returns>Returns the parameter information generated from the parameter definition</returns> public static ParameterInfo GenerateInfo(ParameterDefinition parameter) { // Variables ParameterInfo info = new ParameterInfo(); info.name = parameter.Name; info.typeInfo = QuickTypeInfo.GenerateInfo(parameter.ParameterType); info.attributes = AttributeInfo.GenerateInfoArray(parameter.CustomAttributes); if (parameter.IsIn) { info.modifier = "in"; } else if (parameter.IsOut) { info.modifier = "out"; } else if (parameter.ParameterType.IsByReference) { info.modifier = "ref"; } else if (HasParamsAttribute(info.attributes)) { info.modifier = "params"; } else { info.modifier = ""; } info.isOptional = parameter.IsOptional; info.defaultValue = $"{ parameter.Constant }"; info.genericParameterDeclarations = QuickTypeInfo.GetGenericParametersAsStrings(parameter.ParameterType.FullName); info.fullDeclaration = GetFullDeclaration(info); return(info); }
/// <summary>Generates the property information from the given property definition</summary> /// <param name="property">The property information to gather information from</param> /// <returns>Returns the property information that's generated</returns> public static PropertyInfo GenerateInfo(PropertyDefinition property) { // Variables PropertyInfo info = new PropertyInfo(); info.hasGetter = (property.GetMethod != null); info.hasSetter = (property.SetMethod != null); info.getter = (info.hasGetter ? (isGeneric != -1 ? MethodInfo.GetGenericMethodInfo(_type, _currType, _currTypeRef, property.GetMethod) : MethodInfo.GenerateInfo(property.GetMethod) ) : null ); info.setter = (info.hasSetter ? (isGeneric != -1 ? MethodInfo.GetGenericMethodInfo(_type, _currType, _currTypeRef, property.SetMethod) : MethodInfo.GenerateInfo(property.SetMethod) ) : null ); if (info.getter != null && GetAccessorId(info.getter.accessor) == 0) { info.getter = null; info.hasGetter = false; } if (info.setter != null && GetAccessorId(info.setter.accessor) == 0) { info.setter = null; info.hasSetter = false; } if (!info.hasGetter && !info.hasSetter) { info.shouldDelete = true; return(info); } info.name = property.Name; info.partialFullName = property.FullName.Split("::")[1].Replace(",", ", "); info.isStatic = !property.HasThis; info.attributes = AttributeInfo.GenerateInfoArray(property.CustomAttributes); info.parameters = ParameterInfo.GenerateInfoArray(property.Parameters); info.accessor = GetAccessor(info.getter, info.setter); if (isGeneric == 1) { if (info.hasGetter) { info.typeInfo = info.getter.returnType; info.parameters = info.getter.parameters; } else { info.typeInfo = info.setter.parameters[info.setter.parameters.Length - 1].typeInfo; System.Array.Copy( info.setter.parameters, info.parameters, info.setter.parameters.Length - 1 ); } } else { info.typeInfo = QuickTypeInfo.GenerateInfo(property.PropertyType); } if (!property.HasThis) { info.modifier = "static"; } else { info.modifier = GetModifier(info.getter, info.setter); } info.implementedType = QuickTypeInfo.GenerateInfo(property.DeclaringType); info.getSetDeclaration = GetGetSetDeclaration(info.getter, info.setter, info.accessor); info.declaration = ( info.accessor + " " + (info.modifier != "" ? info.modifier + " " : "") + info.typeInfo.name + " " + (info.parameters.Length == 0 ? info.name : "this") ); info.parameterDeclaration = string.Join(", ", GetParameterDeclarations(info)); info.fullDeclaration = ( info.declaration + (info.parameterDeclaration != "" ? $"[{ info.parameterDeclaration }]" : "") + $" {{ { info.getSetDeclaration } }}" ); isGeneric = -1; return(info); }
/// <summary>Generates the method information from the given method definition</summary> /// <param name="method">The method definition to look into</param> /// <returns>Returns the method information</returns> public static MethodInfo GenerateInfo(MethodDefinition method) { // Variables MethodInfo info = new MethodInfo(); int index; info.isStatic = method.IsStatic; info.isVirtual = method.IsVirtual; info.isConstructor = method.IsConstructor; if (method.IsAssembly) { info.accessor = "internal"; } else if (method.IsFamily) { info.accessor = "protected"; } else if (method.IsPublic) { info.accessor = "public"; } else { info.accessor = "private"; } info.isProperty = method.IsGetter || method.IsSetter; info.isEvent = method.IsAddOn || method.IsRemoveOn; info.isOperator = method.Name.StartsWith("op_"); info.isConversionOperator = ( method.Name == "op_Explicit" || method.Name == "op_Implicit" ); info.implementedType = QuickTypeInfo.GenerateInfo(method.DeclaringType); info.returnType = QuickTypeInfo.GenerateInfo(method.ReturnType); if (info.isConstructor) { info.name = info.implementedType.name; index = info.name.IndexOf('<'); if (index != -1) { info.name = info.name.Substring(0, index); } } else if (info.isConversionOperator) { info.name = method.Name + "__" + info.returnType.name; } else if (info.isOperator) { info.name = method.Name.Substring(3); } else { info.name = method.Name; } info.partialFullName = method.FullName.Split("::")[1].Replace(",", ", "); if (info.isOperator) { info.partialFullName = info.name; } info.parameters = ParameterInfo.GenerateInfoArray(method.Parameters); info.genericParameters = GenericParametersInfo.GenerateInfoArray(method.GenericParameters); info.attributes = AttributeInfo.GenerateInfoArray(method.CustomAttributes); if (info.isConversionOperator) { info.modifier = $"static { method.Name.Substring(3).ToLower() } operator"; } else if (info.isOperator) { info.modifier = "static operator"; } else if (method.IsStatic) { info.modifier = "static"; } else if (method.IsAbstract) { info.modifier = "abstract"; } else if (method.IsVirtual && method.IsReuseSlot) { info.modifier = "override"; } else if (method.IsVirtual) { info.modifier = "virtual"; } else { info.modifier = ""; } info.isExtension = HasExtensionAttribute(info); info.isAbstract = method.IsAbstract; info.isOverriden = method.IsReuseSlot; info.declaration = ( info.accessor + " " + (info.modifier != "" ? info.modifier + " " : "") + (!info.isConstructor && !info.isConversionOperator ? info.returnType.name + " " : "") + (!info.isConversionOperator ? info.name : info.returnType.name) ); info.genericDeclaration = (info.genericParameters.Length > 0 && !method.IsGenericInstance ? $"<{ string.Join(',', GetGenericParameterDeclaration(info.genericParameters)) }>" : "" ); info.parameterDeclaration = string.Join(", ", GetParameterDeclaration(info)); if (info.isExtension) { info.parameterDeclaration = $"this { info.parameterDeclaration }"; } info.fullDeclaration = $"{ info.declaration }{ info.genericDeclaration }({ info.parameterDeclaration })"; info.fullDeclaration += TypeInfo.GetGenericParameterConstraints(info.genericParameters); if (TypeInfo.ignorePrivate && PropertyInfo.GetAccessorId(info.accessor) == 0) { info.shouldDelete = true; } return(info); }
/// <summary>Generates the information for the field from the field definition</summary> /// <param name="field">The field definition to look into</param> /// <returns>Returns the information of the field</returns> public static FieldInfo GenerateInfo(FieldDefinition field) { // Variables FieldInfo info = new FieldInfo(); string val = System.Text.ASCIIEncoding.ASCII.GetString(field.InitialValue); if (field.IsAssembly) { info.accessor = "internal"; } else if (field.IsFamily) { info.accessor = "protected"; } else if (field.IsPrivate) { info.accessor = "private"; } else { info.accessor = "public"; } if (TypeInfo.ignorePrivate && PropertyInfo.GetAccessorId(info.accessor) == 0) { info.shouldDelete = true; return(info); } info.name = field.Name; info.typeInfo = QuickTypeInfo.GenerateInfo(field.FieldType); info.implementedType = QuickTypeInfo.GenerateInfo(field.DeclaringType); info.value = $"{ field.Constant ?? val }"; info.isConstant = field.HasConstant; info.isStatic = field.IsStatic; info.isReadonly = field.IsInitOnly; info.attributes = AttributeInfo.GenerateInfoArray(field.CustomAttributes); if (field.HasConstant) { info.modifier = "const"; } else if (field.IsStatic && field.IsInitOnly) { info.modifier = "static readonly"; } else if (field.IsStatic) { info.modifier = "static"; } else if (field.IsInitOnly) { info.modifier = "readonly"; } else { info.modifier = ""; } info.fullDeclaration = ( $"{ info.accessor } " + (info.modifier != "" ? info.modifier + " " : "") + $"{ info.typeInfo.name } " + info.name ); if (info.isConstant) { info.fullDeclaration += $" = { info.value }"; } return(info); }