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


C# Type.GetRuntimeProperties方法代码示例

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


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

示例1: ProvideRules

        public IEnumerable<IValidationRule> ProvideRules(Type objectType, IEnumerable<string> standards)
        {
            List<IValidationRule> returnList = new List<IValidationRule>();
            List<Attribute> typeAttributes = new List<Attribute>(objectType.GetTypeInfo().GetCustomAttributes());

            foreach (IAttributeValidationRuleProvider attributeValidationRuleProvider in attributeValidationRuleProviders)
            {
                returnList.AddRange(attributeValidationRuleProvider.ProvideRules(objectType, typeAttributes, null, null));
            }

            foreach (PropertyInfo runtimeProperty in objectType.GetRuntimeProperties())
            {
                if (!runtimeProperty.CanRead ||
                     !runtimeProperty.GetMethod.IsPublic ||
                     runtimeProperty.GetMethod.IsStatic)
                {
                    continue;
                }

                foreach (IAttributeValidationRuleProvider attributeValidationRuleProvider in attributeValidationRuleProviders)
                {
                    List<Attribute> propertyAttributes = new List<Attribute>(runtimeProperty.GetCustomAttributes());

                    returnList.AddRange(attributeValidationRuleProvider.ProvideRules(objectType, typeAttributes, runtimeProperty, propertyAttributes));
                }
            }

            return returnList;
        }
开发者ID:jrjohn,项目名称:Grace,代码行数:29,代码来源:AttributeValidationRuleProvider.cs

示例2: OnBuildRequest

        protected override JsTypeDefinition OnBuildRequest(Type t)
        {
            JsTypeDefinition typedefinition = new JsTypeDefinition(t.Name);

            //only instance /public method /prop***
            //MethodInfo[] methods = t.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            var methods = t.GetRuntimeMethods();
            foreach (var met in methods)
            {
                if(!met.IsStatic && met.IsPublic)
                {
                    typedefinition.AddMember(new JsMethodDefinition(met.Name, met));
                }
            }

            //var properties = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            var properties = t.GetRuntimeProperties();
            //TODO finding GetProperties with BindingFlags
            foreach (var property in properties)
            {
                typedefinition.AddMember(new JsPropertyDefinition(property.Name, property)); 
            }

            return typedefinition;
        }
开发者ID:prepare,项目名称:HTML-Renderer,代码行数:25,代码来源:JsTypeDefinitionBuilder.cs

示例3: GetProperties

    internal static IEnumerable<PropertyInfo> GetProperties(Type type) {
#if MONO || UNITY
      return type.GetProperties();
#else
      return type.GetRuntimeProperties();
#endif
    }
开发者ID:cnbcyln,项目名称:Parse-SDK-dotNET,代码行数:7,代码来源:ReflectionHelpers.cs

示例4: SerializeMembers

 /// <summary>
 /// Serialize a list of members from the object.
 /// </summary>
 /// <param name="serializer">The serializer to utilize when serializing the values.</param>
 /// <param name="type">The type of the object to serialize the members from.</param>
 /// <param name="value">The value to serialize the members from.</param>
 /// <returns>The list of members that make up the object.</returns>
 static IEnumerable<JsonMember> SerializeMembers(IJsonSerializer serializer, Type type, object value)
 {
     foreach (var property in type.GetRuntimeProperties().Where(p => p.CanRead))
     {
         yield return new JsonMember(serializer.FieldNamingStrategy.GetName(property.Name), serializer.SerializeValue(property.GetValue(value)));
     }
 }
开发者ID:cosullivan,项目名称:Hypermedia,代码行数:14,代码来源:ComplexConverter.cs

示例5: ValidateContract

        public static void ValidateContract(Type contract)
        {
            if (contract == null)
            {
                throw new ArgumentNullException(nameof(contract));
            }

            if (!contract.GetTypeInfo().IsInterface)
            {
                throw new InvalidOperationException(
                    $"Unable to use class '{contract.FullName}' as contract because only interface contracts are supported.");
            }

            if (contract.GetRuntimeProperties().Any())
            {
                throw new InvalidOperationException(
                    $"Unable to use interface '{contract.FullName}' as contract because it contains properties.");
            }

            IEnumerable<MethodInfo> methods = contract.GetRuntimeMethods().ToList();
            if (methods.Count() != methods.Select(m=>m.Name).Distinct().Count())
            {
                throw new InvalidOperationException(
                    $"Unable to use interface '{contract.FullName}' as contract because it methods with the same name.");
            }
        }
开发者ID:geffzhang,项目名称:Bolt,代码行数:26,代码来源:BoltFramework.cs

