public NameSyntax GetNameSyntax(Type type, Property property) { return(SF.IdentifierName(GetName( type ?? throw new ArgumentNullException(nameof(type)), property ?? throw new ArgumentNullException(nameof(property)) ))); }
public NameSyntax GetNameSyntax(Type type, EnumMember enumMember) { return(SF.IdentifierName(GetName( type ?? throw new ArgumentNullException(nameof(type)), enumMember ?? throw new ArgumentNullException(nameof(enumMember)) ))); }
public NameSyntax GetNameSyntax(Type type, Method method) { return(SF.IdentifierName(GetName( type ?? throw new ArgumentNullException(nameof(type)), method ?? throw new ArgumentNullException(nameof(method)) ))); }
public string GetName(Type type, EnumMember enumMember) { string fullyQualifiedName = (type ?? throw new ArgumentNullException(nameof(type))).FullyQualifiedName; string enumMemberName = (enumMember ?? throw new ArgumentNullException(nameof(enumMember))).Name; // We can't look up the enum member name in _types, because it might belong to a base type that hasn't been parsed yet. return(NameUtils.ConvertEnumMemberName(enumMemberName)); }
public string GetName(Type type, Property property) { string fullyQualifiedName = (type ?? throw new ArgumentNullException(nameof(type))).FullyQualifiedName; string propertyName = (property ?? throw new ArgumentNullException(nameof(property))).Name; // We can't look up the property name in _types, because it might belong to a base type that hasn't been parsed yet. return(NameUtils.ConvertPropertyName(propertyName)); }
public string GetName(Type type, Method method) { string fullyQualifiedName = (type ?? throw new ArgumentNullException(nameof(type))).FullyQualifiedName; string methodName = (method ?? throw new ArgumentNullException(nameof(method))).Name; // We can't look up the method name in _types, because it might belong to a base type that hasn't been parsed yet. return(NameUtils.ConvertMethodName(method.Name)); }
public string GetPackage(Type type) { type = type ?? throw new ArgumentNullException(nameof(type)); string fullyQualifiedName = type.FullyQualifiedName; return(_types[fullyQualifiedName].Package); }
public TypeMetadata(Type type, Assembly assembly) { Type = type ?? throw new ArgumentNullException(nameof(type)); assembly = assembly ?? throw new ArgumentNullException(nameof(assembly)); Package = type.Assembly; Namespace = $"{assembly.GetNativeName(Package)}{type.Namespace.Substring(Package.Length)}"; }
public string GetName(Type type, bool disambiguate = false) { type = type ?? throw new ArgumentNullException(nameof(type)); TypeMetadata metadata = _types[type.FullyQualifiedName]; disambiguate = disambiguate && _types.Values .Any(m => m.Type.FullyQualifiedName != metadata.Type.FullyQualifiedName && m.Name == metadata.Name); return(disambiguate ? metadata.FrameworkFullyQualifiedName : metadata.Name); }
public TypeMetadata(Type type, Assembly assembly) { Type = type ?? throw new ArgumentNullException(nameof(type)); assembly = assembly ?? throw new ArgumentNullException(nameof(assembly)); Package = type.Assembly; string suffix = type.Namespace != null ? $".{type.Namespace}" : ""; Namespace = $"{assembly.GetNativeNamespace(Package)}{suffix}"; }
public TypeSyntax GetTypeSyntax(TypeReference typeReference) { bool isOptional = (typeReference ?? throw new ArgumentNullException(nameof(typeReference))).IsOptional == true; if (typeReference.Primitive != null) { switch (typeReference.Primitive.Value) { case PrimitiveType.Any: return(SF.ParseTypeName("object")); case PrimitiveType.Boolean: return(SF.ParseTypeName(isOptional ? "bool?" : "bool")); case PrimitiveType.Date: return(SF.ParseTypeName(isOptional ? "DateTime?" : "DateTime")); case PrimitiveType.Json: return(SF.ParseTypeName("JObject")); case PrimitiveType.Number: return(SF.ParseTypeName(isOptional ? "double?" : "double")); case PrimitiveType.String: return(SF.ParseTypeName("string")); default: throw new ArgumentException($"Unexpected primitive type {typeReference.Primitive.Value}", nameof(typeReference)); } } if (typeReference.Collection != null) { TypeSyntax elementType = GetTypeSyntax(typeReference.Collection.ElementType); switch (typeReference.Collection.Kind) { case CollectionKind.Array: return(SF.ArrayType( elementType, SF.List(new[] { SF.ArrayRankSpecifier() }) )); case CollectionKind.Map: return(SF.ParseTypeName($"IDictionary<string, {elementType}>")); default: throw new ArgumentException($"Unexpected collection type {typeReference.Collection.Kind}", nameof(typeReference)); } } if (typeReference.Union != null) { return(SF.ParseTypeName("object")); } if (typeReference.FullyQualifiedName != null) { Type type = GetTypeFromFullyQualifiedName(typeReference.FullyQualifiedName); return(SF.ParseTypeName(GetName(type))); } throw new ArgumentException("Invalid type reference", nameof(typeReference)); }
public NameSyntax GetNameSyntax(Type type, bool disambiguate = false) { return(SF.IdentifierName(GetName(type ?? throw new ArgumentNullException(nameof(type)), disambiguate))); }
public SyntaxToken GetPackageSyntaxToken(Type type) { return(SF.Identifier(GetPackage(type ?? throw new ArgumentNullException(nameof(type))))); }
public NameSyntax GetPackageSyntax(Type type) { return(SF.IdentifierName(GetPackage(type ?? throw new ArgumentNullException(nameof(type))))); }
public void Add(Type type) { _referencedNamespaces.Add(_symbols.GetNamespaceSyntax(type)); }
public string GetNamespace(Type type) { string fullyQualifiedName = (type ?? throw new ArgumentNullException(nameof(type))).FullyQualifiedName; return(_types[fullyQualifiedName].Namespace ?? ""); }
private IEnumerable <Property> GetAllProperties(Type type) { IEnumerable <Property> GetAllPropertiesRecurse(Type currentType, IEnumerable <Property> properties) { if (currentType is InterfaceType interfaceType) { // Get all properties from the interface. properties = properties.Concat(interfaceType.Properties ?? Enumerable.Empty <Property>()); // Interfaces can have superinterfaces. Run through them too. if (interfaceType.Interfaces != null) { var superinterfaceMethods = interfaceType.Interfaces.Select(r => Symbols.GetTypeFromFullyQualifiedName(r) as InterfaceType) .SelectMany(i => GetAllPropertiesRecurse(i, properties)) .ToList(); properties = properties.Concat(superinterfaceMethods); } } else if (currentType is ClassType classType) { // Add the properties from the class. properties = properties.Concat(classType.Properties ?? Enumerable.Empty <Property>()); // Run through all the interfaces. if (classType.Interfaces != null) { var superinterfaceMethods = classType.Interfaces.Select(r => Symbols.GetTypeFromFullyQualifiedName(r) as InterfaceType) .SelectMany(i => GetAllPropertiesRecurse(i, properties)) .ToList(); properties = properties.Concat(superinterfaceMethods); } // Run through the superclass. if (classType.Base != null) { properties = properties.Concat(GetAllPropertiesRecurse( Symbols.GetTypeFromFullyQualifiedName(classType.Base) as ClassType, properties)); } } return(properties); } /* * Only get the first declaration encountered, and keep it if it is abstract. The list contains ALL * methods and properties encountered, in the order encountered. An abstract class can have concrete * implementations. Therefore, we only generate methods/properties if the first member encountered * is unimplemented. */ return(GetAllPropertiesRecurse(type, Enumerable.Empty <Property>()) .GroupBy(p => p.Name) .Select(g => g.First()) .Where(p => p.IsAbstract)); }
private IEnumerable <Method> GetAllMethods(Type type) { IEnumerable <Method> GetAllMethodsRecurse(Type currentType, IEnumerable <Method> methods) { if (currentType is InterfaceType interfaceType) { // Get all properties from the interface. methods = methods.Concat(interfaceType.Methods ?? Enumerable.Empty <Method>()); // Interfaces can have superinterfaces. Run through them too. if (interfaceType.Interfaces != null) { var superinterfaceMethods = interfaceType.Interfaces.Select(r => Symbols.GetTypeFromFullyQualifiedName(r) as InterfaceType) .SelectMany(i => GetAllMethodsRecurse(i, methods)) .ToList(); methods = methods.Concat(superinterfaceMethods); } } else if (currentType is ClassType classType) { // Get all methods from the interface methods = methods.Concat(classType.Methods ?? Enumerable.Empty <Method>()); if (classType.Interfaces != null) { // Run through all the interfaces. var superinterfaceMethods = classType.Interfaces.Select(r => Symbols.GetTypeFromFullyQualifiedName(r) as InterfaceType) .SelectMany(i => GetAllMethodsRecurse(i, methods)) .ToList(); methods = methods.Concat(superinterfaceMethods); } // Run through the superclass. if (classType.Base != null) { methods = methods.Concat(GetAllMethodsRecurse( Symbols.GetTypeFromFullyQualifiedName(classType.Base) as ClassType, methods)); } } return(methods); } /* * Only get the first declaration encountered, and keep it if it is abstract. The list contains ALL * methods and properties encountered, in the order encountered. An abstract class can have concrete * implementations. Therefore, we only generate methods/properties if the first member encountered * is unimplemented. */ return(GetAllMethodsRecurse(type, Enumerable.Empty <Method>()) .GroupBy(m => (m.Name, string.Join("", m.Parameters?.Select(p => p.Name + p.Type.FullyQualifiedName) ?? Enumerable.Empty <string>()))) .Select(g => g.First()) .Where(m => m.IsAbstract)); }
public static void MapFullyQualifiedNameToType(this ISymbolMap symbols, string fullyQualifiedName, Type type) { symbols .GetTypeFromFullyQualifiedName(Arg.Is <string>(n => n == fullyQualifiedName)) .Returns(type); }