public sealed override object Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { #if PROJECTN if (parameters != null && parameters.Length != 0) { throw new TargetParameterCountException(); } Guid clsid = _declaringType.GUID; string server = _declaringType.Server; IntPtr pItf = IntPtr.Zero; try { pItf = McgMarshal.CoCreateInstanceEx(clsid, server); // CoCreateInstanceEx will throw exception if it fails to // create an instance. Debug.Assert(pItf != IntPtr.Zero); return(Marshal.GetObjectForIUnknown(pItf)); } finally { if (pItf != IntPtr.Zero) { Marshal.Release(pItf); } } #else throw new PlatformNotSupportedException(); #endif }
public static object UnwrapTarget(object target) { // // If target is a managed wrapper, we should unwrap it and use its target for data binding // For example, you don't want to data bind against a KeyValuePairImpl<K, V> - you want the real // KeyValuePair<K, V> // object newTarget = McgComHelpers.UnboxManagedWrapperIfBoxed(target); if (newTarget != target) { return(newTarget); } if (target is __ComObject) { object winrtUnboxed = McgMarshal.UnboxIfBoxed(target); if (winrtUnboxed != null) { return(winrtUnboxed); } } return(target); }
public sealed override bool IsCOMObject(Type type) { #if PROJECTN return(McgMarshal.IsComObject(type)); #else return(false); #endif }
private static System.InvalidCastException CreateExceptionForInvalidCast( PropertyType type, PropertyType unboxType) { System.InvalidCastException ex = new System.InvalidCastException(SR.Format(SR.PropertyValue_InvalidCast, type, unboxType)); McgMarshal.SetExceptionErrorCode(ex, Interop.COM.TYPE_E_TYPEMISMATCH); return(ex); }
private static System.InvalidCastException CreateExceptionForInvalidCoersion( PropertyType type, object value, PropertyType unboxType, int hr) { InvalidCastException ex = new InvalidCastException(SR.Format(SR.PropertyValue_InvalidCoersion, type, value, unboxType)); McgMarshal.SetExceptionErrorCode(ex, hr); return(ex); }
// V Lookup(K key) public static V Lookup <K, V>(global::System.Collections.Generic.IReadOnlyDictionary <K, V> _this, K key) { try { return(_this[key]); } catch (KeyNotFoundException ex) { // Change error code to match what WinRT expects McgMarshal.SetExceptionErrorCode(ex, global::McgInterop.McgHelpers.__HResults.E_BOUNDS); throw; } }
// T GetAt(uint index) public static T GetAt <T>( global::System.Collections.Generic.IList <T> _this, uint index) { EnsureIndexInt32(index); try { return(_this[(int)index]); } catch (System.ArgumentOutOfRangeException ex) { McgMarshal.SetExceptionErrorCode(ex, global::McgInterop.McgHelpers.__HResults.E_BOUNDS); throw; } }
// void RemoveAtEnd() public static void RemoveAtEnd <T>( global::System.Collections.Generic.IList <T> _this) { uint size = (uint)_this.Count; if (size == 0) { InvalidOperationException ex = new InvalidOperationException(global::Mcg.System.SR.GetString(global::Mcg.System.SR.Excep_CannotRemoveFromEmptyCollection)); // Change error code to match what WinRT expects McgMarshal.SetExceptionErrorCode(ex, global::McgInterop.McgHelpers.__HResults.E_BOUNDS); throw ex; } RemoveAt <T>(_this, size - 1); }
// void RemoveAt(uint index) public static void RemoveAt <T>( global::System.Collections.Generic.IList <T> _this, uint index) { EnsureIndexInt32(index); try { _this.RemoveAt((int)index); } catch (System.ArgumentOutOfRangeException ex) { // Change error code to match what WinRT expects McgMarshal.SetExceptionErrorCode(ex, global::McgInterop.McgHelpers.__HResults.E_BOUNDS); throw; } }
private static bool IsNumericScalarImpl(PropertyType type, object data) { switch (type) { case PropertyType.UInt8: case PropertyType.Int16: case PropertyType.UInt16: case PropertyType.Int32: case PropertyType.UInt32: case PropertyType.Int64: case PropertyType.UInt64: case PropertyType.Single: case PropertyType.Double: return(true); default: return(McgMarshal.IsEnum(data)); } }
// void InsertAt(uint index, T value) public static void InsertAt <T>( global::System.Collections.Generic.IList <T> _this, uint index, T value) { // Inserting at an index one past the end of the list is equivalent to appending // so we need to ensure that we're within (0, count + 1). EnsureIndexInt32(index); try { _this.Insert((int)index, value); } catch (System.ArgumentOutOfRangeException ex) { // Change error code to match what WinRT expects McgMarshal.SetExceptionErrorCode(ex, global::McgInterop.McgHelpers.__HResults.E_BOUNDS); throw; } }
public sealed override bool IsCOMObject(Type type) { return(McgMarshal.IsCOMObject(type)); }
public static string PtrToStringHString(IntPtr ptr) { return(McgMarshal.HStringToString(ptr)); }
public static void FreeHString(IntPtr ptr) { McgMarshal.FreeHString(ptr); }
public static IntPtr StringToHString(string s) { return(McgMarshal.StringToHString(s).handle); }