Beispiel #1
0
        /// <summary>
        /// Gets a constructor as a code gen member type
        /// </summary>
        /// <param name="ci"></param>
        /// <param name="typeName"></param>
        /// <param name="getCallvirtMetadataTokens"></param>
        /// <returns></returns>
        public static CgMember GetAsCgMember(ConstructorInfo ci, string typeName, bool getCallvirtMetadataTokens = false)
        {
            if (ci == null || string.IsNullOrWhiteSpace(typeName))
            {
                return(null);
            }

            var cgMem = new CgMember
            {
                Name          = NfConfig.CTOR_NAME,
                IsCtor        = true,
                TypeName      = typeName,
                MetadataToken = ci.MetadataToken
            };

            foreach (var parameterInfo in ci.GetParameters())
            {
                var paramType = parameterInfo.NfParameterType();
                var cgArg     = new CgArg
                {
                    ArgName = parameterInfo.Name,
                    ArgType = Settings.LangStyle.TransformClrTypeSyntax(paramType)
                };

                cgMem.Args.Add(cgArg);
            }

            if (!getCallvirtMetadataTokens)
            {
                return(cgMem);
            }

            cgMem.opCodeCallsAndCallvirtsMetadatTokens.AddRange(Asm.GetCallsMetadataTokens(ci));
            return(cgMem);
        }
Beispiel #2
0
 public virtual bool Equals(CgArg arg)
 {
     return arg.ArgName == ArgName && arg.ArgType == ArgType;
 }
Beispiel #3
0
        /// <summary>
        /// Gets a method as a code gen member type
        /// </summary>
        /// <param name="mti"></param>
        /// <param name="getCallvirtMetadataTokens"></param>
        /// <returns></returns>
        public static CgMember GetAsCgMember(MethodInfo mti, bool getCallvirtMetadataTokens = false)
        {
            if (mti == null)
                return null;
            string propName;
            if (NfTypeName.IsClrMethodForProperty(mti.Name, out propName))
                return null;
            if (NfTypeName.IsClrGeneratedType(mti.Name))
                //these appear as '<SomeNameOfMethodAlreadyAdded>b__kifkj(...)'
                return null;

            var miReturnType = mti.NfReturnType();

            var cgMem = new CgMember
            {
                Name = mti.Name,
                TypeName = Settings.LangStyle.TransformClrTypeSyntax(miReturnType),
                IsStatic = mti.IsStatic,
                IsGeneric = mti.IsGenericMethod,
                IsEnumerableType = NfTypeName.IsEnumerableReturnType(miReturnType),
                IsMethod = true,
                MetadataToken = mti.MetadataToken
            };
            if(mti.IsAssembly)
                cgMem.AccessModifier = CgAccessModifier.Assembly;
            if(mti.IsFamily)
                cgMem.AccessModifier = CgAccessModifier.Family;
            if(mti.IsFamilyAndAssembly)
                cgMem.AccessModifier = CgAccessModifier.FamilyAssembly;
            if(mti.IsPrivate)
                cgMem.AccessModifier = CgAccessModifier.Private;
            if(mti.IsPublic)
                cgMem.AccessModifier = CgAccessModifier.Public;

            foreach (var parameterInfo in mti.GetParameters())
            {
                var paramType = parameterInfo.NfParameterType();
                var cgArg = new CgArg
                {
                    ArgName = parameterInfo.Name,
                    ArgType = Settings.LangStyle.TransformClrTypeSyntax(paramType)
                };

                cgMem.Args.Add(cgArg);
            }
            cgMem.MethodBodyIL = Convert.ToBase64String(Asm.GetMethodBody(mti));

            if (!getCallvirtMetadataTokens)
                return cgMem;

            cgMem.opCodeCallsAndCallvirtsMetadatTokens.AddRange(Asm.GetCallsMetadataTokens(mti));
            return cgMem;
        }
