public void Cref01()
        {
            var cref = new CRef("M:TestLibrary.SomeNamespace.Class6`1.#ctor(`0)");
            var m    = cref.ToMethod();

            Assert.IsNotNull(m);
        }
Exemplo n.º 2
0
        public void ToMethod03()
        {
            var cref   = new CRef("M:TestLibrary.SomeNamespace.Class1.Foo``4(``0,``1,``2)");
            var method = cref.ToMethod();

            Assert.IsNotNull(method);
            Assert.AreEqual("Foo", method.Name);
        }
        public void Cref04()
        {
            var cref = new CRef("M:TestLibrary.SomeNamespace.Class3`2.#ctor(System.Collections.Generic.IDictionary{`0,`1})");

            Assert.IsTrue(cref.IsMethod);
            var m = cref.ToMethod();

            Assert.IsNotNull(m);
        }
        public void Cref03()
        {
            var cref = new CRef("M:TestLibrary.SomeNamespace.Class7`2.#ctor(`0,`1)");
            var m    = cref.ToMethod();

            Assert.IsNotNull(m);
            var paramArr = m.GetParameters();

            Assert.AreEqual(2, paramArr.Length);
        }
Exemplo n.º 5
0
        public void ToType01()
        {
            var cref = new CRef("T:TestLibrary.SomeNamespace.Class1");

            Assert.IsTrue(cref.IsType);
            Assert.AreEqual("TestLibrary.SomeNamespace.Class1", cref.Value);

            var t = cref.ToType();

            Assert.AreEqual(typeof(Class1), t);
        }
Exemplo n.º 6
0
        public void ToMethod01()
        {
            var cref = new CRef("M:TestLibrary.SomeNamespace.Class1.#ctor");

            Assert.IsTrue(cref.IsMethod);
            Assert.IsTrue(cref.IsConstructor);

            var method = cref.ToMethod();

            Assert.IsNotNull(method);
            Assert.AreEqual(".ctor", method.Name);
        }
        public void Cref02()
        {
            var crefs = new string[]
            {
                "M:TestLibrary.SomeNamespace.Class1.Foo``4(``0,``1,``2)",
                "M:TestLibrary.SomeNamespace.Class6`1.#ctor(`0)",
            };

            foreach (var c in crefs)
            {
                var cref = new CRef(c);
                var m    = cref.ToMethod();
                Assert.IsNotNull(m, $"The string '{c}' must be a valid method reference.");
            }
        }
        /// <summary>
        /// </summary>
        protected override void OnParametersSet()
        {
            base.OnParametersSet();

            var crefValue = this.Node?.Attributes["cref"]?.Value;

            if (null != crefValue)
            {
                CRef cref = new CRef(crefValue);
                switch (cref.CRefType)
                {
                case CRefType.Type:
                    var t = cref.ToType();
                    this.LinkText = t.Name;
                    var result = this.Factory.GetParserByType(t);
                    this.LinkUrl = this.UriBuilder.GetTypeUri(result?.Item1, t);
                    break;
                }
            }
        }
 /// <inheritdoc/>
 public abstract ICodeDocMember GetMemberModel(CRef.CRefIdentifier cRef, CodeDocRepositorySearchContext searchContext = null, CodeDocMemberDetailLevel detailLevel = CodeDocMemberDetailLevel.Full);
