public static ThirdType ToThirdType(this ThisType obj) { return(new ThirdType() { P1 = obj.sPropName, P2 = obj.dPropName }); }
protected void ClearPropertyToValidate <T>(Expression <Func <T> > propertyExpression) { string propertyName = PropertySupport.ExtractPropertyName(propertyExpression); PropertyInfo property = ThisType.GetProperty(propertyName); if (property != null) { m_PropertiesToValidate.Remove(property); } }
/// <summary> /// Deserialize an object instance from a binary stream. /// </summary> /// <param name="Types">List of all types which have been serialized so far.</param> /// <param name="Instances">List of object instances which have been serialized so far.</param> /// <param name="Reader">Binary reader for input data</param> /// <returns>Deserialized object instance</returns> static object DeserializeInstance(List <Type> Types, List <object> Instances, BinaryReader Reader) { Type ThisType; // Get the type int TypeIdx = Reader.ReadInt32(); if (TypeIdx == Types.Count) { string TypeName = Reader.ReadString(); ThisType = Type.GetType(TypeName); Types.Add(ThisType); } else { ThisType = Types[TypeIdx]; } // Create and read the object if (ThisType.IsArray) { int[] Lengths = new int[ThisType.GetArrayRank()]; for (int Idx = 0; Idx < Lengths.Length; Idx++) { Lengths[Idx] = Reader.ReadInt32(); } Array ThisArrayObject = Array.CreateInstance(ThisType.GetElementType(), Lengths); Instances.Add(ThisArrayObject); Type ElementType = ThisArrayObject.GetType().GetElementType(); foreach (int[] Indices in EnumerateArrayIndices(ThisArrayObject)) { ThisArrayObject.SetValue(DeserializeElement(ElementType, Types, Instances, Reader), Indices); } return(ThisArrayObject); } else if (ThisType == typeof(string)) { string ThisStringObject = Reader.ReadString(); Instances.Add(ThisStringObject); return(ThisStringObject); } else { object ThisObject = FormatterServices.GetUninitializedObject(ThisType); Instances.Add(ThisObject); DeserializeObjectFields(ThisObject, FindAllFields(ThisType), Types, Instances, Reader); return(ThisObject); } }
private bool ValidateControllerAttributes(out AttributeBase failedAttribute) { var controllerAttrs = ThisType.GetCustomAttributes(typeof(AttributeBase), true) as AttributeBase[]; foreach (var attr in controllerAttrs) { if (!attr.Validate(Context)) { failedAttribute = attr; return(false); } } failedAttribute = null; return(true); }
public override void ImplementMethod(MethodInfo declaration, MethodBuilder implement, FieldInfo input) { var @params = declaration.GetParameters(); var callee = ThisType.GetMethod(declaration.Name, BindingFlags.Public | BindingFlags.Instance, null, @params.Select(p => p.ParameterType).ToArray(), null); var ilGen = implement.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, input); for (var i = 0; i < @params.Length;) { ilGen.Emit(OpCodes.Ldarg_S, (byte)++i); } ilGen.Emit(OpCodes.Call, callee); ilGen.Emit(OpCodes.Ret); }
private static void MapNestedProperties( string sourcePropertiesPrefix, IEnumerable <PropertyInfo> nestedProperties, IMappingExpression <TLinkedSource, TDestination> expression) { foreach (var property in nestedProperties) { var sourcePropertyInDotNotation = $"{sourcePropertiesPrefix}.{property.Name}"; var method = ThisType.GetMethod("MapProperty"); var genericMethod = method.MakeGenericMethod(property.PropertyType); genericMethod.Invoke(null, new object[] { sourcePropertyInDotNotation, property.Name, expression }); } }
private static void MapContextualizedProperties( IEnumerable <PropertyInfo> contextualizedProperties, IMappingExpression <TLinkedSource, TDestination> expression) { foreach (var property in contextualizedProperties) { var overridingPropertyInDotNotation = string.Format("{0}.{1}", ContextualizationPropertyName, property.Name); var defaultPropertyInDotNotation = string.Format("{0}.{1}", ModelPropertyName, property.Name); var method = ThisType.GetMethod("MapContextualizedProperty"); var genericMethod = method.MakeGenericMethod(property.PropertyType); genericMethod.Invoke(null, new object[] { overridingPropertyInDotNotation, defaultPropertyInDotNotation, property.Name, expression }); } }
protected void AddPropertyToValidate <T>( Expression <Func <T> > propertyExpression, ValidationRule validation) { string propertyName = PropertySupport.ExtractPropertyName(propertyExpression); PropertyInfo property = ThisType.GetProperty(propertyName); if (property != null) { IList <ValidationRule> validations; if (!m_PropertiesToValidate.TryGetValue(property, out validations)) { validations = new List <ValidationRule>(new[] { validation }); m_PropertiesToValidate.Add(property, validations); } if (!validations.Contains(validation)) { validations.Add(validation); } } }
public int FindPortsOfType(MccDaq.MccBoard DaqBoard, int PortType, out int ProgAbility, out MccDaq.DigitalPortType DefaultPort, out int DefaultNumBits, out int FirstBit) { int ThisType, NumPorts, NumBits; int DefaultDev, InMask, OutMask; int PortsFound, curCount, curIndex; short status; bool PortIsCompatible; bool CheckBitProg = false; MccDaq.DigitalPortType CurPort; MccDaq.FunctionType DFunction; MccDaq.ErrorInfo ULStat; string ConnectionConflict; ULStat = MccDaq.MccService.ErrHandling (MccDaq.ErrorReporting.DontPrint, MccDaq.ErrorHandling.DontStop); ConnectionConflict = "This network device is in use by another process or user." + System.Environment.NewLine + System.Environment.NewLine + "Check for other users on the network and close any applications " + System.Environment.NewLine + "(such as Instacal) that may be accessing the network device."; DefaultPort = (MccDaq.DigitalPortType)(-1); CurPort = DefaultPort; PortsFound = 0; FirstBit = 0; ProgAbility = -1; DefaultNumBits = 0; ULStat = DaqBoard.BoardConfig.GetDiNumDevs(out NumPorts); if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)) { clsErrorDefs.DisplayError(ULStat); return(PortsFound); } if ((PortType == BITOUT) || (PortType == BITIN)) { CheckBitProg = true; } if ((PortType == PORTOUTSCAN) || (PortType == PORTINSCAN)) { if (NumPorts > 0) { DFunction = MccDaq.FunctionType.DiFunction; if (PortType == PORTOUTSCAN) { DFunction = MccDaq.FunctionType.DoFunction; } ULStat = DaqBoard.GetStatus(out status, out curCount, out curIndex, DFunction); if (!(ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors)) { NumPorts = 0; } } PortType = PortType & (PORTOUT | PORTIN); } for (int DioDev = 0; DioDev < NumPorts; ++DioDev) { ProgAbility = -1; ULStat = DaqBoard.DioConfig.GetDInMask(DioDev, out InMask); ULStat = DaqBoard.DioConfig.GetDOutMask(DioDev, out OutMask); if ((InMask & OutMask) > 0) { ProgAbility = FIXEDPORT; } ULStat = DaqBoard.DioConfig.GetDevType(DioDev, out ThisType); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { CurPort = (DigitalPortType)Enum.Parse(typeof(DigitalPortType), ThisType.ToString()); } if ((DioDev == 0) && (CurPort == MccDaq.DigitalPortType.FirstPortCL)) { //a few devices (USB-SSR08 for example) //start at FIRSTPORTCL and number the bits //as if FIRSTPORTA and FIRSTPORTB exist for //compatibiliry with older digital peripherals FirstBit = 16; } //check if port is set for requested direction //or can be programmed for requested direction PortIsCompatible = false; switch (PortType) { case (PORTOUT): if (OutMask > 0) { PortIsCompatible = true; } break; case (PORTIN): if (InMask > 0) { PortIsCompatible = true; } break; default: PortIsCompatible = false; break; } PortType = (PortType & (PORTOUT | PORTIN)); if (!PortIsCompatible) { if (ProgAbility != FIXEDPORT) { MccDaq.DigitalPortDirection ConfigDirection; ConfigDirection = DigitalPortDirection.DigitalOut; if (PortType == PORTIN) { ConfigDirection = DigitalPortDirection.DigitalIn; } if ((CurPort == MccDaq.DigitalPortType.AuxPort) && CheckBitProg) { //if it's an AuxPort, check bit programmability ULStat = DaqBoard.DConfigBit(MccDaq.DigitalPortType.AuxPort, FirstBit, ConfigDirection); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { //return port to input mode ULStat = DaqBoard.DConfigBit(MccDaq.DigitalPortType.AuxPort, FirstBit, DigitalPortDirection.DigitalIn); ProgAbility = PROGBIT; } else { if ((ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUseByAnotherProc) || (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUse)) { System.Windows.Forms.MessageBox.Show(ConnectionConflict, "Device In Use"); break; } } } if (ProgAbility == -1) { //check port programmability ULStat = DaqBoard.DConfigPort(CurPort, ConfigDirection); if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NoErrors) { //return port to input mode ULStat = DaqBoard.DConfigBit(MccDaq.DigitalPortType.AuxPort, FirstBit, DigitalPortDirection.DigitalIn); ProgAbility = PROGPORT; } else { if ((ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUseByAnotherProc) || (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.NetDevInUse)) { System.Windows.Forms.MessageBox.Show(ConnectionConflict, "Device In Use"); break; } } } } PortIsCompatible = !(ProgAbility == -1); } if (PortIsCompatible) { PortsFound = PortsFound + 1; } int BitVals, BitWeight; int TotalVal, CurBit; if (DefaultPort == (MccDaq.DigitalPortType)(-1)) { ULStat = DaqBoard.DioConfig.GetNumBits(DioDev, out NumBits); if (ProgAbility == FIXEDPORT) { //could have different number of input and output bits CurBit = 0; TotalVal = 0; BitVals = OutMask; if (PortType == PORTIN) { BitVals = InMask; } do { BitWeight = (int)Math.Pow(2, CurBit); TotalVal = BitWeight + TotalVal; CurBit = CurBit + 1; } while (TotalVal < BitVals); NumBits = CurBit; } DefaultNumBits = NumBits; DefaultDev = DioDev; DefaultPort = CurPort; } if (ProgAbility == PROGBIT) { break; } } ULStat = MccDaq.MccService.ErrHandling (clsErrorDefs.ReportError, clsErrorDefs.HandleError); return(PortsFound); }
public object CreatePlugin() { var type = TypeManager.Instance.GetTypeByName(ThisType.GetFullNameOfMember()); return(ObjectCreator.Instance.Spawn(type)); }