/// <summary>InspectConstructor
        /// <para></para>
        /// </summary>
        public Dictionary <int, ParameterDetail> InspectMethods(Type CurrentType)
        {
            ParameterInfo[]      parameters                    = null;
            ParameterDetail      ObjParameterDetail            = null;
            AnnotationDefination ObjAnnotationDefination       = null;
            Dictionary <int, ParameterDetail> CtorParams       = new Dictionary <int, ParameterDetail>();
            List <string>           TypeCollections            = null;
            ParameterNameCollection ObjParameterNameCollection = null;
            List <string>           GenericParameterTypeName   = new List <string>();

            try
            {
                int index = 0;
                TypeCollections = new List <string>();
                foreach (var ctor in CurrentType.GetConstructors())
                {
                    ObjParameterDetail = new ParameterDetail();
                    parameters         = ctor.GetParameters();
                    foreach (var param in parameters)
                    {
                        var    NewType       = param.ParameterType;
                        String FullNameSpace = NewType.AssemblyQualifiedName;
                        if (FullNameSpace != null)
                        {
                            if (FullNameSpace != null)
                            {
                                ObjParameterNameCollection = new ParameterNameCollection();
                                ObjParameterDetail.WrapperFullDescription = "";
                                if (FullNameSpace.IndexOf("`") != -1)
                                {
                                    ObjParameterNameCollection.Name = FullNameSpace;
                                }
                                else
                                {
                                    ObjParameterNameCollection.Name = FullNameSpace.Split(new char[] { ',' })[0];
                                }
                                ObjParameterNameCollection.ArgumentName = param.Name;
                                ObjParameterDetail.Parameters.Add(ObjParameterNameCollection);
                            }
                            else
                            {
                                throw new ApplicationException("Unable to resolve constructor paramter for class: " + NewType.Name);
                            }
                        }
                        else if (NewType.AssemblyQualifiedName == null)
                        {
                            if (NewType.IsGenericType)
                            {
                                if (NewType.AssemblyQualifiedName == null)
                                {
                                    if (NewType.GenericTypeArguments.Count() > 0)
                                    {
                                        ObjParameterNameCollection = BuildParameter(NewType, ref GenericParameterTypeName);
                                    }
                                    if (ObjParameterNameCollection != null)
                                    {
                                        TypeCollections.Add(ObjParameterNameCollection.Name);
                                    }
                                }
                            }
                            else
                            {
                                ObjParameterNameCollection = BuildParameter(NewType, ref GenericParameterTypeName);
                                if (ObjParameterNameCollection != null)
                                {
                                    TypeCollections.Add(ObjParameterNameCollection.Name);
                                }
                            }
                            ObjParameterDetail.WrapperFullDescription = "";
                            if (ObjParameterNameCollection == null)
                            {
                                ObjParameterNameCollection = new ParameterNameCollection {
                                    Name = NewType.Name
                                }
                            }
                            ;
                            ObjParameterDetail.Parameters.Add(ObjParameterNameCollection);
                        }
                    }

                    IEnumerable <Attribute> CtorAttributes = ctor.GetCustomAttributes();
                    foreach (var attr in CtorAttributes)
                    {
                        ObjAnnotationDefination = new AnnotationDefination();
                        ObjAnnotationDefination.AnnotationName = attr.GetType().Name;
                        ObjAnnotationDefination.AppliedOn      = "ctor";
                        if (ObjAnnotationDefination.AnnotationName == "Enabled")
                        {
                            ObjAnnotationDefination.OrderNo = ((BottomhalfCore.Annotations.Enabled)attr).Order;
                        }
                        if (ObjAnnotationDefination.AnnotationName == "File")
                        {
                            ObjAnnotationDefination.Filename = ((BottomhalfCore.Annotations.File)attr).Filename;
                        }
                        if (ObjParameterDetail.AnnotationDetail == null)
                        {
                            ObjParameterDetail.AnnotationDetail = new List <AnnotationDefination>();
                        }
                        ObjParameterDetail.AnnotationDetail.Add(ObjAnnotationDefination);
                    }

                    if ((ObjParameterDetail.AnnotationDetail != null && ObjParameterDetail.AnnotationDetail.Count > 0) || ObjParameterDetail.Parameters.Count > 0)
                    {
                        CtorParams.Add(++index, ObjParameterDetail);
                    }
                }
                if (TypeCollections.Count() > 0)
                {
                    ObjParameterDetail.IsGeneric = true;
                    if (GenericParameterTypeName.Count() > 0)
                    {
                        ObjParameterDetail.GenericParameterTypeName = GenericParameterTypeName;
                    }
                    else
                    {
                        GenericParameterTypeName = null;
                    }
                }

                return(CtorParams);
            }
            catch (BeanException _beanEx)
            {
                _beanEx.LocationTrack(this.GetType().FullName + "InspectConstructor()");
                throw _beanEx;
            }
            catch (Exception ex)
            {
                BeanException ObjBeanException = new BeanException();
                ObjBeanException.LocationTrack(this.GetType().FullName + "InspectConstructor()");
                ObjBeanException.SetMessage(ex.Message);
                throw ObjBeanException;
            }
        }
