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


C# Type.GetProperty方法代码示例

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


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

示例1: Filter

 /// <summary>
 /// Создает на основе типа фильтр
 /// </summary>
 /// <param name="lib"></param>
 /// <param name="type"></param>
 public Filter(string lib, Type type)
 {
     libname = lib;
     if (type.BaseType == typeof(AbstractFilter))
     {
         Exception fullex = new Exception("");
         ConstructorInfo ci = type.GetConstructor(System.Type.EmptyTypes);
         filter = ci.Invoke(null);
         PropertyInfo everyprop;
         everyprop = type.GetProperty("Name");
         name = (string)everyprop.GetValue(filter, null);
         everyprop = type.GetProperty("Author");
         author = (string)everyprop.GetValue(filter, null);
         everyprop = type.GetProperty("Ver");
         version = (Version)everyprop.GetValue(filter, null);
         help = type.GetMethod("Help");
         MethodInfo[] methods = type.GetMethods();
         filtrations = new List<Filtration>();
         foreach (MethodInfo mi in methods)
             if (mi.Name == "Filter")
             {
                 try
                 {
                     filtrations.Add(new Filtration(mi));
                 }
                 catch (TypeLoadException)
                 {
                     //Не добавляем фильтрацию.
                 }
             }
         if (filtrations == null) throw new TypeIncorrectException("Класс " + name + " не содержит ни одной фильтрации");
     }
     else
         throw new TypeLoadException("Класс " + type.Name + " не наследует AbstractFilter");
 }
开发者ID:verygrey,项目名称:ELPTWPF,代码行数:40,代码来源:Filter.cs

示例2: NullableMembers

 public NullableMembers(Type elementType)
 {
     NullableType = NullableTypeDefinition.MakeGenericType(elementType);
     Constructor = NullableType.GetConstructor(new[] { elementType });
     GetHasValue = NullableType.GetProperty("HasValue").GetGetMethod();
     GetValue = NullableType.GetProperty("Value").GetGetMethod();
 }
开发者ID:jaygumji,项目名称:EnigmaDb,代码行数:7,代码来源:NullableMembers.cs

示例3: EmitPropertyGetAccessor

        /// <summary>
        /// Initializes a new instance of the <see cref="EmitPropertyGetAccessor"/> class.
        /// </summary>
        /// <param name="targetObjectType">Type of the target object.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="assemblyBuilder">The <see cref="AssemblyBuilder"/>.</param>
        /// <param name="moduleBuilder">The <see cref="ModuleBuilder"/>.</param>
        public EmitPropertyGetAccessor(Type targetObjectType, string propertyName, AssemblyBuilder assemblyBuilder, ModuleBuilder moduleBuilder)
        {
            _targetType = targetObjectType;
            _propertyName = propertyName;

            // deals with Overriding a property using new and reflection
            // http://blogs.msdn.com/thottams/archive/2006/03/17/553376.aspx
            PropertyInfo propertyInfo = _targetType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            if (propertyInfo == null)
            {
                propertyInfo = _targetType.GetProperty(propertyName);
            }

            // Make sure the property exists
            if(propertyInfo == null)
            {
                throw new NotSupportedException(
                    string.Format("Property \"{0}\" does not exist for type "
                    + "{1}.", propertyName, _targetType));
            }
            else
            {
                this._propertyType = propertyInfo.PropertyType;
                _canRead = propertyInfo.CanRead;
                this.EmitIL(assemblyBuilder, moduleBuilder);
            }
        }
开发者ID:hejiquan,项目名称:iBATIS_2010,代码行数:34,代码来源:EmitPropertyGetAccessor.cs

示例4: Setup

 public void Setup()
 {
     m_studType = typeof(Student);
     m_idProperty = m_studType.GetProperty("ID");
     m_nameProperty = m_studType.GetProperty("Name");
     m_scoreProperty = m_studType.GetProperty("Score");
 }
开发者ID:stasi009,项目名称:TestDrivenLearn,代码行数:7,代码来源:ReflectionTest.cs

