Example #1
0
        private void SetUniqueKeyValue()
        {
            if (String.IsNullOrEmpty(UniqueKey))
            {
                return;
            }
            var propertyInfo = Type.GetProperty(UniqueKey,
                                                BindingFlags.Public | BindingFlags.Instance);

            if (propertyInfo != null)
            {
                GetUniqueKeyValue = (object value) =>
                {
                    var key = propertyInfo.GetValue(value, null);
                    if (key == null)
                    {
                        throw new Exception($"name must not be null");
                    }
                    return(key.ToString());
                };
                return;
            }
            var filedInfo = Type.GetField(UniqueKey,
                                          BindingFlags.Public | BindingFlags.Instance);

            if (filedInfo != null)
            {
                GetUniqueKeyValue = (object value) =>
                {
                    var key = filedInfo.GetValue(value);
                    if (key == null)
                    {
                        throw new Exception($"name must not be null");
                    }
                    return(key.ToString());
                };
                return;
            }
            else
            {
                throw new Exception("UniqueKey not exists");
            }
        }
Example #2
0
        static SecuredReflectionMethods()
        {
            if (!SecuredReflection.HasReflectionPermission)
            {
                if (!ProfilerInterceptor.IsProfilerAttached)
                {
                    ProfilerInterceptor.ThrowElevatedMockingException();
                }

                ProfilerInterceptor.CreateDelegateFromBridge("ReflectionInvoke", out Invoke);
                ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetProperty", out GetProperty);
                ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetProperty", out SetProperty);
                ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetField", out GetField);
                ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetField", out SetField);
            }
            else
            {
                Invoke      = (method, instance, args) => method.Invoke(instance, args);
                GetProperty = (prop, instance, indexArgs) => prop.GetValue(instance, indexArgs);
                SetProperty = (prop, instance, value, indexArgs) => prop.SetValue(instance, value, indexArgs);
                GetField    = (field, instance) => field.GetValue(instance);
                SetField    = (field, instance, value) => field.SetValue(instance, value);
            }
        }
Example #3
0
 /// <summary>
 /// Initialize a new instance of this class with the provided field info
 /// </summary>
 /// <param name="fieldInfo">The field info</param>
 private RuntimeFieldProxy(FieldInfo fieldInfo, GetFieldDelegate getProxy, SetFieldDelegate setProxy)
 {
     Field    = fieldInfo;
     GetProxy = getProxy;
     SetProxy = setProxy;
 }
		static SecuredReflectionMethods()
		{
			if (!SecuredReflection.HasReflectionPermission)
			{
				if (!ProfilerInterceptor.IsProfilerAttached)
					ProfilerInterceptor.ThrowElevatedMockingException();

				ProfilerInterceptor.CreateDelegateFromBridge("ReflectionInvoke", out Invoke);
				ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetProperty", out GetProperty);
				ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetProperty", out SetProperty);
				ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetField", out GetField);
				ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetField", out SetField);
			}
			else
			{
				Invoke = (method, instance, args) => method.Invoke(instance, args);
				GetProperty = (prop, instance, indexArgs) => prop.GetValue(instance, indexArgs);
				SetProperty = (prop, instance, value, indexArgs) => prop.SetValue(instance, value, indexArgs);
				GetField = (field, instance) => field.GetValue(instance);
				SetField = (field, instance, value) => field.SetValue(instance, value);
			}
		}
Example #5
0
 public static void GridWizard(QuickGrid grid,
     DataTable table,bool isMetric,IsNewAllowed isNewAllowed,
     IsReadOnly isReadOnly,
     string sortingField,GetFieldDelegate getField,
     HelperFunctions.DataGridClientInterface face,params string[] fieldsIn)
 {
     // When you get the field properties than the leading "*" is stripped
     string[] fields = (string[])fieldsIn.Clone();
     fieldsIn.CopyTo(fields,0);
     HelperFunctions.FieldProperties[] fieldProperties = HelperFunctions.GetProperties(ref fields,isMetric);
     DataTable newTable = new DataTable();
     for (int i=0;i<fields.Length;i++)
     {
         newTable.Columns.Add(fields[i],fieldProperties[i].type);
     }
     for (int i=0;i<table.Rows.Count;i++)
     {
         if (!DataInterface.IsRowAlive(table.Rows[i]))
             continue;
         DataRow targetRow = newTable.NewRow();
         foreach (string fieldName in fields)
         {
             object o = getField(table.Rows[i],isMetric,fieldName);
             targetRow[fieldName] = o;
         }
         newTable.Rows.Add(targetRow);
     }
     DataView view = new DataView(newTable,"",sortingField,
         DataViewRowState.CurrentRows);
     HelperFunctions.UpdateGrid(view,grid,face,isMetric,
         isNewAllowed,isReadOnly,fieldsIn);
 }