public static void RegisterTreeViewAttributeTable(ITypeResolver typeResolver) { Type runtimeType = typeResolver.ResolveType(ProjectNeutralTypes.TreeView).RuntimeType; if (runtimeType == (Type)null) { return; } AttributeTableBuilder attributeTableBuilder = new AttributeTableBuilder(); Type treeViewItemType = typeResolver.ResolveType(ProjectNeutralTypes.TreeViewItem).RuntimeType; attributeTableBuilder.AddCallback(runtimeType, (AttributeCallback)(builder => { builder.AddCustomAttributes((Attribute) new StyleTypedPropertyAttribute() { Property = "ItemContainerStyle", StyleTargetType = treeViewItemType }); builder.AddCustomAttributes("SelectedValue", (Attribute) new DataContextValueSourceAttribute("SelectedValuePath", false)); builder.AddCustomAttributes("SelectedValue", (Attribute) new DualDataContextAttribute(true)); builder.AddCustomAttributes("SelectedValuePath", (Attribute) new DataContextPathExtensionAttribute("ItemsSource", true)); builder.AddCustomAttributes("SelectedItem", (Attribute) new DataContextValueSourceAttribute("ItemsSource", true)); builder.AddCustomAttributes("SelectedItem", (Attribute) new DualDataContextAttribute(false)); })); MetadataStore.AddAttributeTable(attributeTableBuilder.CreateTable()); }
public static void RegisterTabControlAttributeTable(ITypeResolver typeResolver) { Type runtimeType1 = typeResolver.ResolveType(ProjectNeutralTypes.TabControl).RuntimeType; if (runtimeType1 == (Type)null) { return; } AttributeTableBuilder attributeTableBuilder = new AttributeTableBuilder(); Type tabItemType = typeResolver.ResolveType(ProjectNeutralTypes.TabItem).RuntimeType; attributeTableBuilder.AddCallback(runtimeType1, (AttributeCallback)(builder => { builder.AddCustomAttributes((Attribute) new StyleTypedPropertyAttribute() { Property = "ItemContainerStyle", StyleTargetType = tabItemType }); builder.AddCustomAttributes("SelectedIndex", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("SelectedItem", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("TabStripPlacement", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); })); Type runtimeType2 = typeResolver.ResolveType(ProjectNeutralTypes.TabItem).RuntimeType; attributeTableBuilder.AddCallback(runtimeType2, (AttributeCallback)(builder => { builder.AddCustomAttributes("Header", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("IsSelected", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); })); MetadataStore.AddAttributeTable(attributeTableBuilder.CreateTable()); }
public static void RegisterDatePickerAttributeTable(ITypeResolver typeResolver) { Type runtimeType = typeResolver.ResolveType(ProjectNeutralTypes.DatePicker).RuntimeType; if (runtimeType == (Type)null) { return; } AttributeTableBuilder attributeTableBuilder = new AttributeTableBuilder(); Type calendarType = typeResolver.ResolveType(ProjectNeutralTypes.Calendar).RuntimeType; attributeTableBuilder.AddCallback(runtimeType, (AttributeCallback)(builder => { builder.AddCustomAttributes((Attribute) new StyleTypedPropertyAttribute() { Property = "CalendarStyle", StyleTargetType = calendarType }); builder.AddCustomAttributes("BlackoutDates", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("DisplayDate", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("DisplayDateEnd", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("DisplayDateStart", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("FirstDayOfWeek", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("IsDropDownOpen", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("IsTodayHighlighted", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("SelectedDateFormat", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("Text", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes((Attribute) new ToolboxCategoryAttribute("", true)); })); MetadataStore.AddAttributeTable(attributeTableBuilder.CreateTable()); }
public Notification Validate(object target) { var validatedType = _typeResolver.ResolveType(target); var notification = new Notification(validatedType); Validate(target, notification); return(notification); }
internal static CanAssignResult CanAssignTo(ITypeResolver typeResolver, ITypeId destinationTypeId, ITypeId sourceTypeId) { IPlatformMetadata platformMetadata = typeResolver.PlatformMetadata; IType type1 = typeResolver.ResolveType(destinationTypeId); IType type2 = typeResolver.ResolveType(sourceTypeId); if (platformMetadata.KnownTypes.NullExtension.IsAssignableFrom((ITypeId)type2)) { return(!type1.SupportsNullValues ? CanAssignResult.NotNullable : CanAssignResult.CanAssign); } if (type2 == type1) { return(CanAssignResult.CanAssign); } if (platformMetadata.KnownTypes.ArrayExtension.IsAssignableFrom((ITypeId)type2)) { if (type1.IsArray) { return(CanAssignResult.CanAssign); } System.Type runtimeType = type1.RuntimeType; if (runtimeType == (System.Type)null) { return(CanAssignResult.Unknown); } if (runtimeType.IsAssignableFrom(typeof(Array))) { return(CanAssignResult.CanAssign); } } else { if (type2.IsExpression) { return(CanAssignResult.Expression); } if (platformMetadata.KnownTypes.XData.Equals((object)type2)) { return(type1.Metadata.SupportsInlineXml ? CanAssignResult.CanAssign : CanAssignResult.NotXmlSerializable); } System.Type runtimeType1 = type2.RuntimeType; System.Type runtimeType2 = type1.RuntimeType; if (runtimeType2 == (System.Type)null || runtimeType1 == (System.Type)null) { return(CanAssignResult.Unknown); } if (platformMetadata.KnownTypes.Expression.IsAssignableFrom((ITypeId)type2)) { return(CanAssignResult.Expression); } if (runtimeType2.IsAssignableFrom(runtimeType1)) { return(CanAssignResult.CanAssign); } } return(CanAssignResult.CannotAssign); }
public static void RegisterWPFToolboxDifferenceAttributeTable(ITypeResolver typeResolver) { AttributeTableBuilder attributeTableBuilder = new AttributeTableBuilder(); Type runtimeType1 = typeResolver.ResolveType(ProjectNeutralTypes.DataGrid).RuntimeType; if (runtimeType1 != (Type)null) { attributeTableBuilder.AddCallback(runtimeType1, (AttributeCallback)(builder => { builder.AddCustomAttributes((Attribute) new ToolboxCategoryAttribute("Data", true)); builder.AddCustomAttributes((Attribute) new DescriptionAttribute(StringTable.DataGridTypeDescription)); })); } Type runtimeType2 = typeResolver.ResolveType(ProjectNeutralTypes.Calendar).RuntimeType; if (runtimeType2 != (Type)null) { attributeTableBuilder.AddCallback(runtimeType2, (AttributeCallback)(builder => { builder.AddCustomAttributes((Attribute) new ToolboxCategoryAttribute("", true)); builder.AddCustomAttributes((Attribute) new DescriptionAttribute(StringTable.CalendarTypeDescription)); })); } Type runtimeType3 = typeResolver.ResolveType(ProjectNeutralTypes.CalendarButton).RuntimeType; if (runtimeType3 != (Type)null) { attributeTableBuilder.AddCallback(runtimeType3, (AttributeCallback)(builder => { builder.AddCustomAttributes((Attribute) new ToolboxCategoryAttribute("Control Parts", false)); builder.AddCustomAttributes((Attribute) new DescriptionAttribute(StringTable.CalendarButtonTypeDescription)); })); } Type runtimeType4 = typeResolver.ResolveType(ProjectNeutralTypes.CalendarDayButton).RuntimeType; if (runtimeType4 != (Type)null) { attributeTableBuilder.AddCallback(runtimeType4, (AttributeCallback)(builder => { builder.AddCustomAttributes((Attribute) new ToolboxCategoryAttribute("Control Parts", false)); builder.AddCustomAttributes((Attribute) new DescriptionAttribute(StringTable.CalendarDayButtonTypeDescription)); })); } Type runtimeType5 = typeResolver.ResolveType(ProjectNeutralTypes.CalendarItem).RuntimeType; if (runtimeType5 != (Type)null) { attributeTableBuilder.AddCallback(runtimeType5, (AttributeCallback)(builder => { builder.AddCustomAttributes((Attribute) new ToolboxCategoryAttribute("Control Parts", false)); builder.AddCustomAttributes((Attribute) new DescriptionAttribute(StringTable.CalendarItemTypeDescription)); })); } MetadataStore.AddAttributeTable(attributeTableBuilder.CreateTable()); }
private object ConvertImageBrush(object value, object result, ITypeResolver sourceTypeResolver, ITypeResolver targetTypeResolver) { ReferenceStep referenceStep1 = (ReferenceStep)sourceTypeResolver.ResolveProperty(TileBrushNode.StretchProperty); ReferenceStep referenceStep2 = (ReferenceStep)targetTypeResolver.ResolveProperty(TileBrushNode.StretchProperty); object valueToSet1 = this.ConvertInternalFast(referenceStep1.GetValue(value), sourceTypeResolver, targetTypeResolver); referenceStep2.SetValue(result, valueToSet1); object objToInspect = ((ReferenceStep)sourceTypeResolver.ResolveProperty(ImageBrushNode.ImageSourceProperty)).GetValue(value); if (!PlatformTypes.IsInstance(objToInspect, PlatformTypes.BitmapImage, sourceTypeResolver)) { return(result); } object obj1 = ((ReferenceStep)sourceTypeResolver.ResolveProperty(BitmapImageNode.UriSourceProperty)).GetValue(objToInspect); if (obj1 == null) { return(result); } Type type1 = obj1.GetType(); IType type2 = targetTypeResolver.ResolveType(PlatformTypes.Uri); string text = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(type1).ConvertToInvariantString(obj1); if (string.IsNullOrEmpty(text)) { return(result); } object valueToSet2 = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(type2.RuntimeType).ConvertFromInvariantString(text); ReferenceStep referenceStep3 = (ReferenceStep)targetTypeResolver.ResolveProperty(ImageBrushNode.ImageSourceProperty); object obj2 = InstanceBuilderOperations.InstantiateType(targetTypeResolver.ResolveType(PlatformTypes.BitmapImage).RuntimeType, true); referenceStep3.SetValue(result, obj2); try { BitmapImage bitmapImage = obj2 as BitmapImage; if (bitmapImage != null) { bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; } ((ReferenceStep)targetTypeResolver.ResolveProperty(BitmapImageNode.UriSourceProperty)).SetValue(obj2, valueToSet2); if (bitmapImage != null) { bitmapImage.EndInit(); } } catch (Exception ex) { result = (object)null; } return(result); }
Type InferTypeFromElement(XmlElement element) { Type objType; string typeFullName = element.GetAttribute("type"); string assemblyFullName = element.GetAttribute("assembly"); if (typeResolver != null) { typeResolver.ResolveType(ref assemblyFullName, ref typeFullName); } try { if (string.IsNullOrEmpty(assemblyFullName)) { // type is directly loadable objType = Type.GetType(typeFullName, true); } else { Assembly asm = Assembly.Load(assemblyFullName); objType = asm.GetType(typeFullName, true); } } catch { objType = typeof(string); } return(objType); }
/// <summary> /// Builds a schema. /// </summary> /// <param name="type"> /// The type to build a schema for. /// </param> /// <param name="cache"> /// An optional schema cache. The cache can be used to provide schemas for certain types, /// and it will also be populated as the schema is built. /// </param> /// <returns> /// A schema that matches the type. /// </returns> public Schema BuildSchema(Type type, IDictionary <Type, Schema> cache = null) { if (cache == null) { cache = new Dictionary <Type, Schema>(); } var resolution = Resolver.ResolveType(type); if (!cache.TryGetValue(resolution.Type, out var schema)) { var match = Cases.FirstOrDefault(c => c.IsMatch(resolution)); if (match == null) { throw new UnsupportedTypeException(type, $"No schema builder case could be applied to {resolution.Type.FullName} ({resolution.GetType().Name})."); } schema = match.BuildSchema(resolution, cache); } if (resolution.IsNullable) { return(new UnionSchema(new Schema[] { new NullSchema(), schema })); } return(schema); }
private static object WarmUpPropertyCacheByITypeId(object arg) { PropertyCacheHelper.DispatchArguments arguments = (PropertyCacheHelper.DispatchArguments)arg; if (arguments.ViewModel.Document != null) { ITypeResolver typeResolver = (ITypeResolver)arguments.ViewModel.ProjectContext; IType type = typeResolver.ResolveType(arguments.TypeList[arguments.Index]); if (!typeResolver.PlatformMetadata.IsNullType((ITypeId)type)) { arguments.ViewModel.CreateSceneNode((ITypeId)type); } ++arguments.Index; if (arguments.Index < arguments.TypeList.Length) { if (PropertyCacheHelper.Synchronous) { PropertyCacheHelper.WarmUpPropertyCacheByITypeId((object)arguments); } else { UIThreadDispatcher.Instance.BeginInvoke <object>(DispatcherPriority.ApplicationIdle, (Func <object>)(() => PropertyCacheHelper.WarmUpPropertyCacheByITypeId((object)arguments))); } } } return((object)null); }
protected override DocumentNode CreateValue(BaseFrameworkElement source) { object tileBrush = this.CreateTileBrush(source); if (tileBrush == null) { return((DocumentNode)null); } ITypeResolver typeResolver = (ITypeResolver)source.ProjectContext; IViewObject visual = source.Visual; if (visual != null) { object platformSpecificObject = visual.PlatformSpecificObject; if (platformSpecificObject != null && PlatformTypes.Image.IsAssignableFrom((ITypeId)visual.GetIType((ITypeResolver)this.SceneViewModel.ProjectContext))) { ReferenceStep referenceStep = typeResolver.ResolveProperty(TileBrushNode.StretchProperty) as ReferenceStep; object obj = referenceStep.GetValue(tileBrush); object valueToSet = (typeResolver.ResolveProperty(ImageElement.StretchProperty) as ReferenceStep).GetValue(platformSpecificObject); if (!obj.Equals(valueToSet)) { referenceStep.SetValue(tileBrush, valueToSet); } } } return(this.SceneViewModel.Document.DocumentContext.CreateNode(typeResolver.ResolveType(PlatformTypes.TileBrush).RuntimeType, tileBrush)); }
private IGrainStorage CreateStorage( string grainType , IGrainState grainState) { // todo: hack, the declared type of the grain state is only accessible like so Type stateType = grainState.GetType().IsGenericType ? grainState.GetType().GenericTypeArguments[0] : grainState.State.GetType(); Type grainImplType = _typeResolver.ResolveType(grainType); Type storageType = typeof(GrainStorage <, ,>) .MakeGenericType(typeof(TContext), grainImplType, stateType); IGrainStorage storage; try { storage = (IGrainStorage)Activator.CreateInstance(storageType, grainType, _serviceProvider); } catch (Exception e) { if (e.InnerException == null) { throw; } // Unwrap target invocation exception throw e.InnerException; } _storage.TryAdd(grainType, storage); return(storage); }
/// <summary> /// Resolves a target type from the registered dependency container /// </summary> /// <typeparam name="TDependency">Type of the dependency to resolve</typeparam> /// <param name="builder">IAppBuilder pipeline</param> /// <returns>Instance of the dependency type or null</returns> public static TDependency Resolve <TDependency>(this IAppBuilder builder) where TDependency : class { ITypeResolver resolver = builder.GetTypeResolver(); return(resolver.ResolveType(typeof(TDependency)) as TDependency); }
private static IList GetVisualStateGroups(object hostElement, ITypeResolver typeResolver) { IType type1 = typeResolver.ResolveType(ProjectNeutralTypes.VisualStateManager); typeResolver.ResolveType(ProjectNeutralTypes.VisualStateGroup); IType type2 = typeResolver.GetType(hostElement.GetType()); if (!PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)type2)) { return((IList) new List <object>()); } return(PlatformTypeHelper.GetMethod(type1.RuntimeType, "GetVisualStateGroups").Invoke(null, new object[1] { hostElement }) as IList); }
public static void RegisterDragDropTargetAttributeTable(ITypeResolver typeResolver) { AttributeTableBuilder attributeTableBuilder = new AttributeTableBuilder(); ITypeId[] typeIdArray = new ITypeId[3] { ProjectNeutralTypes.DataGridDragDropTarget, ProjectNeutralTypes.ListBoxDragDropTarget, ProjectNeutralTypes.TreeViewDragDropTarget }; foreach (ITypeId typeId in typeIdArray) { Type runtimeType = typeResolver.ResolveType(typeId).RuntimeType; if (runtimeType != (Type)null) { attributeTableBuilder.AddCallback(runtimeType, (AttributeCallback)(builder => { builder.AddCustomAttributes("AllowedSourceEffects", (Attribute) new CategoryAttribute(PresentationFrameworkStringTable.Category_Common_Properties)); builder.AddCustomAttributes("AllowedSourceEffects", (Attribute) new DescriptionAttribute(StringTable.DragDropTargetTypeDescription)); builder.AddCustomAttributes("AllowDrop", (Attribute) new EditorBrowsableAttribute(EditorBrowsableState.Always)); })); } } MetadataStore.AddAttributeTable(attributeTableBuilder.CreateTable()); }
private IGrainStorage CreateStorage( string grainType , IGrainState grainState) { Type grainImplType = _typeResolver.ResolveType(grainType); Type stateType = _entityTypeResolver.ResolveStateType(grainType, grainState); Type entityType = _entityTypeResolver.ResolveEntityType(grainType, grainState); Type storageType = typeof(GrainStorage <, , ,>) .MakeGenericType(typeof(TContext), grainImplType, stateType, entityType); IGrainStorage storage; try { storage = (IGrainStorage)Activator.CreateInstance(storageType, grainType, _serviceProvider); } catch (Exception e) when(e.InnerException is GrainStorageConfigurationException) { throw e.InnerException; } _storage.TryAdd(grainType, storage); return(storage); }
public static void GetCtorSBytePtr(ITypeResolver typeResolver, out byte[] code, out IList <object> tokenResolutions, out IList <IType> locals, out IList <IParameter> parameters) { IType systemString = typeResolver.System.System_String; var codeBuilder = new IlCodeBuilder(); codeBuilder.LoadArgument(0); // calculate length codeBuilder.LoadArgument(0); codeBuilder.Add(Code.Call, 2); codeBuilder.Add(Code.Call, 3); codeBuilder.Add(Code.Call, 1); codeBuilder.Add(Code.Ret); code = codeBuilder.GetCode(); locals = new List <IType>(); tokenResolutions = new List <object>(); tokenResolutions.Add(systemString.GetMethodByName("CreateStringFromEncoding", typeResolver)); tokenResolutions.Add(systemString.GetMethodByName("strlen", typeResolver)); tokenResolutions.Add(typeResolver.ResolveType("System.Text.Encoding").GetMethodByName("get_ASCII", typeResolver)); parameters = new List <IParameter>(); parameters.Add(typeResolver.System.System_SByte.ToPointerType().ToParameter()); }
public static object Deserialize(string data, ITypeResolver typeResolver) { var package = JsonSerializer.Deserialize <MessagePackage>(data); var type = typeResolver.ResolveType(package.Type); return(JsonSerializer.Deserialize(package.Payload, type)); }
/// <summary> /// Gets the customization API for the specified type. /// </summary> /// <typeparam name="T">The type to setup.</typeparam> /// <returns>Returns an API which can be used to setup customizations for the specified type.</returns> public Customizer <T> Setup <T>() where T : class { var targetType = resolver.ResolveType(typeof(T)); generator.Invalidate(targetType); return(new Customizer <T>(this, config, targetType)); }
private string GetEngineModule(string[] modules) { if (_typeResolver.ResolveType("Mono.Runtime") != null || modules.Contains("mono")) { return("mono"); } return("roslyn"); }
public AuthorizationRight Authorize(BehaviorChain chain, object model) { if (model != null) { _context.Models.Set(_types.ResolveType(model), model); } return(chain.Authorization.IsAuthorized(_context)); }
public void InvokeObject(object model) { if (_authorization.IsAuthorized(model)) { var requestType = _types.ResolveType(model); _request.Set(requestType, model); _factory.BuildPartial(requestType).InvokePartial(); } }
public IType ResolveType(ITypeResolver typeResolver) { IType type = (IType)null; if (this.type != (Type)null) { type = typeResolver.GetType(this.type); } else if (this.IsCollection) { type = typeResolver.ResolveType(PlatformTypes.Array); } else if (!this.HasChildren) { type = typeResolver.ResolveType(PlatformTypes.String); } return(DesignDataHelper.GetSourceType(type, typeResolver)); }
public static ITypeId GetControlTypeToInstantiate(ITypeResolver typeResolver, ITypeId desiredType) { if (typeResolver == null || desiredType == null || typeResolver.PlatformMetadata.IsNullType(desiredType)) { return((ITypeId)null); } IType type = typeResolver.ResolveType(desiredType); KeyValuePair <ITypeId, ITypeId> keyValuePair = Enumerable.FirstOrDefault <KeyValuePair <ITypeId, ITypeId> >((IEnumerable <KeyValuePair <ITypeId, ITypeId> >)PartsModel.InstanceTypesForAbstractParts, (Func <KeyValuePair <ITypeId, ITypeId>, bool>)(pair => pair.Key.Equals((object)type))); if (keyValuePair.Key != null) { type = typeResolver.ResolveType(keyValuePair.Value); } if (PlatformTypes.Control.IsAssignableFrom((ITypeId)type) && !PlatformTypes.UserControl.IsAssignableFrom((ITypeId)type) && type.HasDefaultConstructor(false)) { return((ITypeId)type); } return((ITypeId)null); }
public static CloudEvent <object> ToStronglyTyped( this CloudEvent cloudEvent, Func <CloudEvent, Type, object> transformer, ITypeResolver typeResolver) { var type = typeResolver.ResolveType(cloudEvent.Type); var data = transformer(cloudEvent, type); return(ToStronglyTypedInternal(cloudEvent, data)); }
public static SqlType Resolve(SqlTypeCode typeCode, string typeName, DataTypeMeta[] metadata, ITypeResolver resolver) { if (PrimitiveTypes.IsPrimitive(typeCode)) return PrimitiveTypes.Resolve(typeCode, typeName, metadata); if (resolver == null) throw new NotSupportedException(String.Format("Cannot resolve type '{0}' without context.", typeName)); var resolveCcontext = new TypeResolveContext(typeCode, typeName, metadata); return resolver.ResolveType(resolveCcontext); }
protected override AuthorizationRight findAnswerFromResolver(object model, Func <IChainResolver, BehaviorChain> finder) { if (model != null) { _request.Set(_types.ResolveType(model), model); } BehaviorChain chain = finder(resolver); return(rightsFor(chain)); }
public AuthorizationRight Authorize(BehaviorChain chain, object model) { if (model != null) { _request.Set(_types.ResolveType(model), model); } var endpoint = _factory.AuthorizorFor(chain.UniqueId); return(endpoint.IsAuthorized(_request)); }
private static Type ResolveDeclaringType(this MemberInfo memberInfo, ITypeResolver typeResolver) { try { return(typeResolver.ResolveType(memberInfo.DeclaringType)); } catch (Exception ex) { throw new Exception($"Declaring type '{memberInfo.DeclaringType}' could not be reconstructed", ex); } }
private static StreamFilterPredicate RehydrateStaticFuncion(string funcClassName, string funcMethodName) { Type funcClassType = TypeResolver.ResolveType(funcClassName); MethodInfo method = funcClassType.GetMethod(funcMethodName); StreamFilterPredicate pred = (StreamFilterPredicate)method.CreateDelegate(typeof(StreamFilterPredicate)); #if DEBUG CheckFilterPredicateFunc(pred); // Assert expected pre-conditions are always true. #endif return(pred); }
public AuthorizationRight Authorize(BehaviorChain chain, object model) { if (model != null) { _request.Set(_types.ResolveType(model), model); } var endpoint = _services.GetInstance <IEndPointAuthorizor>(chain.UniqueId.ToString()); return(endpoint.IsAuthorized(_request)); }
public System.Reflection.FieldInfo ResolveField(ITypeResolver typeResolver) { Type declaringType; try { declaringType = typeResolver.ResolveType(DeclaringType); } catch (Exception ex) { throw new Exception($"Declaring type '{DeclaringType}' could not be reconstructed", ex); } var fieldInfo = declaringType.GetField(Name); return fieldInfo; }
public static void GetCtorSBytePtr(ITypeResolver typeResolver, out byte[] code, out IList<object> tokenResolutions, out IList<IType> locals, out IList<IParameter> parameters) { IType systemString = typeResolver.System.System_String; var codeBuilder = new IlCodeBuilder(); codeBuilder.LoadArgument(0); // calculate length codeBuilder.LoadArgument(0); codeBuilder.Add(Code.Call, 2); codeBuilder.Add(Code.Call, 3); codeBuilder.Add(Code.Call, 1); codeBuilder.Add(Code.Ret); code = codeBuilder.GetCode(); locals = new List<IType>(); tokenResolutions = new List<object>(); tokenResolutions.Add(systemString.GetMethodByName("CreateStringFromEncoding", typeResolver)); tokenResolutions.Add(systemString.GetMethodByName("strlen", typeResolver)); tokenResolutions.Add(typeResolver.ResolveType("System.Text.Encoding").GetMethodByName("get_ASCII", typeResolver)); parameters = new List<IParameter>(); parameters.Add(typeResolver.System.System_SByte.ToPointerType().ToParameter()); }
public System.Reflection.MethodInfo ResolveMethod(ITypeResolver typeResolver) { Type declaringType; try { declaringType = typeResolver.ResolveType(DeclaringType); } catch (Exception ex) { throw new Exception($"Declaring type '{DeclaringType}' could not be reconstructed", ex); } var genericArguments = ReferenceEquals(null, GenericArgumentTypes) ? new Type[0] : GenericArgumentTypes .Select(typeInfo => { try { var genericArgumentType = typeResolver.ResolveType(typeInfo); return genericArgumentType; } catch (Exception ex) { throw new Exception($"Generic argument type '{typeInfo}' could not be reconstructed", ex); } }) .ToArray(); var parameterTypes = ReferenceEquals(null, ParameterTypes) ? new Type[0] : ParameterTypes .Select(typeInfo => { try { var parameterType = typeResolver.ResolveType(typeInfo); return parameterType; } catch (Exception ex) { throw new Exception($"Parameter type '{typeInfo}' could not be reconstructed", ex); } }) .ToArray(); var methodInfo = declaringType.GetMethods(BindingFlags) .Where(m => m.Name == Name) .Where(m => !m.IsGenericMethod || m.GetGenericArguments().Length == genericArguments.Length) .Where(m => m.GetParameters().Length == parameterTypes.Length) .Select(m => m.IsGenericMethod ? m.MakeGenericMethod(genericArguments) : m) .Where(m => { var paramTypes = m.GetParameters(); for (int i = 0; i < parameterTypes.Length; i++) { if (paramTypes[i].ParameterType != parameterTypes[i]) { return false; } } return true; }) .Single(); return methodInfo; }