/// <summary> /// Determines whether the type needs fully qualified name or simple type name in the given namespace context /// </summary> /// <param name="type">type</param> /// <param name="namespaceContext">namespace where type is referenced</param> /// <param name="format">a generated type format, such as I{0}RequestBuilder</param> /// <returns>Either the fully qualified or plain type name</returns> public static string GetTypeString(this OdcmType type, string namespaceContext, string format = null) { var typesNamespace = type.Namespace.GetNamespaceName().Replace("edm.", ""); var plainTypeString = type.GetTypeString(); // refer to core implementation when they are available for Edm types var coreModelTypes = new List <string> { "Date", "Duration", "TimeOfDay" }; if (typesNamespace == "Edm" && coreModelTypes.Contains(plainTypeString)) { typesNamespace = "Microsoft.Graph"; } if (format != null) { plainTypeString = string.Format(format, plainTypeString); } if (string.Equals(typesNamespace, namespaceContext, StringComparison.OrdinalIgnoreCase) || typesNamespace == "Edm") { return(plainTypeString); } else { return(typesNamespace + "." + plainTypeString); } }
public static string GetTypeString(this OdcmType @type) { switch (@type.Name) { case "Int16": case "Int32": return("Integer"); case "Int64": return("Long"); case "Guid": return("java.util.UUID"); case "DateTimeOffset": return("java.util.Calendar"); case "Date": return("com.microsoft.graph.model.DateOnly"); case "Json": return("com.google.gson.JsonElement"); case "Binary": return("byte[]"); default: return(@type.Name.ToUpperFirstChar()); } }
public static bool IsComplex(this OdcmType type) { string t = GetTypeString(type); return (!(t == "int32_t" || t == "int64_t" || t == "int16_t" || t == "BOOL" || t == "Byte" || t == "double")); }
public static string GetTypeString(this OdcmType @type) { switch (@type.Name) { case "Int16": case "Int32": return("Integer"); case "Int64": return("Long"); case "Guid": return("javascript.util.UUID"); case "DateTimeOffset": case "Date": return("javascript.util.Calendar"); case "Binary": return("byte[]"); default: return(@type.Name.ToUpperFirstChar()); } }
public static Identifier GetPublicTypeName(OdcmType odcmType, bool isCollection) { if (odcmType == null) { return(new Identifier(string.Empty, "void")); } if (odcmType.Namespace == OdcmNamespace.Edm) { return(GetPrimitiveTypeName(odcmType)); } if (odcmType is OdcmClass && ((OdcmClass)odcmType).Kind == OdcmClassKind.Entity) { return(GetConcreteInterfaceName(odcmType)); } if (odcmType is OdcmClass && ((OdcmClass)odcmType).Kind == OdcmClassKind.MediaEntity) { return(GetConcreteInterfaceName(odcmType)); } var resolvedName = ResolveIdentifier(odcmType); return(new Identifier(resolvedName.Namespace, resolvedName.Name + (isCollection ? "[]" : string.Empty))); }
public static string GetNSNumberValueMethod(this OdcmType type) { string objectiveCType = type.GetTypeString(); if (objectiveCType.Equals("int32_t") || objectiveCType.Equals("int16_t")) { return("intValue"); } if (objectiveCType.Equals("int64_t")) { return("longLongValue"); } else if (objectiveCType.Equals("BOOL")) { return("boolValue"); } else if (objectiveCType.Equals("double")) { return("floatValue"); } else if (type is OdcmEnum) { return("intValue"); } return(null); }
private static IEnumerable <Method> ForConcreteUpcasts(OdcmType odcmClass) { return(ConfigurationService.OmitFetcherUpcastMethods ? Methods.Emtpy : TypeService.DerivedTypes[odcmClass] .Select(dr => new ConcreteUpcastMethod(odcmClass, dr))); }
public static string GetTypeString(this OdcmType @type) { switch (@type.Name) { case "String": case "Json": case "Guid": return("string"); case "Int8": case "Int16": case "Int32": case "Int64": return("int"); case "Double": return("float"); case "DateTimeOffset": case "Date": return("\\DateTime"); case "Boolean": return("bool"); case "Binary": case "Stream": return("\\GuzzleHttp\\Psr7\\Stream"); default: return(@type.Name.ToUpperFirstChar()); } }
/// <summary> /// Gets all properties for a type. /// </summary> /// <param name="type">The type to evaluate</param> /// <param name="includeInherited">Whether or not to include inherited properties</param> /// <returns>The type's immediate and inherited properties. If the type is not a class, it will return an empty result.</returns> public static IEnumerable <OdcmProperty> EvaluateProperties(this OdcmType type, bool includeInherited = true) { if (type == null) { throw new ArgumentNullException(nameof(type)); } // NOTE: Overridden properties in subtypes are not allowed in OData v4, so we don't need to worry about duplicated properties. // If the type is not a class, there are no properties to return if (type is OdcmClass @class) { // Get the list of classes that we want to get properties from (including the class which is this property's type) List <OdcmClass> classes = new List <OdcmClass>() { @class, }; // Only add base types if we want to include inherited properties if (includeInherited) { classes.AddRange(@class.GetBaseTypes()); } // Iterate over the type and its base types foreach (OdcmClass currentClass in classes) { // Add the immediate properties foreach (OdcmProperty property in currentClass.Properties) { yield return(property); } } } }
public static string GetTypeString(this OdcmType @type) { switch (@type.Name) { case "String": return("str"); case "Int8": case "Int16": case "Int32": case "Int64": return("int"); case "Double": return("float"); case "Guid": return("UUID"); case "DateTimeOffset": return("datetime"); case "Boolean": return("bool"); case "Binary": case "Stream": return("bytes"); default: return(@type.Name.ToUpperFirstChar()); } }
public UpcastMethodBase(OdcmType baseType, OdcmType derivedType) { BaseType = baseType; DerivedType = derivedType; IsPublic = true; }
public static IEnumerable <OdcmProjection> AnyOdcmProjections(this OdcmType odcmType, int count = 5) { for (int i = 0; i < count; i++) { yield return(odcmType.AnyOdcmProjection()); } }
public void It_returns_one_OdcmEntityClass_for_each_EntityType() { var testCase = new EdmxTestCase() .AddEntityType(EdmxTestCase.Keys.EntityType); var entityTypeDescendants = testCase[EdmxTestCase.Keys.EntityType].Element.Descendants(); var keyCount = entityTypeDescendants.Count(x => x.Name.LocalName == "PropertyRef"); var propertyCount = entityTypeDescendants.Count(x => x.Name.LocalName == "Property"); var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata()); OdcmType odcmEntityType = VerifyEntityType(odcmModel, testCase[EdmxTestCase.Keys.EntityType]); odcmEntityType.As <OdcmEntityClass>().Key.Count .Should() .Be(keyCount, "because each property reference added to the key of an entity type should result in an OdcmClass property"); odcmEntityType.As <OdcmEntityClass>().Properties.Count .Should() .Be(propertyCount, "because each property added to an entity type should result in an OdcmClass property"); odcmEntityType.As <OdcmEntityClass>().IsAbstract .Should() .BeFalse("because an entity type with no Abstract facet should be false in the OdcmModel"); odcmEntityType.As <OdcmEntityClass>().IsOpen .Should() .BeFalse("because an entity type with no OpenType facet should be false in the OdcmModel"); }
public static bool IsComplex(this OdcmType type) { string t = GetTypeString(type); return (!(t.Contains("int") || t == "BOOL" || t == "Byte" || t == "CGFloat")); }
public static bool IsValueType(OdcmType type) { if (type == null) { throw new ArgumentNullException("type"); } return (type is OdcmEnum || ( type is OdcmPrimitiveType && type.Namespace.Equals("Edm", StringComparison.OrdinalIgnoreCase) && ( type.Name.Equals("Boolean", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("Byte", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("Date", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("DateTimeOffset", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("Decimal", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("Double", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("Duration", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("Int16", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("Int32", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("Int64", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("SByte", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("Single", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("Guid", StringComparison.OrdinalIgnoreCase) || type.Name.Equals("TimeOfDay", StringComparison.OrdinalIgnoreCase) ) )); }
/// <summary> /// Traverses the tree of a type and its subtypes. /// </summary> /// <param name="baseType">The base type (i.e. root of the tree)</param> /// <param name="typeProcessor">The processor for handling each type</param> /// <param name="visitBaseType">If false, the provided base type is not visited (defaults to true)</param> /// <remarks> /// Types are guaranteed to be processed before the types that derive from them. /// In other words, when a type is visited, it is guaranteed that all of its base types have been processed. /// </remarks> public static void VisitAllDerivedTypes(this OdcmType baseType, Action <OdcmClass> typeProcessor, bool visitBaseType = true) { if (baseType == null) { throw new ArgumentNullException(nameof(baseType)); } if (typeProcessor == null) { throw new ArgumentNullException(nameof(typeProcessor)); } // Inheritance only applies to classes (i.e. entities and complex types) if (!(baseType is OdcmClass @class)) { return; } Stack <OdcmClass> unvisited = new Stack <OdcmClass>(); unvisited.Push(@class); while (unvisited.Any()) { // Get the next type OdcmClass type = unvisited.Pop(); // Add derived types to the unvisited list foreach (OdcmClass derivedType in type.GetImmediateDerivedTypes()) { unvisited.Push(derivedType); } // Process the type typeProcessor(type); } }
private ConcreteNavigationCollectionProperty(OdcmProperty odcmProperty) : base(odcmProperty) { FieldName = NamesService.GetConcreteFieldName(odcmProperty); OdcmType = odcmProperty.Type; PrivateSet = true; Type = new Type(new Identifier("global::System.Collections.Generic", "IList"), new Type(NamesService.GetConcreteInterfaceName(odcmProperty.Type))); }
public static bool IsComplex(this OdcmType type) { string t = type.GetTypeString(); return(!(t == "int" || t == "UUID" || t == "datetime" || t == "bool" || t == "string" || "bytes" == t || t == "float")); }
private ConcreteNavigationCollectionProperty(OdcmProperty odcmProperty) : base(odcmProperty) { FieldName = NamesService.GetConcreteFieldName(odcmProperty); OdcmType = odcmProperty.Type; PrivateSet = true; Type = new Type(NamesService.GetExtensionTypeName("IPagedCollection"), new Type(NamesService.GetConcreteInterfaceName(odcmProperty.Type))); }
public string GetType(OdcmType type) { if (type.IsComplex()) { return(type.IsSystem() ? type.GetTypeString() : type.GetTypeString() + " *"); } return(type.GetTypeString()); }
public ConcreteExecuteAsyncMethod(OdcmType odcmType) { EntityIdentifier = NamesService.GetConcreteInterfaceName(odcmType); DefiningInterface = NamesService.GetFetcherInterfaceName(odcmType); Name = "ExecuteAsync"; Parameters = Parameter.Empty; ReturnType = new Type(new Identifier("global::System.Threading.Tasks", "Task"), new Type(NamesService.GetConcreteInterfaceName(odcmType))); }
/// <summary> /// Gets the name of the ObjectFactoryCmdlet that can be generated from the given OdcmType. /// </summary> /// <param name="type">The ODCM type</param> /// <returns>The name of the ObjectFactoryCmdlet.</returns> public static CmdletName GetObjectFactoryCmdletName(this OdcmType type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } return(new CmdletName(PS.VerbsCommon.New, $"{type.Name.Pascalize()}Object")); }
/// <summary> /// Gets the name of a parameter which accepts a resource URL. /// </summary> /// <param name="type">The ODCM type of the object that will be referenced</param> /// <returns>The name of the parameter which accepts a resource URL.</returns> public static string GetResourceUrlParameterName(this OdcmType type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } return(ODataTypeUtils.GetReferenceUrlParameterName(type.FullName)); }
public static Identifier GetConcreteTypeName(OdcmType odcmType) { if (odcmType is OdcmPrimitiveType) { return(GetPrimitiveTypeName(odcmType)); } return(ResolveIdentifier(odcmType)); }
/// <summary> /// Determines whether the given type represents a media entity (which has an associated stream). /// </summary> /// <param name="type">The ODCM type</param> /// <returns>True if the given type represents a media entity, otherwise false.</returns> public static bool HasStream(this OdcmType type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } // Check if this is a media entity (i.e. has an associated stream) return(type is OdcmMediaClass); }
private void TryToMergeWithTypeCapabilities(OdcmType propertyType, ICollection <OdcmCapability> capabilities) { foreach (var typeCapability in GetCapabilitiesOrEmpty(propertyType)) { if (capabilities.SingleOrDefault(c => c.TermName == typeCapability.TermName) == null) { capabilities.Add(typeCapability); } } }
/// <summary> /// Determines whether the given type represents a data stream. /// </summary> /// <param name="type">The ODCM type</param> /// <returns>True if the given type represents a data stream, otherwise false.</returns> public static bool IsStream(this OdcmType type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } // Check if this is an "Edm.Stream" type return(type.FullName == "Edm.Stream"); }
public string GetParamString(OdcmType p) { p.GetFullType(); //if(p == null) return string.Empty; if (p.IsComplex()) { return(p.IsSystem() ? string.Empty : p.GetTypeString() + " *" + p.Name.ToLowerFirstChar()); } return(p.GetTypeString() + " " + p.Name); }
public static string GetTypeString(this OdcmType type) { if (type == null) { return("id"); } switch (type.Name) { case "String": return("NSString"); case "Int32": return("int32_t"); case "Int64": return("int64_t"); case "Int16": return("int16_t"); case "Guid": return("NSString"); case "Double": case "Float": return("CGFloat"); case "DateTimeOffset": return("NSDate"); case "Date": return("MSDate"); case "TimeOfDay": return("MSTimeOfDay"); case "Binary": return("NSString"); case "Boolean": return("BOOL"); case "Stream": return("NSStream"); case "Duration": return("Duration"); case "NSDictionary": return("NSDictionary"); default: return(Prefix + type.Name.ToUpperFirstChar()); } }
private void VerifyInheritanceLink(OdcmType odcmBaseType, OdcmType odcmEntityType) { odcmEntityType.As <OdcmEntityClass>().Base .Should() .Be(odcmBaseType, "because an entity type with a base type set should have a corresponding OdcmClass and base OdcmClass"); odcmBaseType.As <OdcmEntityClass>().Derived .Should() .Contain(odcmEntityType.As <OdcmEntityClass>(), "because an entity type with a base type set should have a correspond OdcmClass that derives from a base OdcmClass"); }