Ejemplo n.º 1
0
        /// <summary>
        /// Initialises a new instance of the ClassSyntax class.
        /// </summary>
        /// <param name="type">The type to retrieve syntax details for.</param>
        public DelegateSyntax(TypeDef type)
        {
            _type = type;

            MethodDef invokeMethod = _type.Methods.Find(m => m.Name == "Invoke");

            _invokeMethodSyntax = new MethodSyntax(invokeMethod);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a correctly typed and instantiated <see cref="Syntax"/> class
        /// for the specified <paramref name="member"/>.
        /// </summary>
        /// <param name="member">The member to create a Syntax instance for.</param>
        /// <returns>The instantiated Syntax class.</returns>
        private static Syntax CreateSyntax(ReflectedMember member)
        {
            Syntax syntax = null;

            if (member is TypeDef)
            {
                TypeDef type = member as TypeDef;
                if (type.IsInterface)
                {
                    syntax = new InterfaceSyntax(type);
                }
                else if (type.IsEnumeration)
                {
                    syntax = new EnumSyntax(type);
                }
                else if (type.IsStructure)
                {
                    syntax = new StructSyntax(type);
                }
                else if (type.IsDelegate)
                {
                    syntax = new DelegateSyntax(type);
                }
                else
                {
                    syntax = new ClassSyntax(type);
                }
            }
            else if (member is FieldDef)
            {
                FieldDef field = member as FieldDef;
                if (field.IsConstant)
                {
                    syntax = new ConstantSyntax(field);
                }
                else
                {
                    syntax = new FieldSyntax(field);
                }
            }
            else if (member is MethodDef)
            {
                MethodDef method = member as MethodDef;
                if (method.IsConstructor)
                {
                    syntax = new ConstructorSyntax(method);
                }
                else if (method.IsOperator)
                {
                    syntax = new OperatorSyntax(method);
                }
                else
                {
                    syntax = new MethodSyntax(method);
                }
            }
            else if (member is EventDef)
            {
                syntax = new EventSyntax(member as EventDef);
            }
            else if (member is PropertyDef)
            {
                // A property can be a noram property or an indexor
                PropertyDef property = member as PropertyDef;
                if (property.IsIndexer())
                {
                    syntax = new IndexorSyntax(member as PropertyDef);
                }
                else
                {
                    syntax = new PropertySyntax(member as PropertyDef);
                }
            }

            return(syntax);
        }