public static string DecorateNullableName(string nullableTypeName) { GenericTypeReference typeRef = (GenericTypeReference)TypeReference.FromString(nullableTypeName); TypeReference wrappedType = typeRef.GenericArguments[0]; return("Nullable<" + wrappedType.SimpleName + ">"); }
public IEntity ResolveGenericTypeReference(GenericTypeReference gtr, IEntity definition) { ResolveTypeReferenceCollection(gtr.GenericArguments); IType[] typeArguments = gtr.GenericArguments.ToArray(t => TypeSystemServices.GetType(t)); return(My <GenericsServices> .Instance.ConstructEntity(gtr, definition, typeArguments)); }
private static string DecorateNullableName(string typeName) { GenericTypeReference typeRef = (GenericTypeReference)TypeReference.FromString(typeName); TypeReference underlyingType = typeRef.GenericArguments[0]; return("Nullable<" + underlyingType.SimpleName + ">"); }
public static string GetSimpleNameForNullable(string nullableTypeName) { GenericTypeReference typeRef = (GenericTypeReference)TypeReference.FromString(nullableTypeName); TypeReference wrappedType = typeRef.GenericArguments[0]; return(wrappedType.SimpleName); }
public static TypeReference EnumerableTypeReferenceFor(TypeReference tr) { var result = new GenericTypeReference(tr.LexicalInfo, "System.Collections.Generic.IEnumerable"); result.GenericArguments.Add(tr); return(result); }
public void TestGenericName() { GenericType <int, string> o = new GenericType <int, string>(3, "42"); Type t = Type.GetType(o.GetType().FullName); TypeReference stringName = TypeReference.FromString(typeof(string).AssemblyQualifiedName); GenericTypeReference genericTypeName = (GenericTypeReference)TypeReference.FromString(t.AssemblyQualifiedName); Assert.AreEqual("Db4objects.Db4o.Tests.SharpenLang.GenericType`2", genericTypeName.SimpleName); Assert.AreEqual(2, genericTypeName.GenericArguments.Length); Assert.AreEqual(TypeReference.FromString(typeof(int).AssemblyQualifiedName), genericTypeName.GenericArguments[0]); Assert.AreEqual(stringName, genericTypeName.GenericArguments[1]); Type complexType = typeof(GenericType <string, GenericType <int, string> >); GenericTypeReference complexTypeName = (GenericTypeReference)TypeReference.FromString(complexType.AssemblyQualifiedName); Assert.AreEqual(genericTypeName.SimpleName, complexTypeName.SimpleName); Assert.AreEqual(genericTypeName.AssemblyName.FullName, complexTypeName.AssemblyName.FullName); Assert.AreEqual(2, complexTypeName.GenericArguments.Length); Assert.AreEqual(stringName, complexTypeName.GenericArguments[0]); Assert.AreEqual(genericTypeName, complexTypeName.GenericArguments[1]); Assert.AreEqual(typeof(string), TypeReference.FromString("System.String, mscorlib").Resolve()); Assert.AreEqual(t, TypeReference.FromString("Db4objects.Db4o.Tests.SharpenLang.GenericType`2[[System.Int32, mscorlib],[System.String, mscorlib]], " + GetExecutingAssemblySimpleName()).Resolve()); }
public void ResolveSimpleTypeReference(SimpleTypeReference node) { if (null != node.Entity) { return; } IEntity entity = ResolveTypeName(node); if (null == entity) { node.Entity = NameNotType(node, "not found"); return; } GenericTypeReference gtr = node as GenericTypeReference; if (null != gtr) { entity = ResolveGenericTypeReference(gtr, entity); } GenericTypeDefinitionReference gtdr = node as GenericTypeDefinitionReference; if (null != gtdr) { IType type = (IType)entity; if (gtdr.GenericPlaceholders != type.GenericInfo.GenericParameters.Length) { GenericArgumentsCountMismatch(gtdr, type); return; } } entity = Entities.PreferInternalEntitiesOverExternalOnes(entity); if (EntityType.Type != entity.EntityType) { if (EntityType.Ambiguous == entity.EntityType) { entity = AmbiguousReference(node, (Ambiguous)entity); } else if (EntityType.Error != entity.EntityType) { entity = NameNotType(node, entity.ToString()); } } else { node.Name = entity.FullName; } if (node.IsPointer && EntityType.Type == entity.EntityType) { entity = ((IType)entity).MakePointerType(); } node.Entity = entity; }
public override void OnGenericTypeReference(GenericTypeReference node) { if (node.LexicalInfo != null) { results.MapParsedNode(new MappedTypeReference(results, node)); } base.OnGenericTypeReference(node); }
private string SetFieldType(IType type) { if (type.IsNullable) { GenericTypeReference typeRef = (GenericTypeReference)TypeReference.FromString(type.FullName); TypeReference wrappedType = typeRef.GenericArguments[0]; return(wrappedType.SimpleName); } return(type.DisplayName); }
private IType[] ResolveGenericArguments(GenericTypeReference node) { IType[] arguments = new IType[node.GenericArguments.Count]; for (int i = 0; i < arguments.Length; ++i) { ResolveTypeReference(node.GenericArguments[i]); arguments[i] = (IType)node.GenericArguments[i].Entity; } return(arguments); }
public void ResolveSimpleTypeReference(SimpleTypeReference node) { if (null != node.Entity) { return; } IEntity entity = ResolveTypeName(node); if (null == entity) { node.Entity = NameNotType(node); return; } if (EntityType.Type != entity.EntityType) { if (EntityType.Ambiguous == entity.EntityType) { entity = AmbiguousReference(node, (Ambiguous)entity); } else { entity = NameNotType(node); } } else { #if NET_2_0 GenericTypeReference gtr = node as GenericTypeReference; if (null != gtr) { entity = MakeGenericType(gtr, (IType)entity); } GenericTypeDefinitionReference gtdr = node as GenericTypeDefinitionReference; if (null != gtdr) { IType type = (IType)entity; if (gtdr.GenericPlaceholders != type.GenericTypeDefinitionInfo.GenericParameters.Length) { entity = GenericArgumentsCountMismatch(gtdr, type); } } #endif node.Name = entity.FullName; } node.Entity = entity; }
private static void SetFieldType(TreeGridNode node, IType type) { if (type.IsNullable) { GenericTypeReference typeRef = (GenericTypeReference)TypeReference.FromString(type.FullName); TypeReference wrappedType = typeRef.GenericArguments[0]; node.Cells[2].Value = wrappedType.SimpleName; } else { node.Cells[2].Value = type.DisplayName; } node.Cells[2].Tag = type; }
private IEntity MakeGenericType(GenericTypeReference node, IType entity) { if (entity.GenericTypeDefinitionInfo == null) { _context.Errors.Add(CompilerErrorFactory.NotAGenericDefinition(node, node.Name)); return(TypeSystemServices.ErrorEntity); } if (entity.GenericTypeDefinitionInfo.GenericParameters.Length != node.GenericArguments.Count) { return(GenericArgumentsCountMismatch(node, entity)); } IType[] arguments = ResolveGenericArguments(node); return(entity.GenericTypeDefinitionInfo.MakeGenericType(arguments)); }
internal void Ensure(CompilerContext context, Method method) { if (method.Parameters.Count != this.Parameters.Count) { context.Errors.Add(CompilerErrorFactory.MethodArgumentCount(method, method.Name, this.Parameters.Count)); return; } //ensure return type if (method.ReturnType == null) { method.ReturnType = new SimpleTypeReference(ReturnType.FullName); } //ensure parameter types for (var i = 0; i < this.Parameters.Count; i++) { var paramtTypeRef = method.Parameters[i].Type; if (paramtTypeRef == null) { var ensuredType = this.Parameters[i].Type; TypeReference typeRef = null; if (ensuredType.IsGenericType) { var args = new SimpleTypeReference(ensuredType.GenericTypeArguments[0].Name); var name = ensuredType.Name; var tick = name.IndexOf('`'); name = name.Substring(0, tick); typeRef = new GenericTypeReference(name, args); } else { typeRef = new SimpleTypeReference(ensuredType.FullName); } method.Parameters[i].Type = typeRef; } } }
public void MergeIgnoresMatchingBaseTypes() { var foo = new SimpleTypeReference("Foo"); var bar = new SimpleTypeReference("Bar"); var fooOfBar = new GenericTypeReference("Foo", bar); var barOfFoo = new GenericTypeReference("Bar", foo); var subject = new ClassDefinition(); subject.BaseTypes.Add(bar); subject.BaseTypes.Add(fooOfBar); var node = new ClassDefinition(); node.BaseTypes.Add(foo); node.BaseTypes.Add(bar.CloneNode()); node.BaseTypes.Add(fooOfBar.CloneNode()); node.BaseTypes.Add(barOfFoo); subject.Merge(node); Assert.AreEqual(new[] { bar, fooOfBar, foo, barOfFoo }, subject.BaseTypes.ToArray()); }
override public void OnGenericTypeReference(GenericTypeReference node) { OnSimpleTypeReference(node); WriteGenericArguments(node.GenericArguments); }
public IType ResolveGenericTypeReference(GenericTypeReference gtr, IEntity definition) { ResolveTypeReferenceCollection(gtr.GenericArguments); return((IType)_context.TypeSystemServices.GenericsServices.ConstructEntity(definition, gtr, gtr.GenericArguments)); }
override public void OnGenericTypeReference(GenericTypeReference node) { CheckName(node, node.Name); }
override public void LeaveGenericTypeReference(GenericTypeReference node) { OnTypeReference(node); }
override public void OnGenericTypeReference(GenericTypeReference node) { NameResolutionService.ResolveSimpleTypeReference(node); }
public override void OnGenericTypeReference(GenericTypeReference node) { base.OnGenericTypeReference(node); OnTypeReference(node); }
public override void OnGenericTypeReference(GenericTypeReference node) { AddAsSeen(node.Entity); base.OnGenericTypeReference(node); }
public override void OnGenericTypeReference(GenericTypeReference node) { throw new NotImplementedException(); IL_0006 :; }