Beispiel #4
0
        /// <summary>
        /// Gets a constructor as a code gen member type
        /// </summary>
        /// <param name="ci"></param>
        /// <param name="typeName"></param>
        /// <param name="getCallvirtMetadataTokens"></param>
        /// <returns></returns>
        public static CgMember GetAsCgMember(ConstructorInfo ci, string typeName, bool getCallvirtMetadataTokens = false)
        {
            if (ci == null || string.IsNullOrWhiteSpace(typeName))
                return null;

            var cgMem = new CgMember
            {
                Name = Constants.CTOR_NAME,
                IsCtor = true,
                TypeName = typeName,
                MetadataToken = ci.MetadataToken
            };
            foreach (var parameterInfo in ci.GetParameters())
            {
                var paramType = parameterInfo.NfParameterType();
                var cgArg = new CgArg
                {
                    ArgName = parameterInfo.Name,
                    ArgType = Settings.LangStyle.TransformClrTypeSyntax(paramType)
                };

                cgMem.Args.Add(cgArg);
            }

            if (!getCallvirtMetadataTokens) return cgMem;

            cgMem.opCodeCallsAndCallvirtsMetadatTokens.AddRange(Asm.GetCallsMetadataTokens(ci));
            return cgMem;
        }
Beispiel #5
0
 public static string ToGraphVizString(this CgArg cgArg)
 {
     return(NfReflect.GetTypeNameWithoutNamespace(cgArg.ArgType));
 }
Beispiel #6
0
 public virtual bool Equals(CgArg arg)
 {
     return(arg.ArgName == ArgName && arg.ArgType == ArgType);
 }
Beispiel #7
0
        /// <summary>
        /// Gets a method as a code gen member type
        /// </summary>
        /// <param name="mti"></param>
        /// <param name="getCallvirtMetadataTokens"></param>
        /// <returns></returns>
        public static CgMember GetAsCgMember(MethodInfo mti, bool getCallvirtMetadataTokens = false)
        {
            if (mti == null)
            {
                return(null);
            }
            if (NfReflect.IsClrMethodForProperty(mti.Name, out _))
            {
                return(null);
            }
            if (NfReflect.IsClrGeneratedType(mti.Name))
            {
                //these appear as '<SomeNameOfMethodAlreadyAdded>b__kifkj(...)'
                return(null);
            }

            var miReturnType = mti.NfReturnType();

            var cgMem = new CgMember
            {
                Name             = mti.Name,
                TypeName         = Settings.LangStyle.TransformClrTypeSyntax(miReturnType),
                IsStatic         = mti.IsStatic,
                IsGeneric        = mti.IsGenericMethod,
                IsEnumerableType = NfReflect.IsEnumerableReturnType(miReturnType),
                IsMethod         = true,
                MetadataToken    = mti.MetadataToken
            };

            if (mti.IsAssembly)
            {
                cgMem.AccessModifier = CgAccessModifier.Assembly;
            }
            if (mti.IsFamily)
            {
                cgMem.AccessModifier = CgAccessModifier.Family;
            }
            if (mti.IsFamilyAndAssembly)
            {
                cgMem.AccessModifier = CgAccessModifier.FamilyAssembly;
            }
            if (mti.IsPrivate)
            {
                cgMem.AccessModifier = CgAccessModifier.Private;
            }
            if (mti.IsPublic)
            {
                cgMem.AccessModifier = CgAccessModifier.Public;
            }

            foreach (var parameterInfo in mti.GetParameters())
            {
                var paramType = parameterInfo.NfParameterType();
                var cgArg     = new CgArg
                {
                    ArgName = parameterInfo.Name,
                    ArgType = Settings.LangStyle.TransformClrTypeSyntax(paramType)
                };

                cgMem.Args.Add(cgArg);
            }
            cgMem.MethodBodyIL = Convert.ToBase64String(Asm.GetMethodBody(mti));

            if (!getCallvirtMetadataTokens)
            {
                return(cgMem);
            }

            cgMem.opCodeCallsAndCallvirtsMetadatTokens.AddRange(Asm.GetCallsMetadataTokens(mti));
            return(cgMem);
        }