public void Set(ITargetedBind targeted, IValueInterface <T> valueInterface) { var id = targeted.TargetedId; lock (this) { Interfaces[id] = valueInterface; } }
public static void Set <T>(long id, IValueInterface <T> valueInterface) { if (!(ValueInterface <T> .Content is Impl <T>)) { Impl <T> .DefaultInterface = ValueInterface <T> .Content; ValueInterface <T> .SetInterface(Impl <T> .Instance); } Impl <T> .Instance.Set(id, valueInterface); }
public void Set(long id, IValueInterface <T> valueInterface) { lock (this) { var list = Interfaces.ToList(); list.RemoveAll(item => item.Key == id); list.Add(new KeyValuePair <long, IValueInterface <T> >(id, valueInterface)); Interfaces = list.ToArray(); } }
public static void Set <T>(long id, IValueInterface <T> valueInterface) { if (valueInterface == null) { throw new ArgumentNullException(nameof(valueInterface)); } var guid = CreateGuid <T>(id); lock (cache_lock) { ids[id] = guid; cache[guid] = valueInterface; } }
/// <summary> /// 设置当前实例指定类型的值读写器。 /// </summary> /// <typeparam name="T">指定类型</typeparam> /// <param name="valueInterface">值读写器</param> public void SetValueInterface <T>(IValueInterface <T> valueInterface) { if (valueInterface == null) { throw new ArgumentNullException(nameof(valueInterface)); } lock (this) { if (id == 0) { id = (long)Unsafe.AsPointer(ref Unsafe.AsRef(this)); } ValueInterface <T> .SetTargetedInterface(this, valueInterface); } }
/// <summary> /// 设置当前实例指定类型的值读写器。 /// </summary> /// <typeparam name="T">指定类型</typeparam> /// <param name="valueInterface">值读写器</param> public void SetValueInterface <T>(IValueInterface <T> valueInterface) { if (valueInterface == null) { throw new ArgumentNullException(nameof(valueInterface)); } lock (this) { if (Id == 0) { Id = (long)Pointer.UnBox(this); } ValueInterface <T> .SetTargetedInterface(Id, valueInterface); } }
public static void Set <T>(ITargetedBind targeted, IValueInterface <T> valueInterface) { if (valueInterface is null) { throw new ArgumentNullException(nameof(valueInterface)); } lock (targeted) { targeted.MakeTargetedId(); } if (!(ValueInterface <T> .Content is Impl <T>)) { Impl <T> .DefaultInterface = ValueInterface <T> .Content; ValueInterface <T> .SetInterface(Impl <T> .Instance); } Impl <T> .Instance.Set(targeted, valueInterface); }
public XInterfaceAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute, IValueInterface <T> valueInterface) : base(fieldRW, attribute) { this.valueInterface = valueInterface; }
public static void SetDefaultInterface <T>(IValueInterface <T> valueInterface) { Impl <T> .DefaultInterface = valueInterface; }
/// <summary> /// 设置支持针对性接口的对象指定类型的值读写接口。 /// </summary> /// <typeparam name="T">指定类型</typeparam> /// <param name="targeted">支持针对性接口的对象</param> /// <param name="valueInterface">值读写接口</param> public static void SetValueInterface <T>(this ITargetedBind targeted, IValueInterface <T> valueInterface) { ValueInterface <T> .SetTargetedInterface(targeted, valueInterface); }
static ValueInterface() { if (!StaticConstructorInvoked) { GetInterface(typeof(int)); } IsNoModify = true; if (Content != null) { return; } if (StaticConstructorInvoking) { return; } IValueInterface <T> valueInterface; for (int i = Mapers.Count - 1; i >= 0; --i) { valueInterface = Mapers[i].TryMap <T>(); if (valueInterface != null) { Content = valueInterface; return; } } var type = typeof(T); if (typeof(Type).IsAssignableFrom(type)) { Content = (IValueInterface <T>)Activator.CreateInstance((typeof(TypeInfoInterface <>)).MakeGenericType(type)); return; } if (typeof(System.Reflection.Assembly).IsAssignableFrom(type)) { Content = (IValueInterface <T>)Activator.CreateInstance((typeof(AssemblyInterface <>)).MakeGenericType(type)); return; } if (typeof(IDataReader).IsAssignableFrom(type)) { foreach (var item in type.GetInterfaces()) { if (item.IsGenericType && item.GetGenericTypeDefinition() == typeof(IDataReader <>)) { var keyType = item.GetGenericArguments()[0]; Content = (IValueInterface <T>)Activator.CreateInstance((typeof(DataReaderInterface <,>)).MakeGenericType(type, keyType)); return; } } } if (typeof(T).IsEnum) { Content = (IValueInterface <T>)Activator.CreateInstance(typeof(EnumInterface <>).MakeGenericType(type)); return; } if (type.IsArray) { Content = (IValueInterface <T>)Activator.CreateInstance(defaultArrayInterfaceType.MakeGenericType(type)); return; } if (type.IsValueType && type.IsGenericType) { var underlyingType = Nullable.GetUnderlyingType(typeof(T)); if (underlyingType != null && !ReferenceEquals(type, underlyingType)) { Content = (IValueInterface <T>)Activator.CreateInstance(nullableInterfaceType.MakeGenericType(underlyingType)); return; } } if (type.IsInterface || type.IsAbstract || typeof(IFormattable).IsAssignableFrom(type)) { Content = (IValueInterface <T>)Activator.CreateInstance(unknowInterfaceType.MakeGenericType(type)); return; } Content = (IValueInterface <T>)Activator.CreateInstance(defaultObjectInterfaceType.MakeGenericType(type)); }
public static void SetInterface(IValueInterface <T> valueInterface) { Content = valueInterface ?? throw new ArgumentNullException(nameof(valueInterface)); IsNoModify = false; }
public XInterfaceAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute, XBindingFlags flags, IValueInterface <T> valueInterface) : base(fieldRW, attribute, flags) { this.valueInterface = valueInterface; }
static ValueInterface() { if (!StaticConstructorInvoked) { GetInterface(typeof(int)); } try { RuntimeHelpers.RunClassConstructor(typeof(T).TypeHandle); } catch (Exception) { } IsNotModified = true; if (Content != null) { return; } if (StaticConstructorInvoking) { return; } for (int i = Mapers.Count - 1; i >= 0; --i) { var valueInterface = Mapers[i].TryMap <T>(); if (valueInterface != null) { Content = valueInterface; return; } } const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance; var nestedType = typeof(T).GetNestedType(nameof(ValueInterface), flags); if (nestedType != null && nestedType.GetConstructor(flags, Type.DefaultBinder, Type.EmptyTypes, null) != null) { if (nestedType.IsGenericTypeDefinition && typeof(T).IsGenericType && !typeof(T).IsGenericTypeDefinition) { var nestedTypeGenArgs = nestedType.GetGenericArguments(); var typeGenArgs = typeof(T).GetGenericArguments(); if (typeGenArgs.Length == nestedTypeGenArgs.Length) { nestedType = nestedType.MakeGenericType(typeGenArgs); } } if (typeof(IValueInterface <T>).IsAssignableFrom(nestedType)) { Content = (IValueInterface <T>)Activator.CreateInstance(nestedType); return; } } Content = (IValueInterface <T>)Activator.CreateInstance(defaultObjectInterfaceType.MakeGenericType(typeof(T))); }
public static void SetTargetedInterface(ITargetedBind targeted, IValueInterface <T> valueInterface) { TargetedValueInterface.Set(targeted, valueInterface); }
public SetValueFormatInterface(IValueInterface <T> defaultInterface, string format) { DefaultInterface = defaultInterface; Format = format; }
public static void SetTargetedInterface(long targetedId, IValueInterface <T> valueInterface) { TargetedValueInterface.Set(targetedId, valueInterface); }