private IfBuilder BuildTryGetEntityIf(RuntimeTypeInfo entityType) { return(IfBuilder .New() .SetCondition(MethodCallBuilder .Inline() .SetMethodName(_session, "CurrentSnapshot", "TryGetEntity") .AddArgument(_entityId) .AddOutArgument(_entity, entityType.ToString()))); }
private void AddComplexDataHandler( CSharpSyntaxGeneratorSettings settings, ClassBuilder classBuilder, ConstructorBuilder constructorBuilder, MethodBuilder method, ComplexTypeDescriptor complexTypeDescriptor, HashSet<string> processed, bool isNonNullable) { RuntimeTypeInfo typeInfo = complexTypeDescriptor.ParentRuntimeType ?? throw new InvalidOperationException(); method .AddParameter(_dataParameterName) .SetType(typeInfo.ToString().MakeNullable(!isNonNullable)) .SetName(_dataParameterName); if (settings.IsStoreEnabled()) { method .AddParameter(_snapshot) .SetType(TypeNames.IEntityStoreSnapshot); } if (!isNonNullable) { method.AddCode(EnsureProperNullability(_dataParameterName, isNonNullable)); } const string returnValue = nameof(returnValue); method.AddCode($"{complexTypeDescriptor.RuntimeType.Name}? {returnValue};"); method.AddEmptyLine(); GenerateIfForEachImplementedBy( method, complexTypeDescriptor, o => GenerateComplexDataInterfaceIfClause(settings, o, returnValue)); method.AddCode($"return {returnValue};"); AddRequiredMapMethods( settings, _dataParameterName, complexTypeDescriptor, classBuilder, constructorBuilder, processed); }
// // This is a port of the desktop CLR's RuntimeType.FormatTypeName() routine. This routine is used by various Reflection ToString() methods // to display the name of a type. Do not use for any other purpose as it inherits some pretty quirky desktop behavior. // // The Project N version takes a raw metadata handle rather than a completed type so that it remains robust in the face of missing metadata. // public static String FormatTypeName(this RuntimeTypeInfo runtimeType) { try { // Though we wrap this in a try-catch as a failsafe, this code must still strive to avoid triggering MissingMetadata exceptions // (non-error exceptions are very annoying when debugging.) // Legacy: this doesn't make sense, why use only Name for nested types but otherwise // ToString() which contains namespace. RuntimeTypeInfo rootElementType = runtimeType; while (rootElementType.HasElementType) { rootElementType = rootElementType.InternalRuntimeElementType; } if (rootElementType.IsNested) { String name = runtimeType.InternalNameIfAvailable; return(name == null ? UnavailableType : name); } // Legacy: why removing "System"? Is it just because C# has keywords for these types? // If so why don't we change it to lower case to match the C# keyword casing? FoundationTypes foundationTypes = ReflectionCoreExecution.ExecutionDomain.FoundationTypes; String typeName = runtimeType.ToString(); if (typeName.StartsWith("System.")) { foreach (Type pt in ReflectionCoreExecution.ExecutionDomain.PrimitiveTypes) { if (pt.Equals(rootElementType) || rootElementType.Equals(foundationTypes.SystemVoid)) { typeName = typeName.Substring("System.".Length); break; } } } return(typeName); } catch (Exception) { return(UnavailableType); } }
public static string GetParseMethod(RuntimeTypeInfo serializationType) { return(serializationType.ToString() switch { TypeNames.String => nameof(JsonElement.GetString), TypeNames.Uri => nameof(JsonElement.GetString), TypeNames.Byte => nameof(JsonElement.GetByte), TypeNames.ByteArray => nameof(JsonElement.GetBytesFromBase64), TypeNames.Int16 => nameof(JsonElement.GetInt16), TypeNames.Int32 => nameof(JsonElement.GetInt32), TypeNames.Int64 => nameof(JsonElement.GetInt64), TypeNames.UInt16 => nameof(JsonElement.GetUInt16), TypeNames.UInt32 => nameof(JsonElement.GetUInt32), TypeNames.UInt64 => nameof(JsonElement.GetUInt64), TypeNames.Single => nameof(JsonElement.GetSingle), TypeNames.Double => nameof(JsonElement.GetDouble), TypeNames.Decimal => nameof(JsonElement.GetDecimal), TypeNames.DateTimeOffset => nameof(JsonElement.GetString), TypeNames.DateTime => nameof(JsonElement.GetString), TypeNames.TimeSpan => nameof(JsonElement.GetString), TypeNames.Boolean => nameof(JsonElement.GetBoolean), TypeNames.Guid => nameof(JsonElement.GetGuid), _ => throw new NotSupportedException("Serialization format not supported.") });