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


C# PropertyInfo.FirstOrDefault方法代码示例

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


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

示例1: FindAttachedModelProperty

		public PropertyInfo FindAttachedModelProperty(PropertyInfo queryProperty, PropertyInfo[] modelProperties)
		{
			var queryPropertyName = queryProperty.Name;
			if (!queryPropertyName.EndsWith(Suffix)) return null;
			if (queryProperty.PropertyType.GetGenericTypeDefinition() != typeof (Range<>)) return null;
			return
				modelProperties.FirstOrDefault(modelProperty => queryPropertyName == modelProperty.Name + Suffix);
		}
开发者ID:tianzhiyuan,项目名称:agile,代码行数:8,代码来源:RangeAnalyzer.cs

示例2: CopyFromModel

 public void CopyFromModel(PropertyInfo vm, object model, PropertyInfo[] modelProps)
 {
     var ckf = vm.GetAttribute<FieldInfoAttribute>().CheckboxField;
     var ckpi = modelProps.Single(ss => ss.Name == ckf);
     var ck = ckpi.GetValue(model, null) as bool?;
     var m = modelProps.FirstOrDefault(mm => mm.Name == vm.Name);
     Number = ((string)m.GetValue(model, null)).FmtFone();
     ReceiveText = ck ?? false;
 }
开发者ID:stevesloka,项目名称:bvcms,代码行数:9,代码来源:BasicPersonInfo.cs

示例3: CopyToModel

 public List<ChangeDetail> CopyToModel(PropertyInfo vm, object model, PropertyInfo[] modelProps, bool track)
 {
     var changes = new List<ChangeDetail>();
     var ckf = vm.GetAttribute<FieldInfoAttribute>().CheckboxField;
     var ckpi = modelProps.Single(mm => mm.Name == ckf);
     if (track)
     {
         model.UpdateValue(changes, vm.Name, Number.GetDigits());
         model.UpdateValue(changes, ckf, ReceiveText);
         return changes;
     }
     var ci = modelProps.FirstOrDefault(ss => ss.Name == vm.Name);
     Debug.Assert(ci != null, "ci != null");
     ci.SetValue(model, Number.GetDigits(), null);
     ckpi.SetValue(model, ReceiveText, null);
     return changes;
 }
开发者ID:stevesloka,项目名称:bvcms,代码行数:17,代码来源:BasicPersonInfo.cs

示例4: setPropertyFromXmlNode

        //savePropertyFromChildNode
        private void setPropertyFromXmlNode(XmlNode node, PropertyInfo[] properties)
        {
            var property = properties.FirstOrDefault(x => x.Name == node.Name);
            if (property != null && !String.IsNullOrEmpty(node.InnerText))
            {
                if (property.PropertyType == typeof(int)) { property.SetValue(this, int.Parse(node.InnerText), null); }
                if (property.PropertyType == typeof(String)) { property.SetValue(this, node.InnerText, null); }

            }
        }
开发者ID:naishan,项目名称:GroutItToGw,代码行数:11,代码来源:AppSettings.cs