Exemplo n.º 10
0
        private void AddMembers(CRflTyp aPTyp, CodeTypeDeclaration aCdTypDcl, CRflProperty aProperty)
        {
            var    aModel            = aProperty.Model;
            var    aModelInterpreter = this.ModelInterpreter;
            var    aCodeDomBuilder   = this.CodeDomBuilder;
            var    aPTypNme          = this.ModelInterpreter.GetTypName(aPTyp, true);
            var    aCdPTypRef        = new CodeTypeReference(aPTypNme);
            var    aCdPTypRefExp     = new CodeTypeReferenceExpression(aCdPTypRef);
            var    aCTyp             = this.ModelInterpreter.GetReturnTyp(aProperty);
            var    aPrpNme           = aProperty.Name;
            string aMtaFldTypNme;
            var    aMtaPrpNme    = this.Tok.GetRelationyMetaInfoPropertyName(aPrpNme);
            var    aMtaPrpRefExp = new CodePropertyReferenceExpression(aCdPTypRefExp, aMtaPrpNme);
            var    aCTypRef      = this.CodeDomBuilder.NewCodeTypeRef(aCTyp);

            // Relations-Objects
            var aCrd           = this.ModelInterpreter.GetCardinality(aProperty);
            var aRelTypName    = this.ModelInterpreter.GetClassName(aCrd);
            var aRelSystemType = CRef.GetRefClass(aCrd);
            var aCdRTypRef     = new CodeTypeReference(aRelTypName, this.CodeDomBuilder.NewCodeTypeRef(aPTyp), aCTypRef);
            var aCtorArgs1     = new CodeExpression[] { new CodeThisReferenceExpression(), aMtaPrpRefExp };
            var aCtorArgsBuildAttribIsDefined = aRelSystemType.IsNullRef() ? false : aRelSystemType.IsDefined(typeof(CGenCtorArgsBuilderAttribute), true);
            var aWriteOnlyBySystem            = aProperty.Interpret(() => bool.Parse(aProperty.GetAttributeValue(this.Tok.Trg_P_A_WriteOnlyBySystem, false.ToString)));
            var aCtorArgs2            = aWriteOnlyBySystem ? new CodeExpression[] { new CodeObjectCreateExpression(typeof(CAccessKey)) } : new CodeExpression[] { };
            var aCtorArgBuilderAttrib = aCtorArgsBuildAttribIsDefined ? aRelSystemType.GetCustomAttribute <CGenCtorArgsBuilderAttribute>(true) : default(CGenCtorArgsBuilderAttribute);
            var aCtorArgs3            = aCtorArgBuilderAttrib.IsNullRef() ? new CodeExpression[] { } : aCtorArgBuilderAttrib.NewCtorArgs(aModelInterpreter, aCodeDomBuilder, aProperty);
            var aCtorArgs             = aCtorArgs1.Concat(aCtorArgs2).Concat(aCtorArgs3);
            var aNewExp  = new CodeObjectCreateExpression(aCdRTypRef, aCtorArgs.ToArray());
            var aIsClass = true;
            var aLazyPrp = this.CodeDomBuilder.NewLazyLoadPrperty(aCdRTypRef, aIsClass, this.ModelInterpreter.GetEntityRefPropertyName(aProperty), aNewExp, MemberAttributes.Public | MemberAttributes.Final);

            aCdTypDcl.Members.Add(aLazyPrp.Item1);
            aCdTypDcl.Members.Add(aLazyPrp.Item2);
            var aCdPrp = aLazyPrp.Item1;

            aMtaFldTypNme = this.Tok.GeRelationMetaInfoTypName(aRelTypName);

            // Property.Attributes from System
            aCdPrp.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(CTargetTypeAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(aCTypRef))));


            // Property.Attributes from Model
            var aCdAs = this.CodeDomBuilder.NewCodeAttributeDecls(aProperty, this.ModelInterpreter);

            aCdPrp.CustomAttributes.AddRange(aCdAs.ToArray());



            // Property.NetaInfo.Field
            var aMtaFldNme = this.Tok.GetRelationMetaInfoFieldName(aPrpNme);
            //aMtaFldTypNme = this.Tok.Trg_C_Mta_P_Fld_Nme;
            var aCdMtaFldTypRef  = new CodeTypeReference(aMtaFldTypNme);
            var aCdMtaPrpFldDcl  = new CodeMemberField(aMtaFldTypNme, aMtaFldNme);
            var aCdMtaPrpInitExp = new CodeObjectCreateExpression(aCdMtaFldTypRef,
                                                                  this.CodeDomBuilder.NewTypeOfExpression(aPTypNme),
                                                                  this.CodeDomBuilder.NewNameOfPrpertyExpression(aPrpNme)
                                                                  );

            aCdMtaPrpFldDcl.Type       = aCdMtaFldTypRef;
            aCdMtaPrpFldDcl.Attributes = MemberAttributes.Static
                                         | MemberAttributes.Private
            ;
            aCdMtaPrpFldDcl.InitExpression = aCdMtaPrpInitExp;
            aCdTypDcl.Members.Add(aCdMtaPrpFldDcl);

            var aCdMtaFldRefExp = new CodeFieldReferenceExpression(aCdPTypRefExp, aMtaFldNme);

            // Property.MetaInfo.Property
            var aCdMtaPrp = new CodeMemberProperty();

            aCdMtaPrp.Name       = aMtaPrpNme;
            aCdMtaPrp.Type       = aCdMtaFldTypRef;
            aCdMtaPrp.Attributes = MemberAttributes.Static
                                   | MemberAttributes.Public
            ;
            aCdMtaPrp.HasGet = true;
            aCdMtaPrp.GetStatements.Add(new CodeMethodReturnStatement(aCdMtaFldRefExp));
            aCdTypDcl.Members.Add(aCdMtaPrp);
        }
        /// <inheritdoc/>
        public override ICodeDocMember GetMemberModel(CRef.CRefIdentifier cRef, CodeDocRepositorySearchContext searchContext = null, CodeDocMemberDetailLevel detailLevel = CodeDocMemberDetailLevel.Full)
        {
            if (!ActivatedCheck())
                return null;

            try {
                return Repository.GetMemberModel(cRef, searchContext, detailLevel);
            }
            catch (Exception ex) {
                Deactivate(ex);
                return null;
            }
        }