当前位置: 首页>>代码示例>>C#>>正文


C# Type.GetMembers方法代码示例

本文整理汇总了C#中Type.GetMembers方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetMembers方法的具体用法?C# Type.GetMembers怎么用?C# Type.GetMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Type的用法示例。


在下文中一共展示了Type.GetMembers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Analyze

 void Analyze( Type targettype )
 {
     Console.WriteLine( "analyzing " + targettype.ToString() + " ... " );
     foreach( MemberInfo memberinfo in targettype.GetMembers() )
     {
         //Console.WriteLine( memberinfo.MemberType.ToString() + " " + memberinfo.Name );
         if( memberinfo.MemberType == MemberTypes.Field )
         {
             //Console.WriteLine( memberinfo.Name );
             FieldInfo fi = targettype.GetField( memberinfo.Name );
             Console.WriteLine( "Field: " + memberinfo.Name + " " + fi.FieldType + " isliteral " + fi.IsLiteral.ToString() );
         }
         else if( memberinfo.MemberType == MemberTypes.Property )
         {
             //Console.WriteLine( memberinfo.Name );
             PropertyInfo pi = targettype.GetProperty( memberinfo.Name );
             Console.WriteLine( "Property: " + pi.PropertyType + " " + memberinfo.Name );
         }
         else if( memberinfo.MemberType == MemberTypes.Method )
         {
             Console.WriteLine( memberinfo.MemberType.ToString() + " " + memberinfo.Name );
             MethodBase methodbase = memberinfo as MethodBase;
             MethodInfo methodinfo = memberinfo as MethodInfo;
             Console.WriteLine( "   returntype " + methodinfo.ReturnType.ToString() );
             ParameterInfo[] parameterinfos = methodbase.GetParameters();
             for( int i = 0; i < parameterinfos.GetUpperBound(0) + 1; i ++ )
             {
                 Console.WriteLine( "   parameter " + parameterinfos[i].ParameterType + " " + parameterinfos[i].Name );
             }
             //Console.WriteLine( memberinfo.Name );
             //MethodInfo mi = targettype.GetMethod( memberinfo.Name );
             //Console.WriteLine( memberinfo.Name );
         }
     }
 }
开发者ID:achoum,项目名称:spring,代码行数:35,代码来源:AbicWrapperGenerator.cs

示例2: GetMembersForAttribute

 // returns public class members having the attribute attributetype
 // if attributetype is null, returns all public members
 public static MemberInfo[] GetMembersForAttribute( Type objecttype )
 {
     ArrayList members = new ArrayList();
     foreach( MemberInfo memberinfo in objecttype.GetMembers() )
     {
     //        if( attributetype == null || HasAttribute( memberinfo, attributetype ) )
        //     {
             members.Add( memberinfo );
        //     }
     }
     return (MemberInfo[])members.ToArray( typeof( MemberInfo ) );
 }
开发者ID:achoum,项目名称:spring,代码行数:14,代码来源:AbicWrapperGenerator.cs

