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


C# Type.GetProperty方法代码示例

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


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

示例1: WriteGetKeyImpl


//.........这里部分代码省略.........
                            int lastKey = -1;
                            for (int i = 0; i < methodPairs.Length; i++)
                            {
                                if (methodPairs[i].MetaKey == methodPairs[i].BaseKey) break;
                                if (lastKey == methodPairs[i].BaseKey)
                                {   // add the last label again
                                    getKeyLabels.Add(getKeyLabels[getKeyLabels.Count - 1]);
                                }
                                else
                                {   // add a new unique label
                                    getKeyLabels.Add(ctx.DefineLabel());
                                    lastKey = methodPairs[i].BaseKey;
                                }
                            }
                            Compiler.CodeLabel[] subtypeLabels = new Compiler.CodeLabel[getKeyLabels.Count];
                            getKeyLabels.CopyTo(subtypeLabels, 0);

                            ctx.Switch(subtypeLabels);
                            il.Emit(OpCodes.Ldloc_0); // not a sub-type; use the original value
                            il.Emit(OpCodes.Ret);

                            lastKey = -1;
                            // now output the different branches per sub-type (not derived type)
                            for (int i = subtypeLabels.Length - 1; i >= 0; i--)
                            {
                                if (lastKey != methodPairs[i].BaseKey)
                                {
                                    lastKey = methodPairs[i].BaseKey;
                                    // find the actual base-index for this base-key (i.e. the index of
                                    // the base-type)
                                    int keyIndex = -1;
                                    for (int j = subtypeLabels.Length; j < methodPairs.Length; j++)
                                    {
                                        if (methodPairs[j].BaseKey == lastKey && methodPairs[j].MetaKey == lastKey)
                                        {
                                            keyIndex = j;
                                            break;
                                        }
                                    }
                                    ctx.MarkLabel(subtypeLabels[i]);
                                    Compiler.CompilerContext.LoadValue(il, keyIndex);
                                    il.Emit(OpCodes.Ret);
                                }
                            }
                        }
                        else
                        {
                            il.Emit(OpCodes.Ret);
                        }
                    }
                    break;
                case KnownTypes_Dictionary:
                    {
                        LocalBuilder result = il.DeclareLocal(MapType(typeof(int)));
                        Label otherwise = il.DefineLabel();
                        il.Emit(OpCodes.Ldsfld, knownTypes);
                        il.Emit(OpCodes.Ldarg_1);
                        il.Emit(OpCodes.Ldloca_S, result);
                        il.EmitCall(OpCodes.Callvirt, knownTypesLookupType.GetMethod("TryGetValue", BindingFlags.Instance | BindingFlags.Public), null);
                        il.Emit(OpCodes.Brfalse_S, otherwise);
                        il.Emit(OpCodes.Ldloc_S, result);
                        il.Emit(OpCodes.Ret);
                        il.MarkLabel(otherwise);
                        il.Emit(OpCodes.Ldc_I4_M1);
                        il.Emit(OpCodes.Ret);
                    }
                    break;
                case KnownTypes_Hashtable:
                    {
                        Label otherwise = il.DefineLabel();
                        il.Emit(OpCodes.Ldsfld, knownTypes);
                        il.Emit(OpCodes.Ldarg_1);
                        il.EmitCall(OpCodes.Callvirt, knownTypesLookupType.GetProperty("Item").GetGetMethod(), null);
                        il.Emit(OpCodes.Dup);
                        il.Emit(OpCodes.Brfalse_S, otherwise);
#if FX11
                        il.Emit(OpCodes.Unbox, MapType(typeof(int)));
                        il.Emit(OpCodes.Ldobj, MapType(typeof(int)));
#else
                        if (ilVersion == Compiler.CompilerContext.ILVersion.Net1)
                        {
                            il.Emit(OpCodes.Unbox, MapType(typeof(int)));
                            il.Emit(OpCodes.Ldobj, MapType(typeof(int)));
                        }
                        else
                        {
                            il.Emit(OpCodes.Unbox_Any, MapType(typeof(int)));
                        }
#endif
                        il.Emit(OpCodes.Ret);
                        il.MarkLabel(otherwise);
                        il.Emit(OpCodes.Pop);
                        il.Emit(OpCodes.Ldc_I4_M1);
                        il.Emit(OpCodes.Ret);
                    }
                    break;
                default:
                    throw new InvalidOperationException();
            }
        }
开发者ID:SimonPStevens,项目名称:protobuf-net,代码行数:101,代码来源:RuntimeTypeModel.cs

示例2: WriteNullCheckedTail

 internal void WriteNullCheckedTail(Type type, IProtoSerializer tail, Compiler.Local valueFrom)
 {
     if (type.IsValueType)
     {
         Type underlyingType = null;
     #if !FX11
         underlyingType = Helpers.GetUnderlyingType(type);
     #endif
         if (underlyingType == null)
         { // not a nullable T; can invoke directly
             tail.EmitWrite(this, valueFrom);
         }
         else
         { // nullable T; check HasValue
             using (Compiler.Local valOrNull = GetLocalWithValue(type, valueFrom))
             {
                 LoadAddress(valOrNull, type);
                 LoadValue(type.GetProperty("HasValue"));
                 CodeLabel @end = DefineLabel();
                 BranchIfFalse(@end, false);
                 LoadAddress(valOrNull, type);
                 EmitCall(type.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
                 tail.EmitWrite(this, null);
                 MarkLabel(@end);
             }
         }
     }
     else
     { // ref-type; do a null-check
         LoadValue(valueFrom);
         CopyValue();
         CodeLabel hasVal = DefineLabel(), @end = DefineLabel();
         BranchIfTrue(hasVal, true);
         DiscardValue();
         Branch(@end, false);
         MarkLabel(hasVal);
         tail.EmitWrite(this, null);
         MarkLabel(@end);
     }
 }
开发者ID:banksyhf,项目名称:Auxilium-2,代码行数:40,代码来源:CompilerContext.cs

示例3: GetProperty

 internal static PropertyInfo GetProperty(Type type, string name, bool nonPublic)
 {
     return type.GetProperty(name,
         nonPublic ? BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                   : BindingFlags.Instance | BindingFlags.Public);
 }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:6,代码来源:Helpers.cs


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