コード例 #1
0
 public ICliMetadataTypeDefinitionTableRow FindType(IGeneralTypeUniqueIdentifier uniqueIdentifier)
 {
     if (uniqueIdentifier.ParentIdentifier != null)
     {
         var cliType = IdentityManager.ObtainTypeReference(this.FindType(uniqueIdentifier.ParentIdentifier));
         if (cliType is ICliTypeParent)
         {
             var clipt = (ICliTypeParent)cliType;
             return(clipt.FindType(uniqueIdentifier));
         }
     }
     if (uniqueIdentifier.Name.Contains('`'))
     {
         return(this.FindType(uniqueIdentifier.Namespace.Name, uniqueIdentifier.Name));
     }
     else if (uniqueIdentifier is IGenericTypeUniqueIdentifier)
     {
         var genericUniqueId = uniqueIdentifier as IGenericTypeUniqueIdentifier;
         if (genericUniqueId.TypeParameters > 0)
         {
             return(this.FindType(uniqueIdentifier.Namespace.Name, string.Format("{0}`{1}", uniqueIdentifier.Name, ((IGenericTypeUniqueIdentifier)(uniqueIdentifier)).TypeParameters)));
         }
     }
     if (uniqueIdentifier.Namespace == null)
     {
         return(this.FindType(null, uniqueIdentifier.Name));
     }
     else
     {
         return(this.FindType(uniqueIdentifier.Namespace.Name, uniqueIdentifier.Name));
     }
 }
コード例 #2
0
        public override IType GetType(IGeneralTypeUniqueIdentifier identifier)
        {
            var typeDefinition = GetTypeDefinition(identifier);

            if (typeDefinition != null)
            {
                return(this.IdentityManager.ObtainTypeReference(typeDefinition));
            }
            return(null);
        }