示例3: TestPreAppStartClass

        public static void TestPreAppStartClass(Type preAppStartType)
        {
            string typeMessage = String.Format("The type '{0}' must be static, public, and named 'PreApplicationStartCode'.", preAppStartType.FullName);
            Assert.True(preAppStartType.IsSealed && preAppStartType.IsAbstract && preAppStartType.IsPublic && preAppStartType.Name == "PreApplicationStartCode", typeMessage);

            string editorBrowsableMessage = String.Format("The only attribute on type '{0}' must be [EditorBrowsable(EditorBrowsableState.Never)].", preAppStartType.FullName);
            object[] attrs = preAppStartType.GetCustomAttributes(typeof(EditorBrowsableAttribute), true);
            Assert.True(attrs.Length == 1 && ((EditorBrowsableAttribute)attrs[0]).State == EditorBrowsableState.Never, editorBrowsableMessage);

            string startMethodMessage = String.Format("The only public member on type '{0}' must be a method called Start().", preAppStartType.FullName);
            MemberInfo[] publicMembers = preAppStartType.GetMembers(BindingFlags.Public | BindingFlags.Static);
            Assert.True(publicMembers.Length == 1, startMethodMessage);
            Assert.True(publicMembers[0].MemberType == MemberTypes.Method, startMethodMessage);
            Assert.True(publicMembers[0].Name == "Start", startMethodMessage);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:15,代码来源:PreAppStartTestHelper.cs

示例4: TestPreAppStartClass

        public static void TestPreAppStartClass(Type preAppStartType) {
            Assert.IsTrue(preAppStartType.IsSealed && preAppStartType.IsAbstract, "The type '{0}' should be static.", preAppStartType.FullName);
            
            Assert.IsTrue(preAppStartType.IsPublic, "The type '{0}' should be public.", preAppStartType.FullName);

            Assert.AreEqual("PreApplicationStartCode", preAppStartType.Name, "The type '{0}' has the wrong name.", preAppStartType.FullName);

            object[] attrs = preAppStartType.GetCustomAttributes(typeof(EditorBrowsableAttribute), true);
            Assert.AreEqual(1, attrs.Length, "The type '{0}' should have [EditorBrowsable(EditorBrowsableState.Never)] applied to it.", preAppStartType.FullName);
            EditorBrowsableAttribute editorAttr = (EditorBrowsableAttribute)attrs[0];
            Assert.AreEqual(EditorBrowsableState.Never, editorAttr.State, "The type '{0}' should have [EditorBrowsable(EditorBrowsableState.Never)] applied to it.", preAppStartType.FullName);

            MemberInfo[] publicMembers = preAppStartType.GetMembers(BindingFlags.Public | BindingFlags.Static);
            Assert.AreEqual(1, publicMembers.Length, "The type '{0}' should have only one public member.", preAppStartType.FullName);
            Assert.AreEqual(MemberTypes.Method, publicMembers[0].MemberType, "The only public member on type '{0}' should be a method called Start().", preAppStartType.FullName);
            Assert.AreEqual("Start", publicMembers[0].Name, "The only public member on type '{0}' should be a method called Start().", preAppStartType.FullName);
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:17,代码来源:PreAppStartTestHelper.cs

示例5: GetMeberOperationHelperContainer

 private static MeberOperationHelperContainer GetMeberOperationHelperContainer(Type type)
 {
     MemberInfo[] members = type.GetMembers(BindingFlags.Public | BindingFlags.Instance);
     int num = 0;
     foreach (MemberInfo info in members)
     {
         if ((info.MemberType == MemberTypes.Field) || (info.MemberType == MemberTypes.Property))
         {
             num++;
         }
     }
     MeberOperationHelperContainer meberOperationHelperContainer = new MeberOperationHelperContainer(type, num);
     foreach (MemberInfo info in members)
     {
         if (((info.MemberType == MemberTypes.Field) || (info.MemberType == MemberTypes.Property)) && ((info.MemberType != MemberTypes.Property) || !(info as PropertyInfo).NeedExtraParameters()))
         {
             DbColumnAttribute attribute = info.GetAttribute<DbColumnAttribute>() ?? new DbColumnAttribute();
             MemberOperationBase memberOperationBase = MemberOperationBaseRepository.GetMemberOperationBase(info);
             if (!memberOperationBase.GetPropertyType().IsArray())
             {
                 if (!(attribute.IgnoreLoad || memberOperationBase.CanWrite()))
                 {
                     attribute.IgnoreLoad = true;
                 }
                 if (!attribute.IgnoreLoad)
                 {
                     if (memberOperationBase.GetPropertyType().IsValid())
                     {
                         attribute.HasPrefix = true;
                         if (!memberOperationBase.GetPropertyType().HasPublicConstructor())
                         {
                             attribute.IgnoreLoad = true;
                         }
                     }
                     else if (string.IsNullOrEmpty(attribute.Alias))
                     {
                         attribute.Alias = info.Name;
                     }
                 }
                 meberOperationHelperContainer.SetMeberOperationHelperValue(attribute, memberOperationBase);
             }
         }
     }
     return meberOperationHelperContainer;
 }
开发者ID:nakijun,项目名称:FastDBEngine,代码行数:45,代码来源:ClassObjRepository.cs

示例6: GenerateFor

    void GenerateFor( Type targettype, string basetypename, string[]methodstoignore )
    {
        string[] splittargettypestring = targettype.ToString().Split(".".ToCharArray() );
        string namespacename = "";
        if( splittargettypestring.GetUpperBound(0) + 1 > 1 )
        {
            namespacename = splittargettypestring[ 0 ];
        }
        string typename = splittargettypestring[ splittargettypestring.GetUpperBound(0) ];
        //string basetypename = typename.Substring(1); // remove leading "I"
        string basefilename = "Abic" + typename + "Wrapper_generated";

        StreamWriter headerfile = new StreamWriter( basefilename + ".h", false );
        WriteHeaderComments( headerfile );

        // target code to generate for header:
        // AICALLBACK_API int UnitDef_get_id( const UnitDef *self );

        // target code to generate for cpp:
        // AICALLBACK_API int UnitDef_get_id( const UnitDef *self )
        // {
        //     return self->id;
        // }
        // StreamWriter cppfile = new StreamWriter( basefilename + ".cpp", false );
        //WriteHeaderComments( cppfile );
        foreach( MemberInfo memberinfo in targettype.GetMembers() )
        {
            if( !ArrayContains( methodstoignore, memberinfo.Name ) )
            {
                try
                {
                    string declarationstring = GetDeclarationString( targettype, basetypename, memberinfo );
                    if( declarationstring != "" )
                    {
                        // first we generate the string, throwing exceptions as appropriate
                        // then we write them to file if they worked out ok
                        // this needs to be atomic, so that we always have both header declaration + cpp definition, or neither
                        string cppdeclaration = "   " + declarationstring + "\n";
                        cppdeclaration += "   " + "{\n";
                        if( memberinfo.MemberType == MemberTypes.Property )
                        {
                            PropertyInfo pi = targettype.GetProperty( memberinfo.Name );
                            cppdeclaration += "   " + "   return " + basetypename + "_get_" + memberinfo.Name + "( self );\n"; // we can assume a property wont return void
                        }
                        else if( memberinfo.MemberType == MemberTypes.Method )
                        {
                            MethodInfo methodinfo = memberinfo as MethodInfo;
                            if( methodinfo.ReturnType != typeof( void ) )
                            {
                                cppdeclaration += "   " + "   return " + basetypename + "_" + memberinfo.Name + "( self ";
                            }
                            else
                            {
                                cppdeclaration += "   " + "   " + basetypename + "_" + memberinfo.Name + "( self ";
                            }

                            ParameterInfo[] parameterinfos = methodinfo.GetParameters();
                            for( int i = 0; i < parameterinfos.GetUpperBound(0) + 1; i++ )
                            {
                                //if( i < parameterinfos.GetUpperBound(0) )
                                //{
                                    cppdeclaration += ", ";
                                //}
                                cppdeclaration += parameterinfos[i].Name;
                            }

                            cppdeclaration += "  );\n";
                        }
                        cppdeclaration += "   " + "}\n";
                        cppdeclaration += "\n";

                        //headerfile.WriteLine( declarationstring + ";" );
                        headerfile.Write( cppdeclaration );
                    }
                }
                catch( ExceptionCsTypeNotHandled e )
                {
                    Console.WriteLine("Ignoring " + memberinfo.MemberType.ToString() + " " + typename + "." + memberinfo.Name + " " + e.Message );
                }
                catch( Exception e )
                {
                    Console.WriteLine( e.ToString() );
                }
            }
        }

        headerfile.Close();
        //cppfile.Close();
    }
开发者ID:achoum,项目名称:spring,代码行数:89,代码来源:AbicWrapperGenerator.cs

示例7: getAllSignalMethod

 static List<String> getAllSignalMethod(Type pType)
 {
     var lOut = new List<String>();
     var lMembers = pType.GetMembers();
     foreach (var llMember in lMembers)
     {
         if(llMember is MethodInfo)
         {
             var lMethodInfo = (MethodInfo)llMember;
             if (lMethodInfo.GetParameters().Length == 1
                 && lMethodInfo.GetParameters()[0]
                     .ParameterType.BaseType == typeof(MulticastDelegate))
                 lOut.Add(lMethodInfo.Name);
         }
         else if(llMember is PropertyInfo
             && ((PropertyInfo)llMember)
                 .PropertyType.BaseType == typeof(MulticastDelegate))
         {
             lOut.Add(llMember.Name);
         }
         else if(llMember is FieldInfo
             && ((FieldInfo)llMember)
                 .FieldType.BaseType == typeof(MulticastDelegate))
         {
             lOut.Add(llMember.Name);
         }
         else if (llMember is EventInfo)
         {
             lOut.Add(llMember.Name);
         }
     }
     return lOut;
 }
开发者ID:Seraphli,项目名称:TheInsectersWar,代码行数:33,代码来源:zzSignalSlotEditor.cs

示例8: WriteEventArgs

 private static void WriteEventArgs(TreeIter iter, Type args)
 {
     foreach(MemberInfo item in args.GetMembers(BindingFlags.Public | BindingFlags.Instance))
     {
         if(item is PropertyInfo)
         {
             PropertyInfo prop = (PropertyInfo)item;
             string rw = ((prop.CanRead)?"r":"") + ((prop.CanWrite)?"w":"");
             store.AppendValues(iter, "<small>("+rw+")</small>\t<b><tt>"+prop.Name+"</tt></b><small>: "+NiceTypeName(prop.PropertyType)+"</small>", NiceTypeName(args), "");
         }
         if(item is FieldInfo)
         {
             FieldInfo field = (FieldInfo)item;
             store.AppendValues(iter, field.Name, NiceTypeName(args), "");
         }
     }
 }
开发者ID:langpavel,项目名称:LPS-old,代码行数:17,代码来源:Main.cs

示例9: All_Excluded_Members_Are_Declared

        public void All_Excluded_Members_Are_Declared(Type innerType, Type tracerType, string[] exclusions)
        {
            // Arrange & Act
            string[] declaredMembers = tracerType.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Select<MemberInfo, string>(m => m.Name).ToArray();
            string[] unDeclaredExcludedMembers = exclusions.Where(e => !declaredMembers.Contains(e.Substring(e.LastIndexOf('.') + 1))).ToArray();

            // Assert
            Assert.True(unDeclaredExcludedMembers.Length == 0,
                        String.Format("The tracer '{0}' does not declare these members listed for exclusion: {1}",
                                        tracerType.Name,
                                        string.Join(",", unDeclaredExcludedMembers)));
        }
开发者ID:RhysC,项目名称:aspnetwebstack,代码行数:12,代码来源:TracerCorrectnessTest.cs

示例10: GetMembers

 public static MemberInfo[] GetMembers(Type type, BindingFlags bindingAttr)
 {
     Requires.NotNull(type, "type");
     return type.GetMembers(bindingAttr);
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:5,代码来源:TypeExtensions.CoreCLR.cs

示例11: SetNestedClassCompletions

        internal void SetNestedClassCompletions(Type computedType, Type thisType)
        {
            BindingFlags flags = BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance;
            if (computedType.Assembly == thisType.Assembly)
                flags |= BindingFlags.NonPublic;

            // Initialize the list with the computed type's members (no need for interfaces or extension methods)
            List<MemberInfo> members = new List<MemberInfo>(computedType.GetMembers(flags));

            // Filter out the duplicates & special names.
            Dictionary<string, MemberInfo> filteredMembers = new Dictionary<string, MemberInfo>();
            foreach (MemberInfo member in members)
            {
                if (member == null)
                    continue;

                switch (member.MemberType)
                {
                    case MemberTypes.NestedType:
                    case MemberTypes.TypeInfo:
                        if (member.DeclaringType == thisType || IsNonPrivate((Type)member, thisType))
                        {
                            filteredMembers[member.Name] = member;
                        }
                        break;

                    default:
                        // Don't add constructors/method/field/property things to the completion list.
                        break;
                }
            }

            completions = filteredMembers.Values;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:34,代码来源:Parser.cs

示例12: SetTypeMemberCompletions

        internal void SetTypeMemberCompletions(Type computedType, Type thisType, bool isStatic, RuleValidation validation)
        {
            BindingFlags flags = BindingFlags.Public;
            if (isStatic)
                flags |= BindingFlags.Static | BindingFlags.FlattenHierarchy;
            else
                flags |= BindingFlags.Instance;
            if (computedType.Assembly == thisType.Assembly)
                flags |= BindingFlags.NonPublic;

            // Initialize the list with the computed type's members.
            List<MemberInfo> members = new List<MemberInfo>(computedType.GetMembers(flags));
            if (computedType.IsInterface)
            {
                // If it's an interface, we need to chase up the parents and add their members too.
                List<Type> baseInterfaces = new List<Type>(computedType.GetInterfaces());
                for (int i = 0; i < baseInterfaces.Count; ++i)
                {
                    Type baseInterface = baseInterfaces[i];
                    baseInterfaces.AddRange(baseInterface.GetInterfaces());
                    members.AddRange(baseInterface.GetMembers(flags));
                }

                // Finally, we need to add members of System.Object, since all types intrinsically
                // derive from that.
                members.AddRange(typeof(object).GetMembers(flags));
            }

            // add in any extension methods that may be applicable to this type
            List<ExtensionMethodInfo> ext = validation.ExtensionMethods;
            foreach (ExtensionMethodInfo extension in ext)
            {
                ValidationError error;
                if (RuleValidation.TypesAreAssignable(computedType, extension.AssumedDeclaringType, null, out error))
                {
                    members.Add(extension);
                }
            }

            // Filter out the duplicates & special names.
            Dictionary<string, MemberInfo> filteredMembers = new Dictionary<string, MemberInfo>();
            foreach (MemberInfo member in members)
            {
                if (member == null)
                    continue;

                switch (member.MemberType)
                {
                    case MemberTypes.Method:
                        MethodInfo method = (MethodInfo)member;

                        // If method, exclude special names & generic methods.
                        if (!method.IsSpecialName && !method.IsGenericMethod)
                        {
                            // Add all members of this's type, but only non-private members
                            // of other types.
                            if (method.DeclaringType == thisType || IsNonPrivate(method, thisType) || (method is ExtensionMethodInfo))
                                filteredMembers[member.Name] = member;
                        }
                        break;

                    case MemberTypes.NestedType:
                    case MemberTypes.TypeInfo:
                        // Only add nested types if "isStatic" is true.
                        if (isStatic)
                        {
                            if (member.DeclaringType == thisType || IsNonPrivate((Type)member, thisType))
                            {
                                filteredMembers[member.Name] = member;
                            }
                        }
                        break;

                    case MemberTypes.Field:
                        // Add all members of this's type, but only non-private members
                        // of other types.
                        if (member.DeclaringType == thisType || IsNonPrivate((FieldInfo)member, thisType))
                            filteredMembers[member.Name] = member;
                        break;

                    case MemberTypes.Property:
                        PropertyInfo prop = (PropertyInfo)member;
                        ParameterInfo[] propParams = prop.GetIndexParameters();
                        if (propParams != null && propParams.Length > 0)
                        {
                            // If the property has arguments, it can only be accessed by directly calling
                            // its accessor methods.
                            MethodInfo[] accessors = prop.GetAccessors((flags & BindingFlags.NonPublic) != 0);
                            foreach (MethodInfo accessor in accessors)
                            {
                                if (accessor.DeclaringType == thisType || IsNonPrivate(accessor, thisType))
                                    filteredMembers[accessor.Name] = accessor;
                            }
                        }
                        else
                        {
                            if (member.DeclaringType == thisType)
                            {
                                // It's a property on "this", so add it even if it's private.
                                filteredMembers[member.Name] = member;
//.........这里部分代码省略.........
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:101,代码来源:Parser.cs

示例13: GenerateFor

    // patterns:
    // for cs file:
    //        [MethodImpl(MethodImplOptions.InternalCall )]
    //    public extern static void IAICallback_SendTextMsg( IntPtr aicallback, string message, int priority );
    //
    // for definition gpp file:
    //void _IAICallback_SendTextMsg( void *aicallback, double somedouble, int priority )
    //{
    //     IAICallback_SendTextMsg( ( const IAICallback *)aicallback, somedouble, priority );
    // }
    //
    // for binding gpp file:
    //       mono_add_internal_call(PREFIX "IAICallback_SendTextMsg", (void*)_IAICallback_SendTextMsg);
    void GenerateFor( Type targettype, string basetypename, string[]methodstoignore )
    {
        string[] splittargettypestring = targettype.ToString().Split(".".ToCharArray() );
        string namespacename = "";
        if( splittargettypestring.GetUpperBound(0) + 1 > 1 )
        {
            namespacename = splittargettypestring[ 0 ];
        }
        string typename = splittargettypestring[ splittargettypestring.GetUpperBound(0) ];
        //string basetypename = typename.Substring(1); // remove leading "I"
        string basefilename = typename + "_generated";

        StreamWriter definitionfile = new StreamWriter( typename + "definitions_generated.gpp", false );
        WriteHeaderComments( definitionfile );

        StreamWriter bindingfile = new StreamWriter( typename + "bindings_generated.gpp", false );
        WriteHeaderComments( bindingfile );
        foreach( MemberInfo memberinfo in targettype.GetMembers() )
        {
            if( !ArrayContains( methodstoignore, memberinfo.Name ) )
            {
                if( memberinfo.MemberType != MemberTypes.Method || memberinfo.Name.IndexOf( "get_" ) != 0 )
                {
                    try
                    {
                        string csstring = GetCSString( targettype, basetypename, memberinfo );
                        string definitionstringprot = GetDefinitionPrototypeString( targettype, basetypename, memberinfo );
                        string definitionstringimp = GetDefinitionImplementationString( targettype, basetypename, memberinfo );
                        string bindingstring = GetBindingString( targettype, basetypename, memberinfo );

                        if( definitionstringimp.Trim() == "" )
                        {
                            Console.WriteLine( memberinfo.Name + " has an issue" );
                        }
                        csfile.WriteLine( csstring + "\n" );
                        definitionfile.WriteLine( definitionstringprot + "\n" + definitionstringimp );
                        bindingfile.Write( bindingstring );
                    }
                    catch( ExceptionCsTypeNotHandled e )
                    {
                        Console.WriteLine("Ignoring " + memberinfo.MemberType.ToString() + " " + typename + "." + memberinfo.Name + " " + e.Message );
                    }
                    catch( Exception e )
                    {
                        Console.WriteLine( e.ToString() );
                    }
                }
            }
        }

        definitionfile.Close();
        bindingfile.Close();
    }
开发者ID:achoum,项目名称:spring,代码行数:66,代码来源:MonoABICInterfaceGenerator.cs

示例14: GenerateFor

    void GenerateFor( Type targettype, string basetypename, string[]methodstoignore )
    {
        string[] splittargettypestring = targettype.ToString().Split(".".ToCharArray() );
        string namespacename = "";
        if( splittargettypestring.GetUpperBound(0) + 1 > 1 )
        {
            namespacename = splittargettypestring[ 0 ];
        }
        string typename = splittargettypestring[ splittargettypestring.GetUpperBound(0) ];
        //string basetypename = typename.Substring(1); // remove leading "I"
        string basefilename = "CSAIProxy" + typename + "_generated";

        StreamWriter headerfile = new StreamWriter( basefilename + ".h", false );
        WriteHeaderComments( headerfile );

        // pattern:
        // 	double get_maxSlope(){ return actualmovedata->get_maxSlope(); }
        //    double GetUnitDefRadius( int def )
        //    {
        //        return callbacktorts->GetUnitDefRadius( def );
        //    }

        // StreamWriter cppfile = new StreamWriter( basefilename + ".cpp", false );
        //WriteHeaderComments( cppfile );
        foreach( MemberInfo memberinfo in targettype.GetMembers() )
        {
            if( !ArrayContains( methodstoignore, memberinfo.Name ) )
            {
                try
                {
                    string declarationstring = GetDeclarationString( targettype, basetypename, memberinfo );
                    if( declarationstring != "" )
                    {
                        // first we generate the string, throwing exceptions as appropriate
                        // then we write them to file if they worked out ok
                        // this needs to be atomic, so that we always have both header declaration + cpp definition, or neither
                        string cppdeclaration = "   " + declarationstring + "\r\n";
                        cppdeclaration += "   " + "{\r\n";
                        // pattern for strings:
                        // System::String *get_myName(){ return new System::String( string( actualfeaturedef->myName ).c_str() ); }
                        if( memberinfo.MemberType == MemberTypes.Property )
                        {
                            PropertyInfo pi = targettype.GetProperty( memberinfo.Name );
                            if( pi.PropertyType == typeof( string ) )
                            {
                                cppdeclaration += "   " + "   return new System::String( std::string( self->get_" + memberinfo.Name + "() ).c_str() );\r\n"; // we can assume a property wont return void
                            }
                            else
                            {
                                cppdeclaration += "   " + "   return self->get_" + memberinfo.Name + "();\r\n"; // we can assume a property wont return void
                            }
                        }
                        else if( memberinfo.MemberType == MemberTypes.Method )
                        {
                            MethodInfo methodinfo = memberinfo as MethodInfo;
                            if( methodinfo.ReturnType == typeof( void ) )
                            {
                                cppdeclaration += "   " + "   self->" + memberinfo.Name + "( ";
                            }
                            else if( methodinfo.ReturnType == typeof( string ) )
                            {
                                cppdeclaration += "   " + "   return new System::String( std::string( self->" + memberinfo.Name + "( ";
                            }
                            else
                            {
                                cppdeclaration += "   " + "   return self->" + memberinfo.Name + "( ";
                            }

                            ParameterInfo[] parameterinfos = methodinfo.GetParameters();
                            for( int i = 0; i < parameterinfos.GetUpperBound(0) + 1; i++ )
                            {
                                if( i > 0 )
                                //if( i < parameterinfos.GetUpperBound(0) )
                                {
                                    cppdeclaration += ", ";
                                }
                                cppdeclaration += parameterinfos[i].Name;
                            }

                            cppdeclaration += "  )";

                            if( methodinfo.ReturnType == typeof( string ) )
                            {
                                cppdeclaration += " ).c_str() )";
                            }

                            cppdeclaration += ";\r\n";
                        }
                        cppdeclaration += "   " + "}\r\n";
                        cppdeclaration += "\r\n";

                        //headerfile.WriteLine( declarationstring + ";" );
                        headerfile.Write( cppdeclaration );
                    }
                }
                catch( ExceptionCsTypeNotHandled e )
                {
                    Console.WriteLine("Ignoring " + memberinfo.MemberType.ToString() + " " + typename + "." + memberinfo.Name + " " + e.Message );
                }
                catch( Exception e )
//.........这里部分代码省略.........
开发者ID:achoum,项目名称:spring,代码行数:101,代码来源:CSAIProxyGenerator.cs

示例15: listattributes

 private static void listattributes(Type t, string identifier)
 {
     Logger.Log(LogLevel.UserInfo, "List detector attributes");
     //Type t = item.GetType();
     //PropertyInfo[] pia = t.GetProperties();
     //Logger.Log(LogLevel.UserInfo, String.Format("GammaCor={0}", item.GammaCorrection));
     //foreach (PropertyInfo pi in pia)
     //{
     //	Logger.Log(LogLevel.UserInfo, String.Format("Name={0},Property {1}", item.Identifier,
     //			pi.ToString()));
     //}
     MemberInfo[] ms = t.GetMembers();
     foreach (MemberInfo mi in ms)
     {
     Logger.Log(LogLevel.UserInfo, String.Format("Name={0}, Member {1}",identifier,
                 mi.ToString()));
     }
     /*IRMSBaseCupConfigurationData cupData = Instrument.CupConfigurationDataList.GetActiveCupConfiguration();
     foreach (IRMSBaseCollectorItem item in cupData.CollectorItemList)
     {	Type t = item.GetType();
         PropertyInfo[] pia = t.GetProperties();
         //Logger.Log(LogLevel.UserInfo, String.Format("GammaCor={0}", item.GammaCorrection));
         foreach (PropertyInfo pi in pia)
         {
             Logger.Log(LogLevel.UserInfo, String.Format("Name={0},Property {1}", item.Identifier,
                     pi.ToString()));
         }
         MemberInfo[] ms = t.GetMembers();
         foreach (MemberInfo mi in ms)
         {
         Logger.Log(LogLevel.UserInfo, String.Format("Name={0}, Member {1}", item.Identifier,
                     mi.ToString()));
         }
     }*/
 }
开发者ID:NMGRL,项目名称:qtegra,代码行数:35,代码来源:RemoteControlServer.cs


注:本文中的Type.GetMembers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。