示例6: GetAllDependants

        /// <summary>
        /// Recursively gathers the list of all properties which depend
        /// on the provided property, whether directly or indirectly.
        /// Each dependent property will only be included once, so
        /// multiple or circular dependencies will not result in multiple
        /// <see cref="INotifyPropertyChanged.PropertyChanged"/> events.
        /// </summary>
        /// <param name="targetType">The object in which the properties reside.</param>
        /// <param name="propertyName">
        /// The name of the property for which to collect all dependent properties.
        /// </param>
        /// <returns>
        /// Returns the list of all properties which are directly or
        /// indirectly dependent on the original property.
        /// </returns>
        public static IEnumerable<PropertyInfo> GetAllDependants(Type targetType, string propertyName)
        {
            //Retrieve the Property Info for the specified property
            var propertyInfo = targetType.GetRuntimeProperties()
                .First(x => x.Name == propertyName);

            IEnumerable<PropertyInfo> oldResults = null;
            IEnumerable<PropertyInfo> results = new[] { propertyInfo };
            do
            {
                oldResults = results;

                var dependancies = from input in results
                                   from dependancy in GetDirectDependants(targetType, input.Name)
                                   select dependancy;

                //Create union of current results with "new" results,
                //making sure to remove duplicates
                results = results.Union(dependancies)
                    .GroupBy((x) => x.Name)
                    .Select(grp => grp.First());
            }
            while (results.Count() > oldResults.Count());

            //Return results not including the original property name
            return results.Where(x => (x.Name != propertyName));
        }
开发者ID:btowntkd,项目名称:Tourney2015MatchListViewer,代码行数:42,代码来源:DependsOnAttribute.cs

示例7: FormatCompledValue

        private static string FormatCompledValue(object value, int depth, Type type)
        {
            if (depth == MAX_DEPTH)
                return String.Format("{0} {{ ... }}", type.Name);

            var fields = type.GetRuntimeFields()
                             .Where(f => f.IsPublic && !f.IsStatic)
                             .Select(f => new { name = f.Name, value = WrapAndGetFormattedValue(() => f.GetValue(value), depth) });
            var properties = type.GetRuntimeProperties()
                                 .Where(p => p.GetMethod != null && p.GetMethod.IsPublic && !p.GetMethod.IsStatic)
                                 .Select(p => new { name = p.Name, value = WrapAndGetFormattedValue(() => p.GetValue(value), depth) });
            var parameters = fields.Concat(properties)
                                   .OrderBy(p => p.name)
                                   .Take(MAX_OBJECT_PARAMETER_COUNT + 1)
                                   .ToList();

            if (parameters.Count == 0)
                return String.Format("{0} {{ }}", type.Name);

            var formattedParameters = String.Join(", ", parameters.Take(MAX_OBJECT_PARAMETER_COUNT)
                                                                  .Select(p => String.Format("{0} = {1}", p.name, p.value)));

            if (parameters.Count > MAX_OBJECT_PARAMETER_COUNT)
                formattedParameters += ", ...";

            return String.Format("{0} {{ {1} }}", type.Name, formattedParameters);
        }
开发者ID:Tofudebeast,项目名称:xunit,代码行数:27,代码来源:ArgumentFormatter.cs

示例8: GetSheet

        public static Sheet GetSheet(Type t)
        {
            var sheetAttr = (SheetAttribute)t.GetAttribute(typeof(SheetAttribute));
            var sheetName = sheetAttr != null ? sheetAttr.Name : t.Name;
            var definedColumn = sheetAttr != null ? sheetAttr.DefinedColumn : "";
            var startingComments = sheetAttr != null && sheetAttr.StartingComments != null ? sheetAttr.StartingComments.ToList() : new List<string>();

            var properties = from property in t.GetRuntimeProperties()
                    where (property.GetMethod != null && property.GetMethod.IsPublic)
                || (property.SetMethod != null && property.SetMethod.IsPublic)
                || (property.GetMethod != null && property.GetMethod.IsStatic)
                || (property.SetMethod != null && property.SetMethod.IsStatic)
                select property;

            var columns = new List<Column>();
            foreach(var property in properties)
            {
                var ignore = property.GetCustomAttribute(typeof(IgnoredColumnAttribute), true);

                if (property.CanWrite && ignore == null)
                {
                    columns.Add(new Column(property));
                }
            }

            return new Sheet(sheetName, columns, definedColumn, startingComments);
        }
开发者ID:naokirin,项目名称:Buffet,代码行数:27,代码来源:Sheet.cs

示例9: GetProperties

 public static List<PropertyInfo> GetProperties(Type type)
 {
     #if NETFX_CORE
     return type.GetRuntimeProperties().ToList();
     #else
     return type.GetProperties().ToList();
     #endif
 }
开发者ID:phicuong08,项目名称:memorymatch,代码行数:8,代码来源:ReflectionHelper.cs

示例10: GetPublicInstanceProperties

 public IEnumerable<PropertyInfo> GetPublicInstanceProperties(Type mappedType)
 {
     return from p in mappedType.GetRuntimeProperties()
         where
             ((p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic) ||
              (p.GetMethod != null && p.GetMethod.IsStatic) || (p.SetMethod != null && p.SetMethod.IsStatic))
         select p;
 }