Exemplo n.º 2
0
        /// <summary>InspectClassAnnotation
        /// <para></para>
        /// </summary>
        public ClassAnnotationDetail InspectAnnotations(Type CurrentType, TypeRefCollection refCollection)
        {
            ClassAnnotationDetail classAnnotationDetail;
            List <AopDetail>      aopDetailLst = null;
            Boolean DocumentGenerationFlag     = false;
            List <AnnotationDefination> ObjAnnotationDefinationList = new List <AnnotationDefination>();
            AnnotationDefination        ObjAnnotationDefination     = null;

            try
            {
                classAnnotationDetail = new ClassAnnotationDetail();
                foreach (var Annotate in CurrentType.CustomAttributes)
                {
                    if (Annotate.AttributeType.Name == Constants.Scoped)
                    {
                        refCollection.IsScoped = true;
                    }
                    else if (Annotate.AttributeType.Name == Constants.SingleTon)
                    {
                        refCollection.IsSingleTon = true;
                    }
                    else if (Annotate.AttributeType.Name == Constants.Transient)
                    {
                        refCollection.IsTransient = true;
                    }
                    else if (Annotate.AttributeType.Name == "GenerateDoc")
                    {
                        DocumentGenerationFlag = true;
                    }
                    else
                    {
                        ObjAnnotationDefinationList.Add(new AnnotationDefination {
                            AnnotationName = Annotate.AttributeType.Name
                        });
                        if (Annotate.AttributeType.FullName.IndexOf("BottomhalfCore.Annotations") != -1)
                        {
                            if (Annotate.AttributeType.Name == "NoCheck")
                            {
                                container.AddNoCheckClass(CurrentType.FullName.ToLower());
                            }

                            if (IsAopApplied(Annotate.AttributeType.Name))
                            {
                                string ReturnType       = Annotate.ConstructorArguments[0].Value.ToString();
                                string NameSpace        = Annotate.ConstructorArguments[1].Value.ToString();
                                string MethodExpression = Annotate.ConstructorArguments[2].Value.ToString();
                                string Arguments        = Annotate.ConstructorArguments[3].Value.ToString();
                                if (!string.IsNullOrEmpty(ReturnType) && !string.IsNullOrEmpty(NameSpace) && !string.IsNullOrEmpty(MethodExpression) && !string.IsNullOrEmpty(Arguments))
                                {
                                    AopDetail ObjAopDetail = new AopDetail();
                                    ObjAopDetail.AOPType                  = Annotate.AttributeType.Name;
                                    ObjAopDetail.ForArgumentType          = Arguments;
                                    ObjAopDetail.ForNameSpace             = NameSpace;
                                    ObjAopDetail.ForWhichReturnType       = ReturnType;
                                    ObjAopDetail.MethodExpression         = MethodExpression;
                                    ObjAopDetail.AspectClassName          = CurrentType.Name;
                                    ObjAopDetail.AspectFullyQualifiedName = CurrentType.Namespace;
                                    aopDetailLst.Add(ObjAopDetail);
                                }
                            }
                            else
                            {
                                if (ObjAnnotationDefination == null)
                                {
                                    ObjAnnotationDefination = new AnnotationDefination();
                                }
                                ObjAnnotationDefination.AnnotationName = Annotate.AttributeType.Name;
                                foreach (var CtorArgs in Annotate.ConstructorArguments)
                                {
                                    if (CtorArgs.Value != null)
                                    {
                                        ObjAnnotationDefination.Value.Add(CtorArgs.Value);
                                        ObjAnnotationDefination.AppliedOn = "class";
                                        if (Annotate.AttributeType.Name == "Auth")
                                        {
                                            if (ObjAnnotationDefination.Value.Count > 0)
                                            {
                                                string TokenName = ObjAnnotationDefination.Value.FirstOrDefault();
                                                if (!string.IsNullOrEmpty(TokenName))
                                                {
                                                    container.SetTokenName(TokenName);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                classAnnotationDetail.annotationDefination = ObjAnnotationDefinationList;
                classAnnotationDetail.aopDetailLst         = aopDetailLst;
                classAnnotationDetail.IsCodeDocRequired    = DocumentGenerationFlag;
                return(classAnnotationDetail);
            }
            catch (BeanException _beanEx)
            {
                _beanEx.LocationTrack(this.GetType().FullName + "InspectClassAnnotation()");
                throw _beanEx;
            }
            catch (Exception ex)
            {
                BeanException ObjBeanException = new BeanException();
                ObjBeanException.LocationTrack(this.GetType().FullName + "InspectClassAnnotation()");
                ObjBeanException.SetMessage(ex.Message);
                throw ObjBeanException;
            }
        }