本文整理汇总了C#中IReflector.LoadSpecification方法的典型用法代码示例。如果您正苦于以下问题:C# IReflector.LoadSpecification方法的具体用法?C# IReflector.LoadSpecification怎么用?C# IReflector.LoadSpecification使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReflector
的用法示例。
在下文中一共展示了IReflector.LoadSpecification方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
private void Process(IReflector reflector, MethodInfo member, ISpecification holder) {
var allParams = member.GetParameters();
var paramsWithAttribute = allParams.Where(p => p.GetCustomAttribute<ContributedActionAttribute>() != null).ToArray();
if (!paramsWithAttribute.Any()) return; //Nothing to do
var facet = new ContributedActionFacet(holder);
foreach (ParameterInfo p in paramsWithAttribute) {
var attribute = p.GetCustomAttribute<ContributedActionAttribute>();
var type = reflector.LoadSpecification<IObjectSpecImmutable>(p.ParameterType);
if (type != null) {
if (type.IsParseable) {
Log.WarnFormat("ContributedAction attribute added to a value parameter type: {0}", member.Name);
}
else if (type.IsCollection) {
var parent = reflector.LoadSpecification(member.DeclaringType);
if (parent is IObjectSpecBuilder) {
AddLocalCollectionContributedAction(reflector, p, facet);
}
else {
AddCollectionContributedAction(reflector, member, type, p, facet, attribute);
}
}
else {
facet.AddObjectContributee(type, attribute.SubMenu, attribute.Id);
}
}
}
FacetUtils.AddFacet(facet);
}
开发者ID:NakedObjectsGroup,项目名称:NakedObjectsFramework,代码行数:29,代码来源:ContributedActionAnnotationFacetFactory.cs
示例2: ProcessArray
private void ProcessArray(IReflector reflector, Type type, ISpecification holder) {
FacetUtils.AddFacet(new ArrayFacet(holder));
FacetUtils.AddFacet(new TypeOfFacetInferredFromArray(holder));
var elementType = type.GetElementType();
reflector.LoadSpecification(elementType);
}
示例3: AddCollectionContributedAction
private static void AddCollectionContributedAction(IReflector reflector, MethodInfo member, IObjectSpecImmutable type, ParameterInfo p, ContributedActionFacet facet, ContributedActionAttribute attribute) {
if (!type.IsQueryable) {
Log.WarnFormat("ContributedAction attribute added to a collection parameter type other than IQueryable: {0}", member.Name);
}
else {
var returnType = reflector.LoadSpecification<IObjectSpecImmutable>(member.ReturnType);
if (returnType.IsCollection) {
Log.WarnFormat("ContributedAction attribute added to an action that returns a collection: {0}", member.Name);
}
else {
Type elementType = p.ParameterType.GetGenericArguments()[0];
type = reflector.LoadSpecification<IObjectSpecImmutable>(elementType);
facet.AddCollectionContributee(type, attribute.SubMenu, attribute.Id);
}
}
}
开发者ID:NakedObjectsGroup,项目名称:NakedObjectsFramework,代码行数:16,代码来源:ContributedActionAnnotationFacetFactory.cs
示例4: Process
public override void Process(IReflector reflector, MethodInfo actionMethod, IMethodRemover methodRemover, ISpecificationBuilder action) {
string capitalizedName = NameUtils.CapitalizeName(actionMethod.Name);
Type type = actionMethod.DeclaringType;
var facets = new List<IFacet>();
ITypeSpecBuilder onType = reflector.LoadSpecification(type);
var returnSpec = reflector.LoadSpecification<IObjectSpecBuilder>(actionMethod.ReturnType);
IObjectSpecImmutable elementSpec = null;
bool isQueryable = IsQueryOnly(actionMethod) || CollectionUtils.IsQueryable(actionMethod.ReturnType);
if (returnSpec != null && returnSpec.IsCollection) {
Type elementType = CollectionUtils.ElementType(actionMethod.ReturnType);
elementSpec = reflector.LoadSpecification<IObjectSpecImmutable>(elementType);
}
RemoveMethod(methodRemover, actionMethod);
facets.Add(new ActionInvocationFacetViaMethod(actionMethod, onType, returnSpec, elementSpec, action, isQueryable));
MethodType methodType = actionMethod.IsStatic ? MethodType.Class : MethodType.Object;
Type[] paramTypes = actionMethod.GetParameters().Select(p => p.ParameterType).ToArray();
FindAndRemoveValidMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, paramTypes, action);
DefaultNamedFacet(facets, actionMethod.Name, action); // must be called after the checkForXxxPrefix methods
AddHideForSessionFacetNone(facets, action);
AddDisableForSessionFacetNone(facets, action);
FindDefaultHideMethod(reflector, facets, methodRemover, type, methodType, "ActionDefault", action);
FindAndRemoveHideMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, action);
FindDefaultDisableMethod(reflector, facets, methodRemover, type, methodType, "ActionDefault", action);
FindAndRemoveDisableMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, action);
var actionSpecImmutable = action as IActionSpecImmutable;
if (actionSpecImmutable != null) {
// Process the action's parameters names, descriptions and optional
// an alternative design would be to have another facet factory processing just ActionParameter, and have it remove these
// supporting methods. However, the FacetFactory API doesn't allow for methods of the class to be removed while processing
// action parameters, only while processing Methods (ie actions)
IActionParameterSpecImmutable[] actionParameters = actionSpecImmutable.Parameters;
string[] paramNames = actionMethod.GetParameters().Select(p => p.Name).ToArray();
FindAndRemoveParametersAutoCompleteMethod(reflector, methodRemover, type, capitalizedName, paramTypes, actionParameters);
FindAndRemoveParametersChoicesMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters);
FindAndRemoveParametersDefaultsMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters);
FindAndRemoveParametersValidateMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters);
}
FacetUtils.AddFacets(facets);
}
示例5: Process
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) {
if (typeof (Enum).IsAssignableFrom(type)) {
Type semanticsProviderType = typeof (EnumValueSemanticsProvider<>).MakeGenericType(type);
var spec = reflector.LoadSpecification<IObjectSpecImmutable>(type);
object semanticsProvider = Activator.CreateInstance(semanticsProviderType, spec, specification);
MethodInfo method = typeof (ValueUsingValueSemanticsProviderFacetFactory).GetMethod("AddValueFacets", BindingFlags.Static | BindingFlags.Public).MakeGenericMethod(type);
method.Invoke(null, new[] {semanticsProvider, specification});
}
}
示例6: Process
private void Process(IReflector reflector, Type methodReturnType, ISpecification holder) {
if (!CollectionUtils.IsCollection(methodReturnType)) {
return;
}
if (methodReturnType.IsArray) {
Type elementType = methodReturnType.GetElementType();
var elementSpec = reflector.LoadSpecification<IObjectSpecImmutable>(elementType);
FacetUtils.AddFacet(new ElementTypeFacet(holder, elementType, elementSpec));
FacetUtils.AddFacet(new TypeOfFacetInferredFromArray(holder));
}
else if (methodReturnType.IsGenericType) {
Type[] actualTypeArguments = methodReturnType.GetGenericArguments();
if (actualTypeArguments.Any()) {
Type elementType = actualTypeArguments.First();
var elementSpec = reflector.LoadSpecification<IObjectSpecImmutable>(elementType);
FacetUtils.AddFacet(new ElementTypeFacet(holder, elementType, elementSpec));
FacetUtils.AddFacet(new TypeOfFacetInferredFromGenerics(holder));
}
}
}
示例7: Process
private void Process(IReflector reflector, MethodInfo member, ISpecification holder) {
var allParams = member.GetParameters();
var paramsWithAttribute = allParams.Where(p => p.GetCustomAttribute<ContributedActionAttribute>() != null).ToArray();
if (!paramsWithAttribute.Any()) return; //Nothing to do
var facet = new ContributedActionFacet(holder);
foreach (ParameterInfo p in paramsWithAttribute) {
var attribute = p.GetCustomAttribute<ContributedActionAttribute>();
var type = reflector.LoadSpecification<IObjectSpecImmutable>(p.ParameterType);
if (type != null) {
if (type.IsParseable) {
Log.WarnFormat("ContributedAction attribute added to a value parameter type: {0}", member.Name);
}
else {
if (type.IsCollection) {
if (!type.IsQueryable) {
Log.WarnFormat("ContributedAction attribute added to a collection parameter type other than IQueryable: {0}", member.Name);
}
else {
var returnType = reflector.LoadSpecification<IObjectSpecImmutable>(member.ReturnType);
if (returnType.IsCollection) {
Log.WarnFormat("ContributedAction attribute added to an action that returns a collection: {0}", member.Name);
}
else {
Type elementType = p.ParameterType.GetGenericArguments()[0];
type = reflector.LoadSpecification<IObjectSpecImmutable>(elementType);
facet.AddCollectionContributee(type, attribute.SubMenu, attribute.Id);
}
}
}
else {
facet.AddObjectContributee(type, attribute.SubMenu, attribute.Id);
}
}
}
}
FacetUtils.AddFacet(facet);
}
示例8: Process
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) {
if (BooleanValueSemanticsProvider.IsAdaptedType(type)) {
var spec = reflector.LoadSpecification<IObjectSpecImmutable>(BooleanValueSemanticsProvider.AdaptedType);
AddValueFacets(new BooleanValueSemanticsProvider(spec, specification), specification);
}
}
示例9: ProcessCollection
private void ProcessCollection(IReflector reflector, ISpecification holder) {
Type collectionElementType = typeof (object);
var spec = reflector.LoadSpecification<IObjectSpecImmutable>(collectionElementType);
FacetUtils.AddFacet(new TypeOfFacetDefaultToType(holder, collectionElementType, spec));
FacetUtils.AddFacet(new CollectionFacet(holder));
}
示例10: FindAndRemoveChoicesMethod
private void FindAndRemoveChoicesMethod(IReflector reflector,
ICollection<IFacet> propertyFacets,
IMethodRemover methodRemover,
Type type,
string capitalizedName,
Type returnType,
ISpecification property) {
MethodInfo[] methods = FindMethods(reflector,
type,
MethodType.Object,
RecognisedMethodsAndPrefixes.ChoicesPrefix + capitalizedName,
typeof (IEnumerable<>).MakeGenericType(returnType));
if (methods.Length > 1) {
methods.Skip(1).ForEach(m => Log.WarnFormat("Found multiple choices methods: {0} in type: {1} ignoring method(s) with params: {2}",
RecognisedMethodsAndPrefixes.ChoicesPrefix + capitalizedName,
type,
m.GetParameters().Select(p => p.Name).Aggregate("", (s, t) => s + " " + t)));
}
MethodInfo method = methods.FirstOrDefault();
RemoveMethod(methodRemover, method);
if (method != null) {
Tuple<string, IObjectSpecImmutable>[] parameterNamesAndTypes = method.GetParameters().Select(p => new Tuple<string, IObjectSpecImmutable>(p.Name.ToLower(), reflector.LoadSpecification<IObjectSpecImmutable>(p.ParameterType))).ToArray();
propertyFacets.Add(new PropertyChoicesFacet(method, parameterNamesAndTypes, property));
AddOrAddToExecutedWhereFacet(method, property);
}
}
示例11: FindAndRemoveParametersChoicesMethod
private void FindAndRemoveParametersChoicesMethod(IReflector reflector, IMethodRemover methodRemover, Type type, string capitalizedName, Type[] paramTypes, string[] paramNames, IActionParameterSpecImmutable[] parameters) {
for (int i = 0; i < paramTypes.Length; i++) {
Type paramType = paramTypes[i];
string paramName = paramNames[i];
bool isMultiple = false;
if (CollectionUtils.IsGenericEnumerable(paramType)) {
paramType = paramType.GetGenericArguments().First();
isMultiple = true;
}
Type returnType = typeof (IEnumerable<>).MakeGenericType(paramType);
string methodName = RecognisedMethodsAndPrefixes.ParameterChoicesPrefix + i + capitalizedName;
MethodInfo[] methods = FindMethods(
reflector,
type,
MethodType.Object,
methodName,
returnType);
if (methods.Length > 1) {
methods.Skip(1).ForEach(m => Log.WarnFormat("Found multiple action choices methods: {0} in type: {1} ignoring method(s) with params: {2}",
methodName,
type,
m.GetParameters().Select(p => p.Name).Aggregate("", (s, t) => s + " " + t)));
}
MethodInfo methodUsingIndex = methods.FirstOrDefault();
MethodInfo methodUsingName = FindMethod(
reflector,
type,
MethodType.Object,
RecognisedMethodsAndPrefixes.ParameterChoicesPrefix + capitalizedName,
returnType,
new[] {paramType},
new[] {paramName});
if (methodUsingIndex != null && methodUsingName != null) {
Log.WarnFormat("Duplicate choices parameter methods {0} and {1} using {1}", methodUsingIndex.Name, methodUsingName.Name);
}
MethodInfo methodToUse = methodUsingName ?? methodUsingIndex;
if (methodToUse != null) {
// deliberately not removing both if duplicate to show that method is duplicate
RemoveMethod(methodRemover, methodToUse);
// add facets directly to parameters, not to actions
Tuple<string, IObjectSpecImmutable>[] parameterNamesAndTypes = methodToUse.GetParameters().Select(p => new Tuple<string, IObjectSpecImmutable>(p.Name.ToLower(), reflector.LoadSpecification<IObjectSpecImmutable>(p.ParameterType))).ToArray();
FacetUtils.AddFacet(new ActionChoicesFacetViaMethod(methodToUse, parameterNamesAndTypes, returnType, parameters[i], isMultiple));
AddOrAddToExecutedWhereFacet(methodToUse, parameters[i]);
}
}
}
示例12: ProcessParams
public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) {
ParameterInfo parameter = method.GetParameters()[paramNum];
var facets = new List<IFacet>();
if (parameter.ParameterType.IsGenericType && (parameter.ParameterType.GetGenericTypeDefinition() == typeof (Nullable<>))) {
facets.Add(new NullableFacetAlways(holder));
}
var returnSpec = reflector.LoadSpecification<IObjectSpecBuilder>(parameter.ParameterType);
if (returnSpec != null && returnSpec.IsCollection) {
Type elementType = CollectionUtils.ElementType(parameter.ParameterType);
var elementSpec = reflector.LoadSpecification<IObjectSpecImmutable>(elementType);
facets.Add(new ElementTypeFacet(holder, elementType, elementSpec));
}
FacetUtils.AddFacets(facets);
}
示例13: GetTypicalLengthFacet
private ITypicalLengthFacet GetTypicalLengthFacet(IReflector reflector, Type type) {
var paramTypeSpec = reflector.LoadSpecification<IObjectSpecImmutable>(type);
return paramTypeSpec.GetFacet<ITypicalLengthFacet>();
}
示例14: AddLocalCollectionContributedAction
private static void AddLocalCollectionContributedAction(IReflector reflector, ParameterInfo p, ContributedActionFacet facet) {
Type elementType = p.ParameterType.GetGenericArguments()[0];
var type = reflector.LoadSpecification<IObjectSpecImmutable>(elementType);
facet.AddLocalCollectionContributee(type, p.Name);
}
开发者ID:NakedObjectsGroup,项目名称:NakedObjectsFramework,代码行数:5,代码来源:ContributedActionAnnotationFacetFactory.cs