private string ConvertToType(TypeReference argumentType, object argumentValue) { var valueResult = GetArgumentValue("System.Type", argumentType, argumentValue); var typeFullName = MDocUpdater.GetDocTypeFullName((TypeReference)valueResult, isTypeofOperator: true); return $"typeof({typeFullName})"; }
public virtual bool TryFormatValue(object v, ResolvedTypeInfo type, out string returnvalue) { TypeReference valueType = type.Reference; if (v == null) { returnvalue = "null"; return(true); } if (valueType.FullName == "System.Type") { var vTypeRef = v as TypeReference; if (vTypeRef != null) { returnvalue = "typeof(" + NativeTypeManager.GetTranslatedName(vTypeRef) + ")"; // TODO: drop NS handling } else { returnvalue = "typeof(" + v.ToString() + ")"; } return(true); } if (valueType.FullName == "System.String") { returnvalue = "\"" + FilterSpecialChars(v.ToString()) + "\""; return(true); } if (valueType.FullName == "System.Char") { returnvalue = "'" + FilterSpecialChars(v.ToString()) + "'"; return(true); } if (v is Boolean) { returnvalue = (bool)v ? "true" : "false"; return(true); } TypeDefinition valueDef = type.Definition; if (valueDef == null || !valueDef.IsEnum) { returnvalue = v.ToString(); return(true); } string typename = MDocUpdater.GetDocTypeFullName(valueType); var values = GetEnumerationValues(valueDef); long c = ToInt64(v); if (values.ContainsKey(c)) { returnvalue = typename + "." + values[c]; return(true); } returnvalue = null; return(false); }
private (string typeFullName, IDictionary<long, string> enumConstants, long enumValue) ExtractEnumTypeData(TypeReference argumentType, object argumentValue) { var argumentTypeDefinition = argumentType.Resolve(); var typeFullName = MDocUpdater.GetDocTypeFullName(argumentTypeDefinition); var enumConstants = GetEnumerationValues(argumentTypeDefinition); var enumValue = ToInt64(argumentValue); return (typeFullName, enumConstants, enumValue); }
public override bool TryFormatValue(object v, ResolvedTypeInfo type, out string returnvalue) { TypeReference valueType = type.Reference; string typename = MDocUpdater.GetDocTypeFullName(valueType); TypeDefinition valueDef = type.Definition; if (typename.Contains("ObjCRuntime.Platform") && valueDef.CustomAttributes.Any(ca => ca.AttributeType.FullName == "System.FlagsAttribute")) { var values = GetEnumerationValues(valueDef); long c = ToInt64(v); returnvalue = Format(c, values, typename); return(true); } returnvalue = null; return(false); }
public override bool TryFormatValue(object v, ResolvedTypeInfo type, out string returnvalue) { TypeReference valueType = type.Reference; TypeDefinition valueDef = type.Definition; if (valueDef.CustomAttributes.Any(ca => ca.AttributeType.FullName == "System.FlagsAttribute")) { string typename = MDocUpdater.GetDocTypeFullName(valueType); var values = MDocUpdater.GetEnumerationValues(valueDef); long c = MDocUpdater.ToInt64(v); returnvalue = string.Join(" | ", (from i in values.Keys where (c & i) == i && i != 0 select typename + "." + values[i]) .DefaultIfEmpty(c.ToString()).ToArray()); return(true); } returnvalue = null; return(false); }
public override bool TryFormatValue(object v, ResolvedTypeInfo type, out string returnvalue) { returnvalue = "(" + MDocUpdater.GetDocTypeFullName(type.Reference) + ") " + MDocUpdater.FilterSpecialChars(v.ToString()); return(true); }
public static MemberReference GetMember(TypeDefinition type, DocumentationMember member) { string membertype = member.MemberType; string returntype = member.ReturnType; string docName = member.MemberName; string[] docTypeParams = GetTypeParameters(docName, member.TypeParameters); // If we're using 'magic types', then we might get false positives ... in those cases, we keep searching MemberReference likelyCandidate = null; // Loop through all members in this type with the same name var reflectedMembers = GetReflectionMembers(type, docName, membertype).ToArray(); foreach (MemberReference mi in reflectedMembers) { bool matchedMagicType = false; if (mi is TypeDefinition) { continue; } if (MDocUpdater.GetMemberType(mi) != membertype) { continue; } if (MDocUpdater.IsPrivate(mi)) { continue; } IList <ParameterDefinition> pis = null; string[] typeParams = null; if (mi is MethodDefinition) { MethodDefinition mb = (MethodDefinition)mi; pis = mb.Parameters; if (mb.IsGenericMethod()) { IList <GenericParameter> args = mb.GenericParameters; typeParams = args.Select(p => p.Name).ToArray(); } } else if (mi is PropertyDefinition) { pis = ((PropertyDefinition)mi).Parameters; } // check type parameters int methodTcount = member.TypeParameters == null ? 0 : member.TypeParameters.Count; int reflectionTcount = typeParams == null ? 0 : typeParams.Length; if (methodTcount != reflectionTcount) { continue; } // check member parameters int mcount = member.Parameters == null ? 0 : member.Parameters.Count; int pcount = pis == null ? 0 : pis.Count; if (mcount != pcount) { continue; } MethodDefinition mDef = mi as MethodDefinition; if (mDef != null && !mDef.IsConstructor && (mDef.Name.StartsWith("op_Explicit", StringComparison.Ordinal) || mDef.Name.StartsWith("op_Implicit", StringComparison.Ordinal))) { // Casting operators can overload based on return type. string rtype = GetReplacedString( MDocUpdater.GetDocTypeFullName(((MethodDefinition)mi).ReturnType), typeParams, docTypeParams); string originalRType = rtype; if (MDocUpdater.SwitchingToMagicTypes) { rtype = NativeTypeManager.ConvertFromNativeType(rtype); } if ((returntype != rtype && originalRType == rtype) || (MDocUpdater.SwitchingToMagicTypes && returntype != originalRType && returntype != rtype && originalRType != rtype)) { continue; } if (originalRType != rtype) { matchedMagicType = true; } } if (pcount == 0) { return(mi); } bool isExtensionMethod = DocUtils.IsExtensionMethod(mDef); bool good = true; for (int i = 0; i < pis.Count; i++) { bool isRefType = pis[i].ParameterType is ByReferenceType; if (i == 0 && !isRefType && isExtensionMethod) { isRefType = true; // this will be the case for generic parameter types } string paramType = GetReplacedString( MDocUpdater.GetDocParameterType(pis[i].ParameterType), typeParams, docTypeParams); // if magictypes, replace paramType to "classic value" ... so the comparison works string originalParamType = paramType; if (MDocUpdater.SwitchingToMagicTypes) { paramType = NativeTypeManager.ConvertFromNativeType(paramType); } string xmlMemberType = member.Parameters[i]; // TODO: take into account extension method reftype bool xmlIsRefType = xmlMemberType.Contains('&'); bool refTypesMatch = isRefType == xmlIsRefType; if (!refTypesMatch) { good = false; break; } xmlMemberType = xmlIsRefType ? xmlMemberType.Substring(0, xmlMemberType.Length - 1) : xmlMemberType; if ((!paramType.Equals(xmlMemberType) && paramType.Equals(originalParamType)) || (MDocUpdater.SwitchingToMagicTypes && !originalParamType.Equals(xmlMemberType) && !paramType.Equals(xmlMemberType) && !paramType.Equals(originalParamType))) { // did not match ... if we're dropping the namespace, and the paramType has the dropped // namespace, we should see if it matches when added bool stillDoesntMatch = true; if (MDocUpdater.HasDroppedNamespace(type) && paramType.StartsWith(MDocUpdater.droppedNamespace)) { string withDroppedNs = string.Format("{0}.{1}", MDocUpdater.droppedNamespace, xmlMemberType); stillDoesntMatch = withDroppedNs != paramType; } if (stillDoesntMatch) { good = false; break; } } if (originalParamType != paramType) { matchedMagicType = true; } } if (!good) { continue; } if (MDocUpdater.SwitchingToMagicTypes && likelyCandidate == null && matchedMagicType) { // we matched this on a magic type conversion ... let's keep going to see if there's another one we should look at that matches more closely likelyCandidate = mi; continue; } return(mi); } return(likelyCandidate); }
private bool IsApplePlatformEnum(TypeReference argumentType, object argumentValue) { return MDocUpdater.GetDocTypeFullName(argumentType).Contains("ObjCRuntime.Platform"); }