本文整理汇总了C#中PropertyInfo.GetSetMethod方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetSetMethod方法的具体用法?C# PropertyInfo.GetSetMethod怎么用?C# PropertyInfo.GetSetMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.GetSetMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PropertyAccessor
public PropertyAccessor(PropertyInfo propertyInfo)
: base(propertyInfo)
{
_hasSetter = (propertyInfo.GetSetMethod(true) != null);
if (_hasSetter)
_lateBoundPropertySet = DelegateFactory.CreateSet(propertyInfo);
}
示例2: ValueTypePropertyAccessor
public ValueTypePropertyAccessor(PropertyInfo propertyInfo)
: base(propertyInfo)
{
var setMethod = propertyInfo.GetSetMethod(true);
_hasSetter = (setMethod != null);
if (_hasSetter)
_lateBoundPropertySet = setMethod;
}
示例3: GetSetMethod
public static MethodInfo GetSetMethod(PropertyInfo property, bool nonPublic)
{
Requires.NotNull(property, "property");
return property.GetSetMethod(nonPublic);
}
示例4: GetSetMethod
public static MethodInfo GetSetMethod(PropertyInfo property)
{
Requires.NotNull(property, nameof(property));
return property.GetSetMethod();
}
示例5: PropertyField
public PropertyField(System.Object instance, PropertyInfo info, SerializedPropertyType type)
{
m_Instance = instance;
m_Info = info;
m_Type = type;
m_Getter = m_Info.GetGetMethod();
m_Setter = m_Info.GetSetMethod();
}
示例6: initProperty
private void initProperty( object target, PropertyInfo property )
{
this.target = target;
this.propertyInfo = property;
this.propertyGetter = property.GetGetMethod();
this.propertySetter = property.GetSetMethod();
this.canWrite = ( propertySetter != null );
Value = getter();
}
示例7: IsItemThis
static bool IsItemThis(PropertyInfo info)
{
MethodInfo md = info.GetGetMethod();
if (md != null)
{
return md.GetParameters().Length != 0;
}
md = info.GetSetMethod();
if (md != null)
{
return md.GetParameters().Length != 1;
}
return true;
}
示例8: GetPropertyModifiers
static string GetPropertyModifiers (PropertyInfo property)
{
MethodBase mb = property.GetSetMethod (true);
if (mb == null)
mb = property.GetGetMethod (true);
return GetMethodModifiers (mb);
}
示例9: 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);
}
示例10: SetPropertyValue
/// <summary> Set the value of the property using the set accessor </summary>
public static Value SetPropertyValue(Value objectInstance, PropertyInfo propertyInfo, Value[] arguments, Value newValue)
{
CheckObject(objectInstance, propertyInfo);
if (propertyInfo.GetSetMethod() == null) throw new GetValueException("Property does not have a set method");
arguments = arguments ?? new Value[0];
Value[] allParams = new Value[1 + arguments.Length];
allParams[0] = newValue;
arguments.CopyTo(allParams, 1);
return Value.InvokeMethod(objectInstance, (DebugMethodInfo)propertyInfo.GetSetMethod(), allParams);
}
示例11: 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
}
示例12: SetPropertyValue
// Set the current value of the specified property owned by instance. If instance is null then property is static.
// Returns: boolean indicating whether the property was successfully changed, or if property is read-only.
public static bool SetPropertyValue(object instance, PropertyInfo propertyInfo, List<string> parameters) {
if(propertyInfo.GetSetMethod() == null) {
string output = GetPropertyValue(instance, propertyInfo);
if(output == null) { return false; } // Fail: Property is not of a supported type
Echo(propertyInfo.Name + " is read-only!");
Echo(propertyInfo.Name + " is " + output);
return true; // Success: Value is printed when property is read-only
}
object result = ParseParameterListIntoType(propertyInfo.PropertyType.Name, parameters);
if(result != null) {
propertyInfo.SetValue(instance, result, null);
return true;
} else {
return false; // Fail: The parameters could not be parsed into the desired type
}
}
示例13: 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 ("}");
}
示例14: 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);
}
示例15: 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);
}