/// <summary>
        /// 
        /// </summary>
        /// <param name="rootAlias"></param>
        /// <param name="rootType"></param>
        /// <param name="matchMode"></param>
        /// <param name="entityMode"></param>
        /// <param name="instance"></param>
        /// <param name="classInfoProvider"></param>
        public CriteriaCompiled(string rootAlias, System.Type rootType, MatchMode matchMode, EntityMode entityMode,
                                object instance, Func<System.Type, IPersistentClassInfo> classInfoProvider)
        {
            
            if (rootAlias == null || rootAlias.Trim().Equals(string.Empty))
                throw new ArgumentException("The alias for making detached criteria cannot be empty or null", "rootAlias");

            if (rootType == null)
                throw new ArgumentNullException("rootType", "The type which can be used for maikng detached criteria cannot be null.");

            if (instance == null)
                throw new ArgumentNullException("instance", "The instance for building detached criteria cannot be null.");

            if (!rootType.IsInstanceOfType(instance))
                throw new ArgumentTypeException("The given instance for building detached criteria is not suitable for the given criteria type.", "instance", rootType, instance.GetType());

            this.matchMode = matchMode ?? MatchMode.Exact;
            this.entityMode = entityMode;
            this.instance = instance;
            this.classInfoProvider = classInfoProvider;

            this.relationshipTree = new RelationshipTree(rootAlias, rootType);
            this.criteria = DetachedCriteria.For(rootType, rootAlias);
            this.restrictions = new List<ICriterion>();
            this.Init();
        }
 internal static object QueryStateObject(System.Type t, int controlID)
 {
   object o = GUIStateObjects.s_StateCache[controlID];
   if (t.IsInstanceOfType(o))
     return o;
   return (object) null;
 }
Ejemplo n.º 3
0
 internal static object QueryStateObject(System.Type t, int controlID)
 {
     object o = s_StateCache[controlID];
     if (t.IsInstanceOfType(o))
     {
         return o;
     }
     return null;
 }
Ejemplo n.º 4
0
Archivo: Assert.cs Proyecto: AxFab/amy
 public static void Throw(System.Action action, System.Type exType = null)
 {
     if (exType == null)
     exType = typeof(System.Exception);
       try {
     action();
     error("Expected to throw '"+ exType + "' got nothing.");
       } catch (System.Exception ex) {
     if (!exType.IsInstanceOfType(ex))
       error("Expected to throw '" + exType + "' got '" + ex.GetType() + "'.");
       }
 }
Ejemplo n.º 5
0
 internal bool RunDelegateForType(System.Type type, SyntaxTree.TreeNodeDelegate delegateToRun)
 {
     bool result = true;
     if (type.IsInstanceOfType(this))
     {
         result = delegateToRun(this);
     }
     foreach (var node in this._children)
     {
         if (node != null)
             result &= node.RunDelegateForType(type, delegateToRun);
     }
     return result;
 }
