コード例 #1
0
        /// <summary>
        /// Get all <see cref="TypeDecl"/>s declared in the <see cref="NamespaceDecl"/>, or
        /// in any nested NamespaceDecls (recursively).
        /// </summary>
        /// <param name="recursive">True to recursively look in child NamespaceDecls, otherwise false.</param>
        /// <param name="includeNestedTypes">True to include nested types, otherwise false.</param>
        public IEnumerable <TypeDecl> GetTypeDecls(bool recursive, bool includeNestedTypes)
        {
            if (_body != null)
            {
                foreach (CodeObject codeObject in _body)
                {
                    if (codeObject is NamespaceDecl && recursive)
                    {
                        foreach (TypeDecl typeDecl in ((NamespaceDecl)codeObject).GetTypeDecls(true, includeNestedTypes))
                        {
                            yield return(typeDecl);
                        }
                    }
                    else if (codeObject is TypeDecl)
                    {
                        TypeDecl typeDecl = (TypeDecl)codeObject;
                        yield return(typeDecl);

                        if (includeNestedTypes)
                        {
                            foreach (TypeDecl nestedType in typeDecl.GetNestedTypeDecls(true, true))
                            {
                                yield return(nestedType);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        protected void GetOtherParts(List <TypeDecl> otherParts, List <string> parentTypes)
        {
            // Find any other parts of the type
            CodeObject parent = _parent;

            if (parent is NamespaceDecl)
            {
                GetOtherParts(((NamespaceDecl)parent).Namespace.Find(_name), otherParts, parentTypes);
            }
            else if (parent is TypeDecl)
            {
                // Look for other parts of a nested type in the parent type
                TypeDecl parentTypeDecl = (TypeDecl)parent;
                GetOtherParts(parentTypeDecl.Body.FindChildren(_name), otherParts, parentTypes);

                // If the parent type is also partial, then look for other parts of the parent
                // type, and look in them for additional parts of the nested type.
                if (parentTypeDecl.IsPartial)
                {
                    if (parentTypes == null)
                    {
                        parentTypes = new List <string>();
                    }
                    parentTypes.Insert(0, _name);
                    parentTypeDecl.GetOtherParts(otherParts, parentTypes);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Deep-clone the code object.
        /// </summary>
        public override CodeObject Clone()
        {
            TypeDecl clone = (TypeDecl)base.Clone();

            clone._typeParameters    = ChildListHelpers.Clone(_typeParameters, clone);
            clone._constraintClauses = ChildListHelpers.Clone(_constraintClauses, clone);
            return(clone);
        }
コード例 #4
0
        /// <summary>
        /// Remove a <see cref="TypeDecl"/> from the referenced <see cref="Namespace"/>.
        /// </summary>
        public void Remove(TypeDecl typeDecl)
        {
            NamespaceRef namespaceRef = Namespace;

            if (namespaceRef != null)
            {
                namespaceRef.Remove(typeDecl);
            }
        }
コード例 #5
0
        /// <summary>
        /// Add a <see cref="TypeDecl"/> to the referenced <see cref="Namespace"/>.
        /// </summary>
        public void Add(TypeDecl typeDecl)
        {
            NamespaceRef namespaceRef = Namespace;

            if (namespaceRef != null)
            {
                namespaceRef.Add(typeDecl);
            }
        }
コード例 #6
0
        /// <summary>
        /// Get the full name of the <see cref="FieldDecl"/>, including the namespace name.
        /// </summary>
        /// <param name="descriptive">True to display type parameters and method parameters, otherwise false.</param>
        public override string GetFullName(bool descriptive)
        {
            TypeDecl declaringType = DeclaringType;

            if (declaringType != null)
            {
                return(declaringType.GetFullName(descriptive) + "." + _name);
            }
            return(_name);
        }
コード例 #7
0
 /// <summary>
 /// Find a property on the specified <see cref="TypeDecl"/> with the specified name.
 /// </summary>
 /// <returns>A <see cref="PropertyRef"/> to the property, or an <see cref="UnresolvedRef"/> if no match was found.</returns>
 public static SymbolicRef Find(TypeDecl typeDecl, string name, bool isFirstOnLine)
 {
     if (typeDecl != null)
     {
         PropertyRef propertyRef = typeDecl.GetProperty(name);
         if (propertyRef != null)
         {
             propertyRef.IsFirstOnLine = isFirstOnLine;
             return(propertyRef);
         }
     }
     return(new UnresolvedRef(name, isFirstOnLine));
 }
コード例 #8
0
 /// <summary>
 /// Find a field on the specified <see cref="TypeDecl"/> with the specified name.
 /// </summary>
 /// <returns>A <see cref="FieldRef"/> to the field, or an <see cref="UnresolvedRef"/> if no match was found.</returns>
 public static SymbolicRef Find(TypeDecl typeDecl, string name, bool isFirstOnLine)
 {
     if (typeDecl != null)
     {
         FieldRef fieldRef = typeDecl.GetField(name);
         if (fieldRef != null)
         {
             fieldRef.IsFirstOnLine = isFirstOnLine;
             return(fieldRef);
         }
     }
     return(new UnresolvedRef(name, isFirstOnLine));
 }
コード例 #9
0
 /// <summary>
 /// Find the constructor of the specified <see cref="TypeDecl"/> with the specified signature.
 /// </summary>
 /// <returns>A <see cref="ConstructorRef"/> to the constructor, or an <see cref="UnresolvedRef"/> if no match was found.</returns>
 public static TypeRefBase Find(TypeDecl typeDecl, bool isFirstOnLine, params TypeRefBase[] parameterTypes)
 {
     if (typeDecl != null)
     {
         ConstructorRef constructorRef = typeDecl.GetConstructor(parameterTypes);
         if (constructorRef != null)
         {
             constructorRef.IsFirstOnLine = isFirstOnLine;
             return(constructorRef);
         }
         return(new UnresolvedRef(typeDecl.Name, isFirstOnLine));
     }
     return(null);
 }
コード例 #10
0
        /// <summary>
        /// Get the declaring type of the specified enum member object.
        /// </summary>
        /// <param name="enumMemberObj">The enum member object (a <see cref="EnumMemberDecl"/> or <see cref="FieldInfo"/>).</param>
        /// <returns>The <see cref="TypeRef"/> of the declaring type, or null if it can't be determined.</returns>
        public static TypeRefBase GetDeclaringType(object enumMemberObj)
        {
            TypeRefBase declaringTypeRef = null;

            if (enumMemberObj is EnumMemberDecl)
            {
                TypeDecl declaringTypeDecl = ((EnumMemberDecl)enumMemberObj).ParentEnumDecl;
                declaringTypeRef = (declaringTypeDecl != null ? declaringTypeDecl.CreateRef() : null);
            }
            else if (enumMemberObj is FieldInfo)
            {
                declaringTypeRef = TypeRef.Create(((FieldInfo)enumMemberObj).DeclaringType);
            }
            return(declaringTypeRef);
        }
コード例 #11
0
        /// <summary>
        /// Get the declaring type of the specified event object.
        /// </summary>
        /// <param name="eventObj">The event object (an <see cref="EventDecl"/> or <see cref="EventInfo"/>).</param>
        /// <returns>The <see cref="TypeRef"/> of the declaring type, or null if it can't be determined.</returns>
        public static TypeRefBase GetDeclaringType(object eventObj)
        {
            TypeRefBase declaringTypeRef;

            if (eventObj is EventDecl)
            {
                TypeDecl declaringTypeDecl = ((EventDecl)eventObj).DeclaringType;
                declaringTypeRef = (declaringTypeDecl != null ? declaringTypeDecl.CreateRef() : null);
            }
            else //if (eventObj is EventInfo)
            {
                declaringTypeRef = TypeRef.Create(((EventInfo)eventObj).DeclaringType);
            }
            return(declaringTypeRef);
        }
コード例 #12
0
        /// <summary>
        /// Get the declaring type of the specified property object.
        /// </summary>
        /// <param name="propertyObj">The property object (a <see cref="PropertyDeclBase"/> or <see cref="PropertyInfo"/>).</param>
        /// <returns>The <see cref="TypeRef"/> of the declaring type, or null if it can't be determined.</returns>
        public static TypeRefBase GetDeclaringType(object propertyObj)
        {
            TypeRefBase declaringTypeRef = null;

            if (propertyObj is PropertyDeclBase)
            {
                TypeDecl declaringTypeDecl = ((PropertyDeclBase)propertyObj).DeclaringType;
                declaringTypeRef = (declaringTypeDecl != null ? declaringTypeDecl.CreateRef() : null);
            }
            else if (propertyObj is PropertyInfo)
            {
                declaringTypeRef = TypeRef.Create(((PropertyInfo)propertyObj).DeclaringType);
            }
            return(declaringTypeRef);
        }
コード例 #13
0
        /// <summary>
        /// Get the declaring type of the specified field object.
        /// </summary>
        /// <param name="fieldObj">The field object (a <see cref="FieldDecl"/> or <see cref="FieldInfo"/>).</param>
        /// <returns>The <see cref="TypeRef"/> of the declaring type, or null if it can't be determined.</returns>
        public static TypeRefBase GetDeclaringType(object fieldObj)
        {
            TypeRefBase declaringTypeRef;

            if (fieldObj is FieldDecl)
            {
                TypeDecl declaringTypeDecl = ((FieldDecl)fieldObj).DeclaringType;
                declaringTypeRef = (declaringTypeDecl != null ? declaringTypeDecl.CreateRef() : null);
            }
            else //if (fieldObj is FieldInfo)
            {
                declaringTypeRef = TypeRef.Create(((FieldInfo)fieldObj).DeclaringType);
            }
            return(declaringTypeRef);
        }
コード例 #14
0
        /// <summary>
        /// Get all nested type declarations of the <see cref="TypeDecl"/>.
        /// </summary>
        /// <param name="recursive">True to recursively return all nested type declarations, otherwise false.</param>
        /// <param name="currentPartOnly">True to get nested types from current part only if the TypeDecl is partial, otherwise false.</param>
        public IEnumerable <TypeDecl> GetNestedTypeDecls(bool recursive, bool currentPartOnly)
        {
            if (_body != null)
            {
                foreach (CodeObject codeObject in _body)
                {
                    if (codeObject is TypeDecl)
                    {
                        TypeDecl typeDecl = (TypeDecl)codeObject;
                        yield return(typeDecl);

                        if (recursive)
                        {
                            foreach (TypeDecl nestedType in typeDecl.GetNestedTypeDecls(true, currentPartOnly))
                            {
                                yield return(nestedType);
                            }
                        }
                    }
                }
            }
            if (IsPartial && !currentPartOnly)
            {
                foreach (TypeDecl otherPart in GetOtherParts())
                {
                    if (otherPart.Body != null)
                    {
                        foreach (CodeObject codeObject in otherPart.Body)
                        {
                            if (codeObject is TypeDecl)
                            {
                                TypeDecl typeDecl = (TypeDecl)codeObject;
                                yield return(typeDecl);

                                if (recursive)
                                {
                                    foreach (TypeDecl nestedType in typeDecl.GetNestedTypeDecls(true))
                                    {
                                        yield return(nestedType);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// Get the full name of the <see cref="INamedCodeObject"/>, including any namespace name.
        /// </summary>
        /// <param name="descriptive">True to display type parameters and method parameters, otherwise false.</param>
        public override string GetFullName(bool descriptive)
        {
            string name = Name;

            if (descriptive)
            {
                if (_typeParameters != null && _typeParameters.Count > 0)
                {
                    name += TypeDecl.GetTypeParametersAsString(_typeParameters);
                }
                name += GetParametersAsString();
            }
            if (_parent is TypeDecl)
            {
                name = ((TypeDecl)_parent).GetFullName(descriptive) + "." + name;
            }
            return(name);
        }
コード例 #16
0
 private void GetOtherParts(TypeDecl typeDecl, List <TypeDecl> otherParts, List <string> parentTypes)
 {
     if (typeDecl != this)
     {
         if (parentTypes == null)
         {
             if (typeDecl.TypeParameterCount == TypeParameterCount)
             {
                 otherParts.Add(typeDecl);
             }
         }
         else
         {
             List <string> newList    = new List <string>(parentTypes);
             string        parentType = parentTypes[0];
             newList.RemoveAt(0);
             GetOtherParts(typeDecl.Body.FindChildren(parentType), otherParts, newList.Count > 0 ? newList : null);
         }
     }
 }
コード例 #17
0
 /// <summary>
 /// Find the base virtual method for this method if it's an override.
 /// </summary>
 public MethodRef FindBaseMethod()
 {
     if (IsOverride)
     {
         TypeDecl declaringType = DeclaringType;
         if (declaringType != null)
         {
             TypeRef baseTypeRef = declaringType.GetBaseType();
             if (baseTypeRef != null)
             {
                 TypeRefBase[] parameterTypes = null;
                 if (_parameters != null)
                 {
                     parameterTypes = Enumerable.ToArray(Enumerable.Select <ParameterDecl, TypeRefBase>(_parameters, delegate(ParameterDecl parameterDecl) { return(parameterDecl.Type.SkipPrefixes() as TypeRefBase); }));
                 }
                 return(baseTypeRef.GetMethod(Name, parameterTypes));
             }
         }
     }
     return(null);
 }
コード例 #18
0
 /// <summary>
 /// Create a <see cref="NewObject"/>.
 /// </summary>
 /// <param name="typeDecl">The TypeDecl of the object being created.</param>
 /// <param name="parameters">The constructor parameters (if any).</param>
 public NewObject(TypeDecl typeDecl, params Expression[] parameters)
     : base(typeDecl.CreateRef(), parameters)
 {
 }
コード例 #19
0
 /// <summary>
 /// Add a <see cref="TypeDecl"/> to the namespace.
 /// </summary>
 public void Add(TypeDecl typeDecl)
 {
     ((Namespace)_reference).Add(typeDecl);
 }
コード例 #20
0
 /// <summary>
 /// Add a <see cref="TypeDecl"/> to the dictionary.
 /// </summary>
 public void Add(TypeDecl typeDecl)
 {
     Add(typeDecl.Name, typeDecl);
 }
コード例 #21
0
 /// <summary>
 /// Remove the specified <see cref="TypeDecl"/> from the dictionary.
 /// </summary>
 public void Remove(TypeDecl typeDecl)
 {
     Remove(typeDecl.Name, typeDecl);
 }
コード例 #22
0
 /// <summary>
 /// Check if the specified TypeDecl is identical to OR has the same name/namespace as the current one (could be different parts).
 /// </summary>
 public bool IsSameAs(TypeDecl typeDecl)
 {
     return(this == typeDecl || (_name == typeDecl.Name && (_typeParameters != null ? _typeParameters.Count : 0) == typeDecl.TypeParameterCount && GetNamespace() == typeDecl.GetNamespace()));
 }
コード例 #23
0
 /// <summary>
 /// Add the specified <see cref="TypeDecl"/> to the current <see cref="Namespace"/>.
 /// </summary>
 public void Add(TypeDecl typeDecl)
 {
     lock (this)
         _children.Add(typeDecl);
 }
コード例 #24
0
 /// <summary>
 /// Remove the specified <see cref="TypeDecl"/> from the current <see cref="Namespace"/>.
 /// </summary>
 public void Remove(TypeDecl typeDecl)
 {
     lock (this)
         _children.Remove(typeDecl);
 }
コード例 #25
0
 /// <summary>
 /// Add the specified <see cref="TypeDecl"/> to the group.
 /// </summary>
 public void Add(TypeDecl typeDecl)
 {
     Add((object)typeDecl);
 }
コード例 #26
0
 /// <summary>
 /// Find a property on the specified <see cref="TypeDecl"/> with the specified name.
 /// </summary>
 /// <returns>A <see cref="PropertyRef"/> to the property, or an <see cref="UnresolvedRef"/> if no match was found.</returns>
 public static SymbolicRef Find(TypeDecl typeDecl, string name)
 {
     return(Find(typeDecl, name, false));
 }
コード例 #27
0
 /// <summary>
 /// Find the constructor of the specified <see cref="TypeDecl"/> with the specified signature.
 /// </summary>
 /// <returns>A <see cref="ConstructorRef"/> to the constructor, or an <see cref="UnresolvedRef"/> if no match was found.</returns>
 public static TypeRefBase Find(TypeDecl typeDecl, params TypeRefBase[] parameterTypes)
 {
     return(Find(typeDecl, false, parameterTypes));
 }
コード例 #28
0
 /// <summary>
 /// Remove a <see cref="TypeDecl"/> from the namespace.
 /// </summary>
 public void Remove(TypeDecl typeDecl)
 {
     ((Namespace)_reference).Remove(typeDecl);
 }