本文整理汇总了C#中PropertyInfo.GetGetMethod方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetGetMethod方法的具体用法?C# PropertyInfo.GetGetMethod怎么用?C# PropertyInfo.GetGetMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.GetGetMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPropertyModifiers
static string GetPropertyModifiers (PropertyInfo property)
{
MethodBase mb = property.GetSetMethod (true);
if (mb == null)
mb = property.GetGetMethod (true);
return GetMethodModifiers (mb);
}
示例2: AddProperty
static void AddProperty (XmlElement members, PropertyInfo property)
{
XmlDocument document = members.OwnerDocument;
string signature = AddPropertySignature (property);
if (signature == null)
return;
XmlElement member = document.CreateElement ("Member");
member.SetAttribute ("MemberName", property.Name);
members.AppendChild (member);
XmlElement property_signature = document.CreateElement ("MemberSignature");
property_signature.SetAttribute ("Language", "C#");
property_signature.SetAttribute ("Value", signature);
member.AppendChild (property_signature);
member.AppendChild (AddElement (document, "MemberType", "Property"));
Type return_type = property.PropertyType;
member.AppendChild (AddReturnValue (document, return_type));
if (property.CanRead && property.GetGetMethod () != null) {
ParameterInfo [] parameters = property.GetGetMethod ().GetParameters ();
member.AppendChild (AddParameters (document, parameters));
member.AppendChild (AddDocsNode (document, return_type, parameters));
} else
member.AppendChild (AddDocsNode (document, return_type, null));
}
示例3: GetPropertyVisibility
static string GetPropertyVisibility (PropertyInfo property)
{
MethodBase mb = property.GetSetMethod (true);
if (mb == null)
mb = property.GetGetMethod (true);
return GetMethodVisibility (mb);
}
示例4: GetGetMethod
public static MethodInfo GetGetMethod(PropertyInfo property)
{
Requires.NotNull(property, nameof(property));
return property.GetGetMethod();
}
示例5: GetGetMethod
public static MethodInfo GetGetMethod(PropertyInfo property, bool nonPublic)
{
Requires.NotNull(property, "property");
return property.GetGetMethod(nonPublic);
}
示例6: GetModifiers
private static Modifiers GetModifiers(PropertyInfo property)
{
// NOTE we only support the subset of modifiers that is expected for "access stub" properties
MethodInfo getter = property.GetGetMethod(true);
Modifiers modifiers = getter.IsPublic ? Modifiers.Public : Modifiers.Protected;
if(!property.CanWrite)
{
modifiers |= Modifiers.Final;
}
if(getter.IsStatic)
{
modifiers |= Modifiers.Static;
}
return modifiers;
}
示例7: CompiledAccessStubFieldWrapper
private CompiledAccessStubFieldWrapper(TypeWrapper wrapper, PropertyInfo property, TypeWrapper propertyType, string name, string signature, Modifiers modifiers, MemberFlags flags)
: base(wrapper, propertyType, name, signature, modifiers, null, flags)
{
this.getter = property.GetGetMethod(true);
this.setter = property.GetSetMethod(true);
}
示例8: RegisterProperty
static void RegisterProperty(PropertyInfo p, StringBuilder sb) {
string getMethod = "Lua" + p.ReflectedType.Name + "." + p.GetGetMethod().Name;
string setMethod = p.GetSetMethod() == null ? "null" : "Lua" + p.ReflectedType.Name + "." + p.GetSetMethod().Name;
sb.AppendFormat(" LuaDLL.lua_pushcsharpproperty(L, '{0}', {1}, {2});\r\n", p.Name, getMethod, setMethod);
}
示例9: CreateGetHandler
// CreateGetDelegate
internal static GetHandler CreateGetHandler(Type type, PropertyInfo propertyInfo)
{
MethodInfo getMethodInfo = propertyInfo.GetGetMethod(true);
DynamicMethod dynamicGet = CreateGetDynamicMethod(type);
ILGenerator getGenerator = dynamicGet.GetILGenerator();
getGenerator.Emit(OpCodes.Ldarg_0);
getGenerator.Emit(OpCodes.Call, getMethodInfo);
BoxIfNeeded(getMethodInfo.ReturnType, getGenerator);
getGenerator.Emit(OpCodes.Ret);
return (GetHandler)dynamicGet.CreateDelegate(typeof(GetHandler));
}
示例10: GetPropertyValue
/// <summary> Get the value of the property using the get accessor </summary>
public static Value GetPropertyValue(Value objectInstance, PropertyInfo propertyInfo, params Value[] arguments)
{
CheckObject(objectInstance, propertyInfo);
if (propertyInfo.GetGetMethod() == null) throw new GetValueException("Property does not have a get method");
Value val = Value.InvokeMethod(objectInstance, (DebugMethodInfo)propertyInfo.GetGetMethod(), arguments);
return val;
}
示例11: GenProperty
static void GenProperty(PropertyInfo p, StringBuilder sb) {
//先注册get方法
MethodInfo m = p.GetGetMethod();
AppendFunctionHead(m, sb);
string text = m.ReflectedType.Name + "." + m.Name + "(";
string name = "";
int count = m.IsStatic ? 0 : 1;
if (m.IsStatic) {
text = TrimNameSpace(p.ReflectedType) + ".";
}
else {
text = "obj.";
}
if (count > 0) {
text += p.Name;
CheckArgsCount(m, count, sb, true);
}
text += ";\r\n";
sb.Append("\r\n ");
text = text.Remove(text.Length - 3, 3);
GenPushStr(m.ReturnType, text, sb, null);
AppendFunctionEnd(sb);
//注册set方法
m = p.GetSetMethod();
if (m == null) return;
AppendFunctionHead(m, sb);
ParameterInfo[] paramInfos = m.GetParameters();
text = m.ReflectedType.Name + ".";
count = m.IsStatic ? 1 : 2;
if (m.IsStatic) {
text = "\r\n " + TrimNameSpace(m.ReturnType) + ".";
}
else {
text = "\r\n " + "obj.";
}
name = string.Format("({0})", TrimNameSpace(paramInfos[0].ParameterType));
if (paramInfos[0].ParameterType.IsPrimitive && paramInfos[0].ParameterType != typeof(bool)) {
name += "(double)";
}
if (count > 0) {
if (!m.IsStatic) {
CheckArgsCount(m, count, sb, true);
text += string.Format("{0} = {1}LuaStatic.GetObj(L, {2});\r\n", p.Name, name, 2);
}
else {
text += string.Format("{0} = {1}LuaStatic.GetObj(L, {2});\r\n", p.Name, name, 1);
}
}
sb.Append("\r\n ");
sb.Append(text);
AppendFunctionEnd(sb);
}
示例12: GetSetMethod
internal static MethodInfo GetSetMethod(PropertyInfo property, bool nonPublic, bool allowInternal)
{
if (property == null) return null;
#if WINRT
MethodInfo method = property.SetMethod;
if (!nonPublic && method != null && !method.IsPublic) method = null;
return method;
#else
MethodInfo method = property.GetSetMethod(nonPublic);
if (method == null && !nonPublic && allowInternal)
{ // could be "internal" or "protected internal"; look for a non-public, then back-check
method = property.GetGetMethod(true);
if (method == null && !(method.IsAssembly || method.IsFamilyOrAssembly))
{
method = null;
}
}
return method;
#endif
}
示例13: GetPropertyValue
// Get the current value of the specified property owned by instance. If instance is null then property is static.
// Returns: results of the ToString method when called on the result of the property, "write-only" if property is write-only, or null if property is of unsupported type.
public static string GetPropertyValue(object instance, PropertyInfo propertyInfo) {
if(propertyInfo == null) { return null; }
if(propertyInfo.GetGetMethod() == null) { return "write-only!"; }
switch(propertyInfo.PropertyType.Name) {
case "Vector2":
case "Vector3":
case "Color":
case "String":
case "Char":
case "Byte":
case "SByte":
case "Int16":
case "Int32":
case "Int64":
case "UInt16":
case "UInt32":
case "UInt64":
case "Single":
case "Double":
case "Boolean":
return propertyInfo.GetValue(instance, null).ToString();
default:
return null;
}
}
示例14: OutlineProperty
void OutlineProperty (PropertyInfo pi)
{
ParameterInfo [] idxp = pi.GetIndexParameters ();
MethodBase g = pi.GetGetMethod (true);
MethodBase s = pi.GetSetMethod (true);
MethodBase accessor = g != null ? g : s;
if (pi.CanRead && pi.CanWrite) {
// Get the more accessible accessor
if ((g.Attributes & MethodAttributes.MemberAccessMask) !=
(s.Attributes & MethodAttributes.MemberAccessMask)) {
if (g.IsPublic) accessor = g;
else if (s.IsPublic) accessor = s;
else if (g.IsFamilyOrAssembly) accessor = g;
else if (s.IsFamilyOrAssembly) accessor = s;
else if (g.IsAssembly || g.IsFamily) accessor = g;
else if (s.IsAssembly || s.IsFamily) accessor = s;
}
}
o.Write (GetMethodVisibility (accessor));
o.Write (GetMethodModifiers (accessor));
o.Write (FormatType (pi.PropertyType));
o.Write (" ");
if (idxp.Length == 0)
o.Write (pi.Name);
else {
o.Write ("this [");
OutlineParams (idxp);
o.Write ("]");
}
o.WriteLine (" {");
o.Indent ++;
if (g != null && ShowMember (g)) {
if ((g.Attributes & MethodAttributes.MemberAccessMask) !=
(accessor.Attributes & MethodAttributes.MemberAccessMask))
o.Write (GetMethodVisibility (g));
o.WriteLine ("get;");
}
if (s != null && ShowMember (s)) {
if ((s.Attributes & MethodAttributes.MemberAccessMask) !=
(accessor.Attributes & MethodAttributes.MemberAccessMask))
o.Write (GetMethodVisibility (s));
o.WriteLine ("set;");
}
o.Indent --;
o.Write ("}");
}
示例15: GetMethodType
static int GetMethodType(MethodBase md, out PropertyInfo pi)
{
int methodType = 0;
pi = null;
int pos = allProps.FindIndex((p) => { return p.GetGetMethod() == md || p.GetSetMethod() == md; });
if (pos >= 0)
{
methodType = 1;
pi = allProps[pos];
if (md == pi.GetGetMethod())
{
if (md.GetParameters().Length > 0)
{
methodType = 2;
}
}
else if (md == pi.GetSetMethod())
{
if (md.GetParameters().Length > 1)
{
methodType = 2;
}
}
}
return methodType;
}