Ejemplo n.º 6
0
 public IStatusUpdate GetToolStripItem(System.Type commandType)
 {
     foreach (ToolStrip strip in this.ToolBars)
     {
         foreach (ToolStripItem item in strip.Items)
         {
             IStatusUpdate update = item as IStatusUpdate;
             if (((update != null) && (update.Command != null)) && commandType.IsInstanceOfType(update.Command))
             {
                 return update;
             }
         }
     }
     return null;
 }
 public object GetHandler(System.Type handlerType)
 {
     if (handlerType == this.lastHandlerType)
     {
         return this.lastHandler;
     }
     for (HandlerEntry entry = this.handlerHead; entry != null; entry = entry.next)
     {
         if ((entry.handler != null) && handlerType.IsInstanceOfType(entry.handler))
         {
             this.lastHandlerType = handlerType;
             this.lastHandler = entry.handler;
             return entry.handler;
         }
     }
     return null;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Converts a value to the specified type using either .NET or COM conversion rules.
        /// </summary>
        private object ChangeType(object source, System.Type type, bool supportsCOM)
        {
            if (source == null || type == null)
            {
                return source;
            }

            // check for an invalid req type.
            if (type == Type.ILLEGAL_TYPE)
            {
                throw new ResultIDException(ResultID.Da.E_BADTYPE);
            }

            // check for no conversion.
            if (type.IsInstanceOfType(source))
            {
                return Opc.Convert.Clone(source);
            }

            // convert the data.
            if (supportsCOM)
            {
                return ChangeTypeForCOM(source, type);
            }
            else
            {
                return ChangeType(source, type);
            }
        }
Ejemplo n.º 9
0
 public List<IStatusUpdate> GetToolStripItems(System.Type commandType)
 {
     List<IStatusUpdate> list = new List<IStatusUpdate>();
     foreach (ToolStrip strip in this.ToolBars)
     {
         foreach (ToolStripItem item in strip.Items)
         {
             IStatusUpdate update = item as IStatusUpdate;
             if (((update != null) && (update.Command != null)) && commandType.IsInstanceOfType(update.Command))
             {
                 list.Add(update);
             }
         }
     }
     return list;
 }
Ejemplo n.º 10
0
 public Instruction Ancestor(System.Type type)
 {
     Instruction ins = m_parent;
     while (ins != null && ! (type.IsInstanceOfType(ins)))
         ins = ins.Parent;
     return ins; // may be null!
 }
Ejemplo n.º 11
0
        /// <summary> Derive a ranking based on how "natural" the conversion is.
        /// The special value CONVERSION_NONE means no conversion is possible,
        /// and CONVERSION_NONTRIVIAL signals that more type conformance testing
        /// is required.
        /// Based on
        /// <a href="http://www.mozilla.org/js/liveconnect/lc3_method_overloading.html">
        /// "preferred method conversions" from Live Connect 3</a>
        /// </summary>
        internal static int GetConversionWeight(System.Object fromObj, System.Type to)
        {
            int fromCode = GetJSTypeCode (fromObj);

            switch (fromCode) {
                case JSTYPE_UNDEFINED:
                    if (to == typeof (string) || to == typeof (object)) {
                        return 1;
                    }
                    break;
                case JSTYPE_NULL:
                    if (!to.IsPrimitive) {
                        return 1;
                    }
                    break;
                case JSTYPE_BOOLEAN:
                    if (to == typeof (bool)) {
                        return 1;
                    }
                    else if (to == typeof (object)) {
                        return 2;
                    }
                    else if (to == typeof (string)) {
                        return 3;
                    }
                    break;

                case JSTYPE_NUMBER:
                    if (to.IsPrimitive) {
                        if (to == typeof (double)) {
                            return 1;
                        }
                        else if (to != typeof (bool)) {
                            return 1 + GetSizeRank (to);
                        }
                    }
                    else {
                        if (to == typeof (string)) {
                            // native numbers are #1-8
                            return 9;
                        }
                        else if (to == typeof (object)) {
                            return 10;
                        }
                        else if (CliHelper.IsNumberType (to)) {
                            // "double" is #1
                            return 2;
                        }
                    }
                    break;

                case JSTYPE_STRING:
                    if (to == typeof (string)) {
                        return 1;
                    }
                    else if (to.IsInstanceOfType (fromObj)) {
                        return 2;
                    }
                    else if (to.IsPrimitive) {
                        if (to == typeof (char)) {
                            return 3;
                        }
                        else if (to != typeof (bool)) {
                            return 4;
                        }
                    }
                    break;

                case JSTYPE_CLI_CLASS:
                    if (to == typeof (Type)) {
                        return 1;
                    }
                    else if (to == typeof (object)) {
                        return 3;
                    }
                    else if (to == typeof (string)) {
                        return 4;
                    }
                    break;

                case JSTYPE_CLI_OBJECT:
                case JSTYPE_CLI_ARRAY:
                    object cliObj = fromObj;
                    if (cliObj is Wrapper) {
                        cliObj = ((Wrapper)cliObj).Unwrap ();
                    }
                    if (to.IsInstanceOfType (cliObj)) {
                        return CONVERSION_NONTRIVIAL;
                    }
                    if (to == typeof (string)) {
                        return 2;
                    }
                    else if (to.IsPrimitive && to != typeof (bool)) {
                        return (fromCode == JSTYPE_CLI_ARRAY) ? CONVERSION_NONTRIVIAL : 2 + GetSizeRank (to);
                    }
                    break;

                case JSTYPE_OBJECT:
                    // Other objects takes #1-#3 spots
                    if (to == fromObj.GetType ()) {
                        // No conversion required
                        return 1;
                    }
                    if (to.IsArray) {
                        if (fromObj is BuiltinArray) {
                            // This is a native array conversion to a java array
                            // Array conversions are all equal, and preferable to object
                            // and string conversion, per LC3.
                            return 1;
                        }
                    }
                    else if (to == typeof (object)) {
                        return 2;
                    }
                    else if (to == typeof (string)) {
                        return 3;
                    }
                    else if (to == typeof (DateTime)) {
                        if (fromObj is BuiltinDate) {
                            // This is a native date to java date conversion
                            return 1;
                        }
                    }
                    else if (to.IsInterface) {
                        if (fromObj is IFunction) {
                            // See comments in coerceType
                            if (to.GetMethods ().Length == 1) {
                                return 1;
                            }
                        }
                        return 11;
                    }
                    else if (to.IsPrimitive && to != typeof (bool)) {
                        return 3 + GetSizeRank (to);
                    }
                    break;
            }

            return CONVERSION_NONE;
        }
Ejemplo n.º 12
0
		public virtual int nextSpanTransition(int start, int limit, System.Type kind)
		{
			int count = mSpanCount;
			object[] spans = mSpans;
			int[] starts = mSpanStarts;
			int[] ends = mSpanEnds;
			int gapstart = mGapStart;
			int gaplen = mGapLength;
			if (kind == null)
			{
				kind = typeof(object);
			}
			{
				for (int i = 0; i < count; i++)
				{
					int st = starts[i];
					int en = ends[i];
					if (st > gapstart)
					{
						st -= gaplen;
					}
					if (en > gapstart)
					{
						en -= gaplen;
					}
					if (st > start && st < limit && kind.IsInstanceOfType(spans[i]))
					{
						limit = st;
					}
					if (en > start && en < limit && kind.IsInstanceOfType(spans[i]))
					{
						limit = en;
					}
				}
			}
			return limit;
		}
 internal ConnectionPointCookie(object source, object sink, System.Type eventInterface, bool throwException)
 {
     if (source is System.Windows.Forms.UnsafeNativeMethods.IConnectionPointContainer)
     {
         System.Windows.Forms.UnsafeNativeMethods.IConnectionPointContainer container = (System.Windows.Forms.UnsafeNativeMethods.IConnectionPointContainer) source;
         try
         {
             Guid gUID = eventInterface.GUID;
             if (container.FindConnectionPoint(ref gUID, out this.connectionPoint) != 0)
             {
                 this.connectionPoint = null;
             }
         }
         catch
         {
             this.connectionPoint = null;
         }
         if (this.connectionPoint != null)
         {
             if ((sink != null) && eventInterface.IsInstanceOfType(sink))
             {
                 int num = this.connectionPoint.Advise(sink, ref this.cookie);
                 if (num != 0)
                 {
                     this.cookie = 0;
                     Marshal.ReleaseComObject(this.connectionPoint);
                     this.connectionPoint = null;
                     if (throwException)
                     {
                         throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, System.Windows.Forms.SR.GetString("AXNoSinkAdvise", new object[] { eventInterface.Name }), new object[] { num }));
                     }
                 }
                 else
                 {
                     this.threadId = Thread.CurrentThread.ManagedThreadId;
                 }
             }
             else if (throwException)
             {
                 throw new InvalidCastException(System.Windows.Forms.SR.GetString("AXNoSinkImplementation", new object[] { eventInterface.Name }));
             }
         }
         else if (throwException)
         {
             throw new ArgumentException(System.Windows.Forms.SR.GetString("AXNoEventInterface", new object[] { eventInterface.Name }));
         }
     }
     else if (throwException)
     {
         throw new InvalidCastException(System.Windows.Forms.SR.GetString("AXNoConnectionPointContainer"));
     }
     if ((this.connectionPoint == null) || (this.cookie == 0))
     {
         if (this.connectionPoint != null)
         {
             Marshal.ReleaseComObject(this.connectionPoint);
         }
         if (throwException)
         {
             throw new ArgumentException(System.Windows.Forms.SR.GetString("AXNoConnectionPoint", new object[] { eventInterface.Name }));
         }
     }
 }