示例5: API

		static API()
		{
			var editorAssembly = typeof(EditorWindow).Assembly;
			containerWindowType = editorAssembly.GetType("UnityEditor.ContainerWindow");
			viewType = editorAssembly.GetType("UnityEditor.View");
			dockAreaType = editorAssembly.GetType("UnityEditor.DockArea");
			parentField = typeof(EditorWindow).GetField("m_Parent", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic);
			if (dockAreaType != null)
			{
				panesField = dockAreaType.GetField("m_Panes", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic);
				addTabMethod = dockAreaType.GetMethod("AddTab", new System.Type[] { typeof(EditorWindow) });
			}
			if (containerWindowType != null)
			{
				windowsField = containerWindowType.GetProperty("windows", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic);
				mainViewField = containerWindowType.GetProperty("mainView", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (viewType != null)
				allChildrenField = viewType.GetProperty("allChildren", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic);
				
			FieldInfo windowsReorderedField = typeof(EditorApplication).GetField("windowsReordered", BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic);
			windowsReordered = windowsReorderedField.GetValue(null) as EditorApplication.CallbackFunction;

			System.Type projectWindowUtilType = editorAssembly.GetType("UnityEditor.ProjectWindowUtil");
			if (projectWindowUtilType != null)
				createAssetMethod = projectWindowUtilType.GetMethod("CreateAsset", new System.Type[] { typeof(Object), typeof(string) });
		}
开发者ID:CountrysideGames,项目名称:Nostalgia,代码行数:27,代码来源:FGCodeWindow.cs

示例6: SelectInterceptors

        /// <summary>Select interceptors which must be applied to the method.</summary>
        /// <param name="type">The type.</param>
        /// <param name="method">The method.</param>
        /// <param name="interceptors">The interceptors.</param>
        /// <returns>The interceptors after filtering.</returns>
        public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
        {
            if (method.IsGetter())
            {
                var propertyInfo = type.GetProperty(method);
                if (propertyInfo.IsPropertyWithSelectorAttribute())
                {
                    return typeof(BaseHtmlElement).IsAssignableFrom(method.ReturnType) 
                        ? interceptors.Where(x => x is PropertyInterceptor).ToArray() 
                        : interceptors.Where(x => x is CollectionPropertyInterceptor).ToArray();
                }
            }

            if (method.IsSetter())
            {
                var propertyInfo = type.GetProperty(method);
                if (propertyInfo.IsPropertyWithSelectorAttribute())
                {
                    return interceptors.Where(x => x is InvalidWriteOperationInterceptor).ToArray();
                }
            }

            return interceptors.Where(x => !(x is PropertyInterceptor) 
                && !(x is CollectionPropertyInterceptor)
                && !(x is InvalidWriteOperationInterceptor)).ToArray();
        }
开发者ID:pbakshy,项目名称:Selenol,代码行数:31,代码来源:InterceptorSelector.cs

示例7: EntityMetadataBase

 /// <summary>
 /// Initialize entity metadata.
 /// </summary>
 /// <param name="entityType"></param>
 protected EntityMetadataBase(Type entityType)
 {
     if (entityType == null)
         throw new ArgumentNullException("entityType");
     Type = entityType;
     var key = entityType.GetProperties().FirstOrDefault(t => t.GetCustomAttribute<KeyAttribute>() != null);
     if (key != null)
         KeyType = key.PropertyType;
     else
     {
         key = entityType.GetProperty("Index");
         if (key != null)
             KeyType = key.PropertyType;
         else
         {
             key = entityType.GetProperty("Id");
             if (key != null)
                 KeyType = key.PropertyType;
             else
             {
                 key = entityType.GetProperty("ID");
                 if (key != null)
                     KeyType = key.PropertyType;
             }
         }
     }
 }
开发者ID:alexyjian,项目名称:ComBoost,代码行数:31,代码来源:EntityMetadataBase.cs

示例8: Logging

            public Logging()
            {
                _loggingType = Type.GetType("System.Net.Logging, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

                if (_loggingType == null)
                {
                    return;
                }

                var webProperty = _loggingType.GetProperty("Web", BindingFlags.NonPublic | BindingFlags.Static);
                if (webProperty != null)
                {
                    Sources.Add((TraceSource)webProperty.GetValue(null));
                }

                var socketsProperty = _loggingType.GetProperty("Sockets", BindingFlags.NonPublic | BindingFlags.Static);
                if (socketsProperty != null)
                {
                    Sources.Add((TraceSource)socketsProperty.GetValue(null));
                }

                var webSocketsProperty = _loggingType.GetProperty("WebSockets", BindingFlags.NonPublic | BindingFlags.Static);
                if (webSocketsProperty != null)
                {
                    Sources.Add((TraceSource)webSocketsProperty.GetValue(null));
                }
            }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:27,代码来源:SystemNetLogging.cs

示例9: IsInteresting

 public static bool IsInteresting(Type t)
 {
     if (t == null || t.Namespace == null) return false;
     if (t.IsEnum || !t.Namespace.StartsWith(SchemaBuilder.Linq2AzureNamespace)) return false;
     if (t.GetProperty("Subscription") == null && t.GetProperty("Parent") == null) return false;
     return true;
 }
开发者ID:jamesmiles,项目名称:API,代码行数:7,代码来源:CustomMemberProvider.cs

示例10: FromController

 public void FromController(Type ctrl)
 {
     ProductCode = (string)ctrl.GetProperty("ProductCode", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null, null);
     ProductName = (string)ctrl.GetProperty("ProductName", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null, null);
     ProductKey = (string)ctrl.GetProperty("ProductKey", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null, null);
     Version = (string)ctrl.GetProperty("Version", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null, null);
 }
开发者ID:dnnsharp,项目名称:DynamicRotator,代码行数:7,代码来源:RegCoreApp.cs

示例11: CheckHasMethodRemoved

 private void CheckHasMethodRemoved(Type proto2Type, Type proto3Type, string name)
 {
     Assert.NotNull(proto2Type.GetProperty(name));
     Assert.NotNull(proto2Type.GetProperty("Has" + name));
     Assert.NotNull(proto3Type.GetProperty(name));
     Assert.Null(proto3Type.GetProperty("Has" + name));
 }
开发者ID:JuWell,项目名称:SmallNetGame,代码行数:7,代码来源:FieldPresenceTest.cs

示例12: ProjectElement

        static ProjectElement()
        {
            s_projectElement =
                Type.GetType(
                    "Microsoft.Build.Construction.ProjectElement, Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
                    false,
                    false);

            if (s_projectElement != null)
            {
                s_projectElementLocation = s_projectElement.GetProperty("Location");
            }

            s_elementLocation =
                Type.GetType(
                    "Microsoft.Build.Construction.ElementLocation, Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
                    false,
                    false);

            if (s_elementLocation != null)
            {
                s_elementLocationFile = s_elementLocation.GetProperty("File");
                s_elementLocationLine= s_elementLocation.GetProperty("Line");
                s_elementLocationColumn = s_elementLocation.GetProperty("Column");
                s_elementLocationLocationString = s_elementLocation.GetProperty("LocationString");
            }
        }
开发者ID:sbambach,项目名称:ATF,代码行数:27,代码来源:ProjectElement.cs

示例13: DisplayStringAttribute

 public DisplayStringAttribute(Type resourceManagerType, string resourceKey)
 {
     PropertyInfo property = resourceManagerType.GetProperty(resourceKey);
       if (property == (PropertyInfo) null)
     property = resourceManagerType.GetProperty(resourceKey, BindingFlags.Static | BindingFlags.NonPublic);
       this.Value = property.GetValue((object) null, (object[]) null) as string;
 }
开发者ID:sulerzh,项目名称:wpfext,代码行数:7,代码来源:DisplayStringAttribute.cs

示例14: DataContractResolverStrategy

		/// <summary>
		/// CCtor
		/// </summary>
		static DataContractResolverStrategy()
		{
			string[] assemblyName = typeof(Object).Assembly.FullName.Split(',');
			assemblyName[0] = DataContractAssemblyName;

			Assembly assembly = Assembly.Load(String.Join(",", assemblyName));

			DataContractType = assembly.GetType(DataContractTypeName);
			DataMemberType = assembly.GetType(DataMemberTypeName);
			IgnoreDataMemberType = assembly.GetType(IgnoreDataMemberTypeName);

			if (DataContractType != null)
			{
				PropertyInfo property = DataContractType.GetProperty("Name", BindingFlags.Public|BindingFlags.Instance|BindingFlags.FlattenHierarchy);
				DataContractNameGetter = DynamicMethodGenerator.GetPropertyGetter(property);
				property = DataContractType.GetProperty("Namespace", BindingFlags.Public|BindingFlags.Instance|BindingFlags.FlattenHierarchy);
				DataContractNamespaceGetter = DynamicMethodGenerator.GetPropertyGetter(property);
			}

			if (DataContractResolverStrategy.DataMemberType != null)
			{
				PropertyInfo property = DataMemberType.GetProperty("Name", BindingFlags.Public|BindingFlags.Instance|BindingFlags.FlattenHierarchy);
				DataMemberNameGetter = DynamicMethodGenerator.GetPropertyGetter(property);
			}
		}
开发者ID:RocketChicken,项目名称:jsonfx,代码行数:28,代码来源:DataContractResolverStrategy.cs

示例15: Read

        object Read(XmlReader reader, Type type)
        {
            var obj = Activator.CreateInstance(type);

            if (reader.HasAttributes)
            {
                reader.MoveToFirstAttribute();
                do
                {
                    var propertyInfo = type.GetProperty(reader.Name);
                    propertyInfo
                        .SetValue(
                            obj,
                            Convert.ChangeType(reader.Value, propertyInfo.PropertyType)
                        );
                } while (reader.MoveToNextAttribute());
            }

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        var propertyInfo = type.GetProperty(reader.Name);
                        propertyInfo
                            .SetValue(
                                obj,
                                ReadValue(reader, propertyInfo.PropertyType)
                            );
                        break;
                }
            }

            return obj;
        }
开发者ID:MrAntix,项目名称:Serializing,代码行数:35,代码来源:POXSerializer.deserialize.cs


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