示例5: TryFindAndCreateEnumProperties

        private bool TryFindAndCreateEnumProperties(
            Type type, StructuralType cspaceType, StructuralType ospaceType, PropertyInfo[] clrProperties,
            List<Action> referenceResolutionListForCurrentType)
        {
            var typeClosureToTrack = new List<KeyValuePair<EdmProperty, PropertyInfo>>();

            foreach (
                var cspaceProperty in cspaceType.GetDeclaredOnlyMembers<EdmProperty>().Where(p => Helper.IsEnumType(p.TypeUsage.EdmType)))
            {
                var clrProperty = clrProperties.FirstOrDefault(p => MemberMatchesByConvention(p, cspaceProperty));
                if (clrProperty != null)
                {
                    typeClosureToTrack.Add(new KeyValuePair<EdmProperty, PropertyInfo>(cspaceProperty, clrProperty));
                }
                else
                {
                    var message = Strings.Validator_OSpace_Convention_MissingRequiredProperty(cspaceProperty.Name, type.FullName);
                    SessionData.LoadMessageLogger.LogLoadMessage(message, cspaceType);
                    return false;
                }
            }

            foreach (var typeToTrack in typeClosureToTrack)
            {
                TrackClosure(typeToTrack.Value.PropertyType);
                // prevent the lifting of these closure variables
                var ot = ospaceType;
                var cp = typeToTrack.Key;
                var clrp = typeToTrack.Value;
                referenceResolutionListForCurrentType.Add(() => CreateAndAddEnumProperty(type, ot, cp, clrp));
            }

            return true;
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:34,代码来源:ObjectItemConventionAssemblyLoader.cs

示例6: TryFindAndCreatePrimitiveProperties

 private bool TryFindAndCreatePrimitiveProperties(
     Type type, StructuralType cspaceType, StructuralType ospaceType, PropertyInfo[] clrProperties)
 {
     foreach (
         var cspaceProperty in
             cspaceType.GetDeclaredOnlyMembers<EdmProperty>().Where(p => Helper.IsPrimitiveType(p.TypeUsage.EdmType)))
     {
         var clrProperty = clrProperties.FirstOrDefault(p => MemberMatchesByConvention(p, cspaceProperty));
         if (clrProperty != null)
         {
             PrimitiveType propertyType;
             if (TryGetPrimitiveType(clrProperty.PropertyType, out propertyType))
             {
                 if (clrProperty.CanRead
                     && clrProperty.CanWrite)
                 {
                     AddScalarMember(type, clrProperty, ospaceType, cspaceProperty, propertyType);
                 }
                 else
                 {
                     var message = Strings.Validator_OSpace_Convention_ScalarPropertyMissginGetterOrSetter(
                         clrProperty.Name, type.FullName, type.Assembly.FullName);
                     SessionData.LoadMessageLogger.LogLoadMessage(message, cspaceType);
                     return false;
                 }
             }
             else
             {
                 var message = Strings.Validator_OSpace_Convention_NonPrimitiveTypeProperty(
                     clrProperty.Name, type.FullName, clrProperty.PropertyType.FullName);
                 SessionData.LoadMessageLogger.LogLoadMessage(message, cspaceType);
                 return false;
             }
         }
         else
         {
             var message = Strings.Validator_OSpace_Convention_MissingRequiredProperty(cspaceProperty.Name, type.FullName);
             SessionData.LoadMessageLogger.LogLoadMessage(message, cspaceType);
             return false;
         }
     }
     return true;
 }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:43,代码来源:ObjectItemConventionAssemblyLoader.cs

示例7: TryFindNavigationProperties

        private bool TryFindNavigationProperties(
            Type type, StructuralType cspaceType, StructuralType ospaceType, PropertyInfo[] clrProperties,
            List<Action> referenceResolutionListForCurrentType)
        {
            var typeClosureToTrack =
                new List<KeyValuePair<NavigationProperty, PropertyInfo>>();
            foreach (var cspaceProperty in cspaceType.GetDeclaredOnlyMembers<NavigationProperty>())
            {
                var clrProperty = clrProperties.FirstOrDefault(p => NonPrimitiveMemberMatchesByConvention(p, cspaceProperty));
                if (clrProperty != null)
                {
                    var needsSetter = cspaceProperty.ToEndMember.RelationshipMultiplicity != RelationshipMultiplicity.Many;
                    if (clrProperty.CanRead
                        && (!needsSetter || clrProperty.CanWrite))
                    {
                        typeClosureToTrack.Add(
                            new KeyValuePair<NavigationProperty, PropertyInfo>(
                                cspaceProperty, clrProperty));
                    }
                }
                else
                {
                    var message = Strings.Validator_OSpace_Convention_MissingRequiredProperty(
                        cspaceProperty.Name, type.FullName);
                    SessionData.LoadMessageLogger.LogLoadMessage(message, cspaceType);
                    return false;
                }
            }

            foreach (var typeToTrack in typeClosureToTrack)
            {
                TrackClosure(typeToTrack.Value.PropertyType);

                // keep from lifting these closure variables
                var ct = cspaceType;
                var ot = ospaceType;
                var cp = typeToTrack.Key;
                var clrp = typeToTrack.Value;

                referenceResolutionListForCurrentType.Add(() => CreateAndAddNavigationProperty(ct, ot, cp, clrp));
            }

            return true;
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:44,代码来源:ObjectItemConventionAssemblyLoader.cs

示例8: CopyFromModel

 public void CopyFromModel(PropertyInfo vm, object existing, object model, PropertyInfo[] modelProps)
 {
     string altname = vm.Name + "Id";
     var fiattr = vm.GetAttribute<FieldInfoAttribute>();
     if (fiattr != null && fiattr.IdField.HasValue())
         altname = fiattr.IdField;
     var mid = modelProps.FirstOrDefault(mm => mm.Name == altname || mm.Name == vm.Name);
     var midvalue = mid.GetValue(model, null);
     if (mid.PropertyType == typeof(int?) || mid.PropertyType == typeof(int))
         Value = midvalue.ToInt().ToString();
     else if (midvalue == null)
         Value = null;
     else if (mid.PropertyType.Name == "CodeInfo")
         Value = ((CodeInfo) midvalue).Value;
     else
         Value = midvalue.ToString();
     var cinfo = midvalue as CodeInfo;
     if (cinfo == null && existing != null)
         cinfo = existing as CodeInfo;
     if (items == null && cinfo != null && cinfo.items != null)
         items = cinfo.items;
     Name = vm.Name;
 }
开发者ID:clearfunction,项目名称:bvcms,代码行数:23,代码来源:CodeInfo.cs

示例9: CopyToModel

        public List<ChangeDetail> CopyToModel(PropertyInfo vm, object model, PropertyInfo[] modelProps, bool track)
        {
            var changes = new List<ChangeDetail>();
            string altname = vm.Name + "Id";
            var attr = vm.GetAttribute<FieldInfoAttribute>();
            if (attr != null && attr.IdField.HasValue())
                altname = attr.IdField;
            var mid = modelProps.FirstOrDefault(mm => mm.Name == altname || mm.Name == vm.Name);

            if (mid == null)
                return changes;

            if (mid.PropertyType.Name == "CodeInfo")
            {
                Util.SetPropertyEx(model, vm.Name + ".Value", Value == "0" ? null : Value);
            }
            else
            {
                if (track)
                {
                    if (mid.PropertyType == typeof(int?) || mid.PropertyType == typeof(int))
                        if (Value == "0")
                            model.UpdateValue(changes, altname, null);
                        else
                            model.UpdateValue(changes, altname, Value.ToInt());
                    return changes;
                }
                mid.SetPropertyFromText(model, Value == "0" ? null : Value);
            }

            return changes;
        }
开发者ID:clearfunction,项目名称:bvcms,代码行数:32,代码来源:CodeInfo.cs

示例10: CopyToModel

 public string CopyToModel(PropertyInfo vm, object model, PropertyInfo[] modelProps, bool track)
 {
     string altname = vm.Name + "Id";
     var attr = vm.GetAttribute<FieldInfoAttribute>();
     if (attr != null && attr.IdField.HasValue())
         altname = attr.IdField;
     var mid = modelProps.FirstOrDefault(mm => mm.Name == altname || mm.Name == vm.Name);
     if (mid == null)
         return string.Empty;
     if (track)
     {
         var changes = new StringBuilder();
         if (mid.PropertyType == typeof(int?) || mid.PropertyType == typeof(int))
             if (Value == "0")
                 model.UpdateValue(changes, altname, null);
             else
                 model.UpdateValue(changes, altname, Value.ToInt());
         return changes.ToString();
     }
     mid.SetPropertyFromText(model, Value);
     return string.Empty;
 }
开发者ID:hkouns,项目名称:bvcms,代码行数:22,代码来源:CodeInfo.cs

示例11: CopyFromModel

 public void CopyFromModel(PropertyInfo vm, object model, PropertyInfo[] modelProps)
 {
     string altname = vm.Name + "Id";
     var fiattr = vm.GetAttribute<FieldInfoAttribute>();
     if (fiattr != null && fiattr.IdField.HasValue())
         altname = fiattr.IdField;
     var mid = modelProps.FirstOrDefault(mm => mm.Name == altname || mm.Name == vm.Name);
     var midvalue = mid.GetValue(model, null);
     if (mid.PropertyType == typeof(int?) || mid.PropertyType == typeof(int))
         Value = midvalue.ToInt().ToString();
     else if (midvalue == null)
         Value = null;
     else
         Value = midvalue.ToString();
     Name = vm.Name;
 }
开发者ID:hkouns,项目名称:bvcms,代码行数:16,代码来源:CodeInfo.cs

示例12: FindAttachedModelProperty

		public PropertyInfo FindAttachedModelProperty(PropertyInfo queryProperty, PropertyInfo[] modelProperties)
		{
			var queryPropertyName = queryProperty.Name;
			if (!queryPropertyName.EndsWith(Suffix)) return null;
			if (!TypeUtils.IsBaseEntityQuery(queryProperty.PropertyType)) return null;
			return modelProperties.FirstOrDefault(modelProperty => modelProperty.Name + Suffix == queryPropertyName);
		}
开发者ID:tianzhiyuan,项目名称:agile,代码行数:7,代码来源:NavigationAnalyzer.cs

示例13: CopyToModel

 public string CopyToModel(PropertyInfo vm, object model, PropertyInfo[] modelProps, bool track)
 {
     var ckf = vm.GetAttribute<FieldInfoAttribute>().CheckboxField;
     var ckpi = modelProps.Single(mm => mm.Name == ckf);
     if (track)
     {
         var changes = new StringBuilder();
         model.UpdateValue(changes, vm.Name, Address);
         model.UpdateValue(changes, ckf, Send);
         return changes.ToString();
     }
     var ci = modelProps.FirstOrDefault(ss => ss.Name == vm.Name);
     Debug.Assert(ci != null, "ci != null");
     ci.SetValue(model, Address, null);
     ckpi.SetValue(model, Send, null);
     return string.Empty;
 }
开发者ID:hkouns,项目名称:bvcms,代码行数:17,代码来源:BasicPersonInfo.cs

示例14: AssignListParameter

    /// <summary>
    /// If command has a ListParameter, assign unmatched  values from <c>numbered</c> to it.
    /// </summary>
    /// <param name="cmd">The command</param>
    /// <param name="properties">The command properties</param>
    /// <param name="numbered">Unmatched parameteres from ExtractParameters call</param>
    private void AssignListParameter(ICommand cmd, PropertyInfo[] properties, string[] numbered)
    {
      var listProperty = properties.FirstOrDefault(p => CommandInspector.GetListParameter(p) != null);
      if (listProperty == null)
        return;

      var numberedParameters = properties.Select(CommandInspector.GetNumberedParameter)
                         .Where(p => p != null)
                         .Select(p => p.Number);

      int numberedParametersToSkip = (numberedParameters.Any()) ? numberedParameters.Max() + 1 : 0;
      var list = numbered.Skip(numberedParametersToSkip).ToList();
      list = (from element in list
        select Parser.PerformSubstitution(_context, element)).ToList();
#if NET45
      listProperty.SetValue(cmd, list);
#else
      listProperty.SetValue(cmd, list, null);
#endif
    }
开发者ID:KerwinMa,项目名称:revolver,代码行数:26,代码来源:CommandHandler.cs


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