Ejemplo n.º 14
0
    bool IRemotingTypeInfo.CanCastTo (System.Type targetType, object o)
    {
      //      Console.WriteLine ("CanCastTo: " + targetType);

      // if this is a local servant, check it directly
      if (_realObject != null)
        return targetType.IsInstanceOfType (_realObject);

      // check if the thing was created with a valid type
      if (targetType.IsInstanceOfType (o))
        return true;

      // otherwise, perform the remote query if necessary
      string icename = IceUtil.TypeToIceName (targetType);

      if (_typeIds == null) {
        Ice.Object iob = o as Ice.Object;
        _typeIds = iob.ice_ids();
      }

      return ((IList) _typeIds).Contains (icename);
    }
 internal static void VerifyInitializeArgument(IComponent component, System.Type expectedType)
 {
     if (!expectedType.IsInstanceOfType(component))
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, System.Design.SR.GetString("ControlDesigner_ArgumentMustBeOfType"), new object[] { expectedType.FullName }), "component");
     }
 }
Ejemplo n.º 16
0
 private static MatchResult MatchArgument(System.Type parameter, object arg)
 {
     if (parameter.IsInstanceOfType(arg))
         return MatchResult.Exact;
     if (arg is Basic && parameter.IsInstanceOfType(((Basic)arg).Inner()))
         return MatchResult.BasicConversion;
     if (arg == null && !parameter.IsValueType)
         return MatchResult.Exact;
     if (arg is Proc && parameter.IsSubclassOf(typeof(System.Delegate)))
         return MatchResult.ProcConversion;
     if (arg is Array && (parameter.IsSubclassOf(typeof(System.Array))))
         return MatchResult.ArrayConversion;
     if (parameter.IsValueType) {
         if (parameter == typeof(System.Int64)) {
             return MatchResult.Int64Conversion;
         }
         if (parameter == typeof(System.UInt64)) {
             return MatchResult.UInt64Conversion;
         }
     }
     return MatchResult.NoMatch;
 }