コード例 #3
0
        private ICliMetadataTypeDefinitionTableRow GetTypeDefinition(IGeneralTypeUniqueIdentifier identifier)
        {
            var nestingHierarchy = identifier.GetNestingHierarchy();
            ICliMetadataTypeDefinitionTableRow typeDefinition = null;
            bool first = true;

            while (nestingHierarchy.Count > 0)
            {
                var current = nestingHierarchy.Pop();
                if (first)
                {
                    /* *
                     * Going off of a true namespace setup.
                     * */
                    var topLevelType = this.FindType(current);
                    if (topLevelType == null)
                    {
                        return(null);
                    }
                    typeDefinition = topLevelType;
                    first          = false;
                }
                else
                {
                    bool   found = false;
                    string name  = current.Name;
                    if (current is IGenericTypeUniqueIdentifier)
                    {
                        var genericCurrent = ((IGenericTypeUniqueIdentifier)current);
                        if (!genericCurrent.UsesNonstandardGraveAccentElement)
                        {
                            name = string.Format("{0}`{1}", name, genericCurrent.TypeParameters);
                        }
                    }
                    foreach (var nestedType in typeDefinition.NestedClasses)
                    {
                        if (nestedType.Name == name &&
                            current.Namespace == null && string.IsNullOrEmpty(nestedType.Namespace) ||
                            (current.Namespace != null && nestedType.Namespace == current.Namespace.Name))
                        {
                            typeDefinition = nestedType;
                            found          = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        return(null);
                    }
                }
            }
            return(typeDefinition);
        }
コード例 #4
0
        public static Stack <IGeneralTypeUniqueIdentifier> GetNestingHierarchy(this IGeneralTypeUniqueIdentifier identifier)
        {
            var nestingHierarchy = new Stack <IGeneralTypeUniqueIdentifier>();
            var id = (IGeneralTypeUniqueIdentifier)identifier;

            while (id != null)
            {
                nestingHierarchy.Push(id);
                id = id.ParentIdentifier;
            }
            return(nestingHierarchy);
        }
コード例 #5
0
            private string ReadBoilerplateAttribute(IGeneralTypeUniqueIdentifier attributeTypeIdentifier)
            {
                var attributeType = owner.IdentityManager.ObtainTypeReference(attributeTypeIdentifier, this.owner);

                if (owner.IsDefined(attributeType))
                {
                    var attributeDef  = owner.Metadata[attributeType];
                    var firstCtorVal  = attributeDef.Parameters.FirstOrDefault();
                    var stringTypeRef = owner.IdentityManager.ObtainTypeReference(RuntimeCoreType.String, owner);
                    if (firstCtorVal.ParameterType == stringTypeRef)
                    {
                        return(firstCtorVal.Value as string);
                    }
                }
                return(null);
            }
コード例 #6
0
 public IType ObtainTypeReference(IGeneralTypeUniqueIdentifier typeIdentity, IAssembly originatingAssembly)
 {
     /* *
      * With no assembly as a guide, a guess has to be made.
      * */
     if (typeIdentity.Assembly == null)
     {
         if (this.RuntimeEnvironment.UseCoreLibrary)
         {
             var coreLibraryId  = this.RuntimeEnvironment.CoreLibraryIdentifier;
             var coreLibrary    = this.ObtainAssemblyReference(coreLibraryId);
             var cliCoreLibrary = (ICliAssembly)coreLibrary;
             var type           = cliCoreLibrary.GetType(typeIdentity);
             if (type != null)
             {
                 return(type);
             }
         }
         if (originatingAssembly != null)
         {
             var originatingSearch = originatingAssembly.GetType(typeIdentity);
             if (originatingSearch != null)
             {
                 return(originatingSearch);
             }
             foreach (var assembly in originatingAssembly.References.Values)
             {
                 var test = assembly.GetType(typeIdentity);
                 if (test != null)
                 {
                     return(test);
                 }
             }
         }
     }
     else
     {
         var assembly = this.ObtainAssemblyReference(typeIdentity.Assembly);
         var type     = assembly.GetType(typeIdentity);
         if (type != null)
         {
             return(type);
         }
     }
     throw new TypeLoadException(string.Format("Could not load {0}.", typeIdentity.ToString()));
 }
コード例 #7
0
        public ICliMetadataTypeDefinitionTableRow FindType(IGeneralTypeUniqueIdentifier uniqueIdentifier)
        {
            var myID  = this.UniqueIdentifier;
            var depth = ((IGeneralTypeUniqueIdentifier)this.UniqueIdentifier).GetDepth();

            /* *
             * If the hierarchy of the unique identifier is properly formed, then
             * the current type's identifier should be contained within it.
             * */
            var hierarchy = uniqueIdentifier.GetNestingHierarchy().Skip(depth - 1);
            var first     = hierarchy.FirstOrDefault();

            if (first == null ||
                !myID.Equals(first))
            {
                return(null);
            }
            ICliMetadataTypeDefinitionTableRow typeDefinition = this.MetadataEntry;
            var remainingHierarchy = new Stack <IGeneralTypeUniqueIdentifier>(hierarchy.Skip(1).Reverse());

            while (remainingHierarchy.Count > 0)
            {
                var  current = remainingHierarchy.Pop();
                bool found   = false;
                foreach (var nestedType in typeDefinition.NestedClasses)
                {
                    if (nestedType.Name == current.Name &&
                        current.Namespace == null && string.IsNullOrEmpty(nestedType.Namespace) ||
                        (current.Namespace != null && nestedType.Namespace == current.Namespace.Name))
                    {
                        typeDefinition = nestedType;
                        found          = true;
                        break;
                    }
                }
                if (!found)
                {
                    return(null);
                }
            }
            return(typeDefinition);
        }
コード例 #8
0
        public IType ObtainTypeReference(IGeneralTypeUniqueIdentifier typeIdentity)
        {
            return(ObtainTypeReference(typeIdentity, null));

            /* *
             * With no assembly as a guide, a guess has to be made.
             * */
            if (typeIdentity.Assembly == null)
            {
                if (this.RuntimeEnvironment.UseCoreLibrary)
                {
                    var coreLibraryId = this.RuntimeEnvironment.CoreLibraryIdentifier;
                    var coreLibrary   = this.ObtainAssemblyReference(coreLibraryId);
                    var type          = coreLibrary.GetType(typeIdentity);
                    if (type != null)
                    {
                        return(type);
                    }
                    foreach (var assembly in this.loadedAssemblies.Values)
                    {
                        if (assembly.UniqueIdentifier == coreLibraryId)
                        {
                            continue;
                        }
                        else if ((type = assembly.GetType(typeIdentity)) != null)
                        {
                            return(type);
                        }
                    }
                }
            }
            else
            {
                var assembly = this.ObtainAssemblyReference(typeIdentity.Assembly);
                var type     = assembly.GetType(typeIdentity);
                if (type != null)
                {
                    return(type);
                }
            }
            throw new TypeLoadException(string.Format("Could not load {0}.", typeIdentity.ToString()));
        }
コード例 #9
0
 public ICliMetadataTypeDefinitionTableRow FindType(IGeneralTypeUniqueIdentifier uniqueIdentifier)
 {
     return(CliCommon.FindTypeImplementation(this.IdentityManager, this.Assembly, uniqueIdentifier, this.namespaceInfo));
 }
コード例 #10
0
 public ICliMetadataTypeDefinitionTableRow FindType(IGeneralTypeUniqueIdentifier uniqueIdentifier)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
 /// <summary>
 /// Returns the <see cref="IType"/> for the <paramref name="identifier"/>
 /// provided.
 /// </summary>
 /// <param name="identifier">The <see cref="IGeneralTypeUniqueIdentifier"/> to obtain the
 /// <see cref="IType"/> of.</param>
 /// <returns>A <see cref="IType"/> from the current <see cref="AssemblyBase"/>
 /// which is represented by the <paramref name="identifier"/>.</returns>
 public abstract IType GetType(IGeneralTypeUniqueIdentifier identifier);