开发者ID:Reza1024,项目名称:SQLite.Net-PCL,代码行数:8,代码来源:ReflectionServiceWinRT.cs

示例11: GetPrimaryKey

 public static string[] GetPrimaryKey(Type type) {
     return new MemberInfo[0]
         .Concat(type.GetRuntimeProperties())
         .Concat(type.GetRuntimeFields())
         .Where(m => m.GetCustomAttributes(true).Any(i => i.GetType().Name == "KeyAttribute"))
         .Select(m => m.Name)
         .OrderBy(i => i)
         .ToArray();
 }
开发者ID:DevExpress,项目名称:DevExtreme.AspNet.Data,代码行数:9,代码来源:Utils.cs

示例12: Apply

        public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type)
        {
            if (schema == null || schema.properties == null || type == null) return;

            bool isPushTrigger = type.AssemblyQualifiedNameNoTypeParams() == typeof(TriggerInput<string, string>).AssemblyQualifiedNameNoTypeParams();

            foreach (var propertyName in schema.properties.Keys)
            {
                var property = schema.properties[propertyName];

                if (isPushTrigger && propertyName == Constants.CALLBACK_URL_PROPERTY_NAME)
                {
                    #region Apply callback magic defaults

                    // Apply trigger magic defaults:
                    // "x-ms-scheduler-recommendation": "@accessKeys('default').primary.secretRunUri
                    schema.SetChildPropertyRequired(Constants.CALLBACK_URL_PROPERTY_NAME);

                    property.SetVisibility(VisibilityType.Internal);
                    property.SetSchedulerRecommendation(Constants.CALLBACK_URL_MAGIC_DEFAULT);

                    // This is what this will look like (pulled from HTTP Listener API Definition)
                    //
                    // "TriggerInput[TriggerPushParameters,TriggerOutputParameters]": {
                    //     "required": [            <-- SetChildPropertyRequired (on the parent model containing the callbackUrl property)
                    //       "callbackUrl"
                    // ],
                    // "type": "object",
                    // "properties": {
                    //   "callbackUrl": {            <-- SetSchedulerRecommendation (on the actual property)
                    //     "type": "string",
                    //     "x-ms-visibility": "internal",
                    //     "x-ms-scheduler-recommendation": "@accessKeys('default').primary.secretRunUri"
                    //   },

                    #endregion
                }

                // Apply friendly names and descriptions wherever possible
                // "x-ms-summary" - friendly name (applies to properties)
                // schema.properties["prop"].description - description (applies to parameters)

                var propertyInfo = type.GetRuntimeProperties().Where(p => p.Name == propertyName).FirstOrDefault();

                if (propertyInfo == null) return;

                var propertyMetadata = propertyInfo.GetCustomAttribute<MetadataAttribute>();

                if (propertyMetadata != null)
                {
                    property.SetVisibility(propertyMetadata.Visibility);
                    property.SetFriendlyNameAndDescription(propertyMetadata.FriendlyName, propertyMetadata.Description);
                }

            }
        }
开发者ID:ninocrudele,项目名称:TRex,代码行数:56,代码来源:TRexSchemaFilter.cs

示例13: GetPublicInstanceProperties

 public IEnumerable<PropertyInfo> GetPublicInstanceProperties(Type mappedType)
 {
     if (mappedType == null)
     {
         throw new ArgumentNullException("mappedType");
     }
     return from p in mappedType.GetRuntimeProperties()
         where
             ((p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic) ||
              (p.GetMethod != null && p.GetMethod.IsStatic) || (p.SetMethod != null && p.SetMethod.IsStatic))
         select p;
 }
开发者ID:Reza1024,项目名称:SQLite.Net-PCL,代码行数:12,代码来源:ReflectionServiceWP8.cs

示例14: GetProperty

        public static PropertyInfo GetProperty(Type sourceType, string propertyName)
        {
            var allProperties = sourceType.GetRuntimeProperties ();
            var property = allProperties.Where(
                mi => string.Equals(propertyName, mi.Name, StringComparison.Ordinal)).ToList();

            if (property.Count > 1)
            {
                throw new AmbiguousMatchException();
            }

            return property.FirstOrDefault();
        }
开发者ID:rid00z,项目名称:JellyBeanTracker,代码行数:13,代码来源:ReflectionHelpers.cs

示例15: GetProperties

        public static IEnumerable<Property> GetProperties(Type type)
        {
            lock (PropertyCacheByType)
            {
                if (!PropertyCacheByType.ContainsKey(type))
                {
                    var properties = type.GetRuntimeProperties().Select(p => new Property(p, GetCustomAttributes(p))).ToList();
                    PropertyCacheByType[type] = properties;
                }

                return PropertyCacheByType[type];
            }
        }
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:13,代码来源:ReflectionCache.cs


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