Ejemplo n.º 17
0
		public virtual int nextSpanTransition(int start, int limit, System.Type kind)
		{
			int count = mSpanCount;
			object[] spans = mSpans;
			int[] data = mSpanData;
			if (kind == null)
			{
				kind = typeof(object);
			}
			{
				for (int i = 0; i < count; i++)
				{
					int st = data[i * COLUMNS + START];
					int en = data[i * COLUMNS + END];
					if (st > start && st < limit && kind.IsInstanceOfType(spans[i]))
					{
						limit = st;
					}
					if (en > start && en < limit && kind.IsInstanceOfType(spans[i]))
					{
						limit = en;
					}
				}
			}
			return limit;
		}
Ejemplo n.º 18
0
 public ConnectionPointCookie(object source, object sink, System.Type eventInterface, bool throwException)
 {
     Exception exception1 = null;
     if (source is Microsoft.VisualStudio.OLE.Interop.IConnectionPointContainer)
     {
         this.cpc = (Microsoft.VisualStudio.OLE.Interop.IConnectionPointContainer) source;
         try
         {
             Guid guid1 = eventInterface.GUID;
             this.cpc.FindConnectionPoint(ref guid1, out this.connectionPoint);
         }
         catch
         {
             this.connectionPoint = null;
         }
         if (this.connectionPoint == null)
         {
             exception1 = new ArgumentException();
             goto Label_009A;
         }
         if ((sink == null) || !eventInterface.IsInstanceOfType(sink))
         {
             exception1 = new InvalidCastException();
             goto Label_009A;
         }
         try
         {
             this.connectionPoint.Advise(sink, out this.cookie);
             goto Label_009A;
         }
         catch
         {
             this.cookie = 0;
             this.connectionPoint = null;
             exception1 = new Exception();
             goto Label_009A;
         }
     }
     exception1 = new InvalidCastException();
     Label_009A:
     if (!throwException || ((this.connectionPoint != null) && (this.cookie != 0)))
     {
         return;
     }
     if (exception1 == null)
     {
         throw new ArgumentException();
     }
     throw exception1;
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Asserts that an object is an instance of a given type.
 /// </summary>
 /// <param name="expected">The expected Type</param>
 /// <param name="actual">The object being examined</param>
 /// <param name="message">A message to display in case of failure</param>
 /// <param name="args">An array of objects to be used in formatting the message</param>
 public static void IsInstanceOfType(System.Type expected, object actual, string message, params object[] args)
 {
     if (!expected.IsInstanceOfType(actual))
     {
         Assert.Fail(message);
     }
 }
Ejemplo n.º 20
0
		private Elements GetSelectedElements(System.Type type)
		{
			Elements elements = new Elements();

			foreach (Shape shape in Shapes.Values)
			{
				if (shape.Selected && (type.IsInstanceOfType(shape) || shape.GetType().IsSubclassOf(type))) elements.Add(shape.Key,shape);
			}

			foreach (Line line in Lines.Values)
			{
				if (line.Selected && (type.IsInstanceOfType(line) || line.GetType().IsSubclassOf(type))) elements.Add(line.Key,line);
			}

			elements.SetModifiable(false);
			return elements;
		}
Ejemplo n.º 21
0
        /// <summary> Type-munging for field setting and method invocation.
        /// Conforms to LC3 specification
        /// </summary>
        internal static System.Object CoerceType(System.Type type, System.Object value)
        {
            if (value != null && value.GetType () == type) {
                return value;
            }

            switch (GetJSTypeCode (value)) {

                case JSTYPE_NULL:
                    // raise error if type.isPrimitive()
                    if (type.IsPrimitive) {
                        reportConversionError (value, type);
                    }
                    return null;

                case JSTYPE_UNDEFINED:
                    if (type == typeof (string) || type == typeof (object)) {
                        return "undefined";
                    }
                    else {
                        reportConversionError ("undefined", type);
                    }
                    break;

                case JSTYPE_BOOLEAN:
                    // Under LC3, only JS Booleans can be coerced into a Boolean value
                    if (type == typeof (bool) || type == typeof (bool) || type == typeof (object)) {
                        return value;
                    }
                    else if (type == typeof (string)) {
                        return value.ToString ();
                    }
                    else {
                        reportConversionError (value, type);
                    }
                    break;

                case JSTYPE_NUMBER:
                    if (type == typeof (string)) {
                        return ScriptConvert.ToString (value);
                    }
                    else if (type == typeof (object)) {
                        return CoerceToNumber (typeof (double), value);
                    }
                    else if ((type.IsPrimitive && type != typeof (bool)) || CliHelper.IsNumberType (type)) {
                        return CoerceToNumber (type, value);
                    }
                    else {
                        reportConversionError (value, type);
                    }
                    break;

                case JSTYPE_STRING:
                    if (type == typeof (string) || type.IsInstanceOfType (value)) {
                        return value;
                    }
                    else if (type == typeof (char)) {
                        // Special case for converting a single char string to a
                        // character
                        // Placed here because it applies *only* to JS strings,
                        // not other JS objects converted to strings
                        if (((System.String)value).Length == 1) {
                            return ((System.String)value) [0];
                        }
                        else {
                            return CoerceToNumber (type, value);
                        }
                    }
                    else if ((type.IsPrimitive && type != typeof (bool)) || CliHelper.IsNumberType (type)) {
                        return CoerceToNumber (type, value);
                    }
                    else {
                        reportConversionError (value, type);
                    }
                    break;

                case JSTYPE_CLI_CLASS:
                    if (value is Wrapper) {
                        value = ((Wrapper)value).Unwrap ();
                    }

                    if (type == typeof (Type) || type == typeof (object)) {
                        return value;
                    }
                    else if (type == typeof (string)) {
                        return value.ToString ();
                    }
                    else {
                        reportConversionError (value, type);
                    }
                    break;

                case JSTYPE_CLI_OBJECT:
                case JSTYPE_CLI_ARRAY:
                    if (type.IsPrimitive) {
                        if (type == typeof (bool)) {
                            reportConversionError (value, type);
                        }
                        return CoerceToNumber (type, value);
                    }
                    else {
                        if (value is Wrapper) {
                            value = ((Wrapper)value).Unwrap ();
                        }
                        if (type == typeof (string)) {
                            return value.ToString ();
                        }
                        else {
                            if (type.IsInstanceOfType (value)) {
                                return value;
                            }
                            else {
                                reportConversionError (value, type);
                            }
                        }
                    }
                    break;

                case JSTYPE_OBJECT:
                    if (type == typeof (string)) {
                        return ScriptConvert.ToString (value);
                    }
                    else if (type.IsPrimitive) {
                        if (type == typeof (bool)) {
                            reportConversionError (value, type);
                        }
                        return CoerceToNumber (type, value);
                    }
                    else if (type.IsInstanceOfType (value)) {
                        return value;
                    }
                    else if (type == typeof (DateTime) && value is BuiltinDate) {
                        double time = ((BuiltinDate)value).JSTimeValue;
                        // TODO: This will replace NaN by 0
                        return BuiltinDate.FromMilliseconds ((long)time);
                    }
                    else if (type.IsArray && value is BuiltinArray) {
                        // Make a new java array, and coerce the JS array components
                        // to the target (component) type.
                        BuiltinArray array = (BuiltinArray)value;
                        long length = array.getLength ();
                        System.Type arrayType = type.GetElementType ();
                        System.Object Result = System.Array.CreateInstance (arrayType, (int)length);
                        for (int i = 0; i < length; ++i) {
                            try {
                                ((System.Array)Result).SetValue (CoerceType (arrayType, array.Get (i, array)), i);
                            }
                            catch (EcmaScriptException) {
                                reportConversionError (value, type);
                            }
                        }

                        return Result;
                    }
                    else if (value is Wrapper) {
                        value = ((Wrapper)value).Unwrap ();
                        if (type.IsInstanceOfType (value))
                            return value;
                        reportConversionError (value, type);
                    }
                    else {
                        reportConversionError (value, type);
                    }
                    break;
            }

            return value;
        }
        /// <summary>
        /// Writes an encodeable object array to the stream.
        /// </summary>
        public void WriteEncodeableArray(string fieldName, IList<IEncodeable> values, System.Type systemType)
        {            
            if (BeginField(fieldName, values == null, true))
            {
                // check the length.
                if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
                {
                    throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded);
                }

                // get name for type being encoded.
                XmlQualifiedName xmlName = EncodeableFactory.GetXmlName(systemType);

                if (xmlName == null)
                {
                    xmlName = new XmlQualifiedName("IEncodeable", Namespaces.OpcUaXsd);
                }
                
                PushNamespace(xmlName.Namespace);

                // encode each element in the array.
                for (int ii = 0; ii < values.Count; ii++)
                {
                    IEncodeable value = values[ii];

                    if (systemType != null)
                    {
                        if (!systemType.IsInstanceOfType(value))
                        {
                            throw new ServiceResultException(
                                StatusCodes.BadEncodingError,
                                Utils.Format("Objects with type '{0}' are not allowed in the array being serialized.", systemType.FullName));
                        }

                        WriteEncodeable(xmlName.Name, value, systemType);
                    }
                }

                PopNamespace();

                EndField(fieldName);
            }
        }
 //-- Many thanks to Bea Stollnitz, on whose blog I found the original C# version of below in a drag-drop helper class...
 public static FrameworkElement FindVisualAncestor(System.Type ancestorType, System.Windows.Media.Visual visual)
 {
     while ((visual != null && !ancestorType.IsInstanceOfType(visual)))
     visual = (System.Windows.Media.Visual)System.Windows.Media.VisualTreeHelper.GetParent(visual);
     return (FrameworkElement)visual;
 }